Test evaluation of per-config COMPILE_DEFINITIONS (#14037)

Teach the CompileDefinitions test to cover evaluation of config-specific
generator expressions.
This commit is contained in:
Brad King 2013-03-25 09:43:22 -04:00
parent a6286e92c9
commit 1703b00c7f
6 changed files with 92 additions and 3 deletions

View File

@ -7,10 +7,19 @@ if ("${CMAKE_GENERATOR}" STREQUAL "Visual Studio 6")
add_definitions(-DNO_SPACES_IN_DEFINE_VALUES) add_definitions(-DNO_SPACES_IN_DEFINE_VALUES)
endif() endif()
# Use compile flags to tell executables which config is built
# without depending on the compile definitions functionality.
foreach(c DEBUG RELEASE RELWITHDEBINFO MINSIZEREL)
set(CMAKE_C_FLAGS_${c} "${CMAKE_C_FLAGS_${c}} -DTEST_CONFIG_${c}")
set(CMAKE_CXX_FLAGS_${c} "${CMAKE_CXX_FLAGS_${c}} -DTEST_CONFIG_${c}")
endforeach()
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS
"BUILD_CONFIG_NAME=\"$<CONFIGURATION>\""
)
add_subdirectory(add_definitions_command) add_subdirectory(add_definitions_command)
add_subdirectory(target_prop) add_subdirectory(target_prop)
add_subdirectory(add_definitions_command_with_target_prop) add_subdirectory(add_definitions_command_with_target_prop)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/dummyexecutable.cpp" "int main(int, char **) { return 0; }\n") add_executable(CompileDefinitions runtest.c)
add_executable(CompileDefinitions "${CMAKE_CURRENT_BINARY_DIR}/dummyexecutable.cpp")

View File

@ -3,5 +3,6 @@ project(add_definitions_command)
add_definitions(-DCMAKE_IS_FUN -DCMAKE_IS=Fun -DCMAKE_IS_="Fun" -DCMAKE_IS_REALLY="Very Fun") add_definitions(-DCMAKE_IS_FUN -DCMAKE_IS=Fun -DCMAKE_IS_="Fun" -DCMAKE_IS_REALLY="Very Fun")
add_definitions(-DCMAKE_IS_="Fun" -DCMAKE_IS_REALLY="Very Fun" -DCMAKE_IS_FUN -DCMAKE_IS=Fun) add_definitions(-DCMAKE_IS_="Fun" -DCMAKE_IS_REALLY="Very Fun" -DCMAKE_IS_FUN -DCMAKE_IS=Fun)
add_definitions(-DBUILD_IS_DEBUG=$<CONFIG:Debug> -DBUILD_IS_NOT_DEBUG=$<NOT:$<CONFIG:Debug>>)
add_executable(add_definitions_command_executable ../compiletest.cpp) add_executable(add_definitions_command_executable ../compiletest.cpp)

View File

@ -12,3 +12,6 @@ set_property(TARGET add_definitions_command_with_target_prop_executable APPEND P
add_definitions(-DCMAKE_IS_FUN) add_definitions(-DCMAKE_IS_FUN)
set_property(TARGET add_definitions_command_with_target_prop_executable APPEND PROPERTY COMPILE_DEFINITIONS CMAKE_IS=Fun CMAKE_IS_="Fun") set_property(TARGET add_definitions_command_with_target_prop_executable APPEND PROPERTY COMPILE_DEFINITIONS CMAKE_IS=Fun CMAKE_IS_="Fun")
add_definitions(-DBUILD_IS_DEBUG=$<CONFIG:Debug>)
set_property(TARGET add_definitions_command_with_target_prop_executable APPEND PROPERTY COMPILE_DEFINITIONS BUILD_IS_NOT_DEBUG=$<NOT:$<CONFIG:Debug>>)

View File

@ -45,6 +45,30 @@ enum {
// TEST_GENERATOR_EXPRESSIONS // TEST_GENERATOR_EXPRESSIONS
#endif #endif
#ifndef BUILD_IS_DEBUG
# error "BUILD_IS_DEBUG not defined!"
#endif
#ifndef BUILD_IS_NOT_DEBUG
# error "BUILD_IS_NOT_DEBUG not defined!"
#endif
// Check per-config definitions.
#ifdef TEST_CONFIG_DEBUG
# if !BUILD_IS_DEBUG
# error "BUILD_IS_DEBUG false with TEST_CONFIG_DEBUG!"
# endif
# if BUILD_IS_NOT_DEBUG
# error "BUILD_IS_NOT_DEBUG true with TEST_CONFIG_DEBUG!"
# endif
#else
# if BUILD_IS_DEBUG
# error "BUILD_IS_DEBUG true without TEST_CONFIG_DEBUG!"
# endif
# if !BUILD_IS_NOT_DEBUG
# error "BUILD_IS_NOT_DEBUG false without TEST_CONFIG_DEBUG!"
# endif
#endif
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
return 0; return 0;

View File

@ -0,0 +1,47 @@
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#ifndef BUILD_CONFIG_NAME
# error "BUILD_CONFIG_NAME not defined!"
#endif
int main()
{
char build_config_name[] = BUILD_CONFIG_NAME;
char* c;
for(c = build_config_name; *c; ++c)
{
*c = (char)tolower((int)*c);
}
fprintf(stderr, "build_config_name=\"%s\"\n", build_config_name);
#ifdef TEST_CONFIG_DEBUG
if(strcmp(build_config_name, "debug") != 0)
{
fprintf(stderr, "build_config_name is not \"debug\"\n");
return 1;
}
#endif
#ifdef TEST_CONFIG_RELEASE
if(strcmp(build_config_name, "release") != 0)
{
fprintf(stderr, "build_config_name is not \"release\"\n");
return 1;
}
#endif
#ifdef TEST_CONFIG_MINSIZEREL
if(strcmp(build_config_name, "minsizerel") != 0)
{
fprintf(stderr, "build_config_name is not \"minsizerel\"\n");
return 1;
}
#endif
#ifdef TEST_CONFIG_RELWITHDEBINFO
if(strcmp(build_config_name, "relwithdebinfo") != 0)
{
fprintf(stderr, "build_config_name is not \"relwithdebinfo\"\n");
return 1;
}
#endif
return 0;
}

View File

@ -14,3 +14,8 @@ set_property(TARGET target_prop_executable APPEND PROPERTY COMPILE_DEFINITIONS
"$<0:GE_NOT_DEFINED>" "$<0:GE_NOT_DEFINED>"
"$<1:ARGUMENT;LIST>" "$<1:ARGUMENT;LIST>"
) )
set_property(TARGET target_prop_executable APPEND PROPERTY COMPILE_DEFINITIONS
BUILD_IS_DEBUG=$<CONFIG:Debug>
BUILD_IS_NOT_DEBUG=$<NOT:$<CONFIG:Debug>>
)