From 131d446183d5f4f6ec7ebb7648cbcc163b20781f Mon Sep 17 00:00:00 2001 From: Dean Moldovan Date: Wed, 4 May 2016 00:33:29 +0200 Subject: [PATCH 1/3] Fix compile tests not clearing the cache after an error The cache bug meant that a failed test would appear forever broken, even if the proper fix was applied. --- test/compile-test/CMakeLists.txt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/compile-test/CMakeLists.txt b/test/compile-test/CMakeLists.txt index 35a2d296..68cfe0c8 100644 --- a/test/compile-test/CMakeLists.txt +++ b/test/compile-test/CMakeLists.txt @@ -20,22 +20,28 @@ function (expect_compile code) generate_source(source "${code}") check_cxx_source_compiles("${source}" compiles) if (NOT compiles) - message(FATAL_ERROR "Compile error for: ${code}") + set(error_msg "Compile error for: ${code}") endif () # Unset the CMake cache variable compiles. Otherwise the compile test will # just use cached information next time it runs. unset(compiles CACHE) + if (error_msg) + message(FATAL_ERROR ${error_msg}) + endif () endfunction () function (expect_compile_error code) generate_source(source "${code}") check_cxx_source_compiles("${source}" compiles) if (compiles) - message(FATAL_ERROR "No compile error for: ${code}") + set(error_msg "No compile error for: ${code}") endif () # Unset the CMake cache variable compiles. Otherwise the compile test will # just use cached information next time it runs. unset(compiles CACHE) + if (error_msg) + message(FATAL_ERROR ${error_msg}) + endif () endfunction () # check if the source file skeleton compiles From 8eaad79de7cb48c2b2513fed3814571c36a3fd3e Mon Sep 17 00:00:00 2001 From: Dean Moldovan Date: Wed, 4 May 2016 00:36:48 +0200 Subject: [PATCH 2/3] Fix FMT_STATIC_ASSERT compile test FMT_STATIC_ASSERT is defined in posix.h so expect_compile_error was actually failing on a missing macro instead of the static assert. --- test/compile-test/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/compile-test/CMakeLists.txt b/test/compile-test/CMakeLists.txt index 68cfe0c8..b7126248 100644 --- a/test/compile-test/CMakeLists.txt +++ b/test/compile-test/CMakeLists.txt @@ -9,7 +9,7 @@ set(CMAKE_REQUIRED_FLAGS ${CPP11_FLAG}) function (generate_source result fragment) set(${result} " #define FMT_HEADER_ONLY 1 - #include \"fmt/format.h\" + #include \"fmt/posix.h\" int main() { ${fragment} } @@ -63,6 +63,7 @@ expect_compile_error("fmt::MemoryWriter() << fmt::pad(42, 5, L' ');") # Formatting a wide character with a narrow format string is forbidden. expect_compile_error("fmt::format(\"{}\", L'a';") +expect_compile("FMT_STATIC_ASSERT(true, \"this should never happen\");") expect_compile_error("FMT_STATIC_ASSERT(0 > 1, \"oops\");") # Make sure that compiler features detected in the header From f3d6d3a8f2bb675c5c6a636fd6cc989a213df46c Mon Sep 17 00:00:00 2001 From: Dean Moldovan Date: Wed, 4 May 2016 00:51:28 +0200 Subject: [PATCH 3/3] Fix find-package-test failure with non-default compiler The failure would happen when the main project was configured with a compiler which is not the system default. The new configuration was not forwarded to "ctest --build-and-test". This fixes it. --- test/CMakeLists.txt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3506b461..c329749b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -137,8 +137,10 @@ if (FMT_PEDANTIC) "${CMAKE_CURRENT_BINARY_DIR}/find-package-test" --build-generator ${CMAKE_GENERATOR} --build-makeprogram ${CMAKE_MAKE_PROGRAM} - --build-options "-DFMT_DIR=${PROJECT_BINARY_DIR}" - "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}") + --build-options + "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" + "-DFMT_DIR=${PROJECT_BINARY_DIR}" + "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}") # test if the targets are findable when add_subdirectory is used add_test(add-subdirectory-test ${CMAKE_CTEST_COMMAND} @@ -148,5 +150,7 @@ if (FMT_PEDANTIC) "${CMAKE_CURRENT_BINARY_DIR}/add-subdirectory-test" --build-generator ${CMAKE_GENERATOR} --build-makeprogram ${CMAKE_MAKE_PROGRAM} - --build-options "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}") + --build-options + "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" + "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}") endif ()