From 01fa5dff3575ff21339a2105c08fa9673ec9d1b2 Mon Sep 17 00:00:00 2001 From: Joe Jordan Date: Mon, 25 Jan 2021 12:48:56 +0000 Subject: [PATCH] Check availability of compile flags at cmake time Fixes #3821 Ensures that compile flag can be used before using it. Gives a message if flag cannot be used. --- api/nblib/samples/tests/CMakeLists.txt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/api/nblib/samples/tests/CMakeLists.txt b/api/nblib/samples/tests/CMakeLists.txt index 972c252fac..b4b0576dbc 100644 --- a/api/nblib/samples/tests/CMakeLists.txt +++ b/api/nblib/samples/tests/CMakeLists.txt @@ -48,8 +48,14 @@ gmx_add_gtest_executable( # files with code for tests argon-sample.cpp ) -#The following line is a not so nice hack to prevent compiler warnings that are not relevant for the sample scripts -set_source_files_properties(argon-sample.cpp PROPERTIES COMPILE_FLAGS "-Wno-header-hygiene") -target_link_libraries(nblib-samples-test PRIVATE nblib) -gmx_register_gtest_test(${testname} ${exename}) -add_dependencies(check-nblib ${exename}) +#The following compiler option prevents compiler warnings that are not relevant for the sample scripts +set(sampleCompileFlag "-Wno-header-hygiene") +check_cxx_compiler_flag(${sampleCompileFlag} CanCompileSamples) +if(CanCompileSamples) + set_source_files_properties(argon-sample.cpp PROPERTIES COMPILE_FLAGS ${sampleCompileFlag}) + target_link_libraries(nblib-samples-test PRIVATE nblib) + gmx_register_gtest_test(${testname} ${exename}) + add_dependencies(check-nblib ${exename}) +else() + message(WARNING "Failed to test compile with flag ${sampleCompileFlag}, so samples cannot be compiled.") +endif() \ No newline at end of file -- 2.22.0