diff options
author | Brad King <brad.king@kitware.com> | 2013-03-25 13:43:22 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2013-03-25 14:49:42 (GMT) |
commit | 1703b00c7fc34f473e84f4ba29bdc73476637005 (patch) | |
tree | d32cb8e0ef24144e0ee7c904884cbd8adebc78d5 /Tests/CompileDefinitions | |
parent | a6286e92c9be9f5b8ad8fb25b3c6e15c0ec17fa0 (diff) | |
download | CMake-1703b00c7fc34f473e84f4ba29bdc73476637005.zip CMake-1703b00c7fc34f473e84f4ba29bdc73476637005.tar.gz CMake-1703b00c7fc34f473e84f4ba29bdc73476637005.tar.bz2 |
Test evaluation of per-config COMPILE_DEFINITIONS (#14037)
Teach the CompileDefinitions test to cover evaluation of config-specific
generator expressions.
Diffstat (limited to 'Tests/CompileDefinitions')
6 files changed, 92 insertions, 3 deletions
diff --git a/Tests/CompileDefinitions/CMakeLists.txt b/Tests/CompileDefinitions/CMakeLists.txt index e7d91bf..d3e9a3e 100644 --- a/Tests/CompileDefinitions/CMakeLists.txt +++ b/Tests/CompileDefinitions/CMakeLists.txt @@ -7,10 +7,19 @@ if ("${CMAKE_GENERATOR}" STREQUAL "Visual Studio 6") add_definitions(-DNO_SPACES_IN_DEFINE_VALUES) 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(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 "${CMAKE_CURRENT_BINARY_DIR}/dummyexecutable.cpp") +add_executable(CompileDefinitions runtest.c) diff --git a/Tests/CompileDefinitions/add_definitions_command/CMakeLists.txt b/Tests/CompileDefinitions/add_definitions_command/CMakeLists.txt index a6372af..d3886a1 100644 --- a/Tests/CompileDefinitions/add_definitions_command/CMakeLists.txt +++ b/Tests/CompileDefinitions/add_definitions_command/CMakeLists.txt @@ -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_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) diff --git a/Tests/CompileDefinitions/add_definitions_command_with_target_prop/CMakeLists.txt b/Tests/CompileDefinitions/add_definitions_command_with_target_prop/CMakeLists.txt index e415390..5587f7f 100644 --- a/Tests/CompileDefinitions/add_definitions_command_with_target_prop/CMakeLists.txt +++ b/Tests/CompileDefinitions/add_definitions_command_with_target_prop/CMakeLists.txt @@ -12,3 +12,6 @@ set_property(TARGET add_definitions_command_with_target_prop_executable APPEND P 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") + +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>>) diff --git a/Tests/CompileDefinitions/compiletest.cpp b/Tests/CompileDefinitions/compiletest.cpp index f18e59e..14b8eab 100644 --- a/Tests/CompileDefinitions/compiletest.cpp +++ b/Tests/CompileDefinitions/compiletest.cpp @@ -45,6 +45,30 @@ enum { // TEST_GENERATOR_EXPRESSIONS #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) { return 0; diff --git a/Tests/CompileDefinitions/runtest.c b/Tests/CompileDefinitions/runtest.c new file mode 100644 index 0000000..02d2cad --- /dev/null +++ b/Tests/CompileDefinitions/runtest.c @@ -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; +} diff --git a/Tests/CompileDefinitions/target_prop/CMakeLists.txt b/Tests/CompileDefinitions/target_prop/CMakeLists.txt index abdf257..1ef2d6d 100644 --- a/Tests/CompileDefinitions/target_prop/CMakeLists.txt +++ b/Tests/CompileDefinitions/target_prop/CMakeLists.txt @@ -14,3 +14,8 @@ set_property(TARGET target_prop_executable APPEND PROPERTY COMPILE_DEFINITIONS "$<0:GE_NOT_DEFINED>" "$<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>> + ) |