Commit 6825ac9c authored by Victor Zverovich's avatar Victor Zverovich

Merge pull request #313 from dean0x7d/test-fixes

Fix a few bugs related to compile tests
parents 40421982 f3d6d3a8
...@@ -137,8 +137,10 @@ if (FMT_PEDANTIC) ...@@ -137,8 +137,10 @@ if (FMT_PEDANTIC)
"${CMAKE_CURRENT_BINARY_DIR}/find-package-test" "${CMAKE_CURRENT_BINARY_DIR}/find-package-test"
--build-generator ${CMAKE_GENERATOR} --build-generator ${CMAKE_GENERATOR}
--build-makeprogram ${CMAKE_MAKE_PROGRAM} --build-makeprogram ${CMAKE_MAKE_PROGRAM}
--build-options "-DFMT_DIR=${PROJECT_BINARY_DIR}" --build-options
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}") "-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 # test if the targets are findable when add_subdirectory is used
add_test(add-subdirectory-test ${CMAKE_CTEST_COMMAND} add_test(add-subdirectory-test ${CMAKE_CTEST_COMMAND}
...@@ -148,5 +150,7 @@ if (FMT_PEDANTIC) ...@@ -148,5 +150,7 @@ if (FMT_PEDANTIC)
"${CMAKE_CURRENT_BINARY_DIR}/add-subdirectory-test" "${CMAKE_CURRENT_BINARY_DIR}/add-subdirectory-test"
--build-generator ${CMAKE_GENERATOR} --build-generator ${CMAKE_GENERATOR}
--build-makeprogram ${CMAKE_MAKE_PROGRAM} --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 () endif ()
...@@ -9,7 +9,7 @@ set(CMAKE_REQUIRED_FLAGS ${CPP11_FLAG}) ...@@ -9,7 +9,7 @@ set(CMAKE_REQUIRED_FLAGS ${CPP11_FLAG})
function (generate_source result fragment) function (generate_source result fragment)
set(${result} " set(${result} "
#define FMT_HEADER_ONLY 1 #define FMT_HEADER_ONLY 1
#include \"fmt/format.h\" #include \"fmt/posix.h\"
int main() { int main() {
${fragment} ${fragment}
} }
...@@ -20,22 +20,28 @@ function (expect_compile code) ...@@ -20,22 +20,28 @@ function (expect_compile code)
generate_source(source "${code}") generate_source(source "${code}")
check_cxx_source_compiles("${source}" compiles) check_cxx_source_compiles("${source}" compiles)
if (NOT compiles) if (NOT compiles)
message(FATAL_ERROR "Compile error for: ${code}") set(error_msg "Compile error for: ${code}")
endif () endif ()
# Unset the CMake cache variable compiles. Otherwise the compile test will # Unset the CMake cache variable compiles. Otherwise the compile test will
# just use cached information next time it runs. # just use cached information next time it runs.
unset(compiles CACHE) unset(compiles CACHE)
if (error_msg)
message(FATAL_ERROR ${error_msg})
endif ()
endfunction () endfunction ()
function (expect_compile_error code) function (expect_compile_error code)
generate_source(source "${code}") generate_source(source "${code}")
check_cxx_source_compiles("${source}" compiles) check_cxx_source_compiles("${source}" compiles)
if (compiles) if (compiles)
message(FATAL_ERROR "No compile error for: ${code}") set(error_msg "No compile error for: ${code}")
endif () endif ()
# Unset the CMake cache variable compiles. Otherwise the compile test will # Unset the CMake cache variable compiles. Otherwise the compile test will
# just use cached information next time it runs. # just use cached information next time it runs.
unset(compiles CACHE) unset(compiles CACHE)
if (error_msg)
message(FATAL_ERROR ${error_msg})
endif ()
endfunction () endfunction ()
# check if the source file skeleton compiles # check if the source file skeleton compiles
...@@ -57,6 +63,7 @@ expect_compile_error("fmt::MemoryWriter() << fmt::pad(42, 5, L' ');") ...@@ -57,6 +63,7 @@ expect_compile_error("fmt::MemoryWriter() << fmt::pad(42, 5, L' ');")
# Formatting a wide character with a narrow format string is forbidden. # Formatting a wide character with a narrow format string is forbidden.
expect_compile_error("fmt::format(\"{}\", L'a';") 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\");") expect_compile_error("FMT_STATIC_ASSERT(0 > 1, \"oops\");")
# Make sure that compiler features detected in the header # Make sure that compiler features detected in the header
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment