Skip to content

Commit

Permalink
CMake: Refactor compilation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Mar 11, 2019
1 parent b416176 commit 1e8e80f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions test/integration/compilation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,31 @@
# This CMake script creates multiple additional targets to test the compilation of public headers
# with different C and C++ standards.

list(APPEND all_features ${CMAKE_CXX_COMPILE_FEATURES})
list(APPEND all_features ${CMAKE_C_COMPILE_FEATURES})

# Disable standard extensions globally for test targets.
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_C_EXTENSIONS OFF)

macro(create_compilation_test STANDARD)
if (${STANDARD} MATCHES "^(C|CXX)([0-9]+)$")
if (${STANDARD} MATCHES "^(c|cxx)_std_([0-9]+)$")
set(lang ${CMAKE_MATCH_1})
set(num ${CMAKE_MATCH_2})
else()
message(FATAL_ERROR "Unknown language standard: ${STANDARD}")
message(FATAL_ERROR "Unknown standard: ${STANDARD}")
endif()

if (lang STREQUAL CXX)
set(ext cpp)
if(${STANDARD} IN_LIST all_features)
set(target test-compile-${STANDARD})
add_library(${target} OBJECT compilation_test.${lang})
target_compile_features(${target} PRIVATE ${STANDARD})
target_include_directories(${target} PRIVATE ${include_dir})
else()
set(ext c)
message(STATUS "Compilation test SKIPPED: ${STANDARD}")
endif()

string(TOLOWER ${STANDARD} standard)
set(target test-compile-${standard})

add_library(${target} OBJECT compilation_test.${ext})
target_include_directories(${target} PRIVATE ${include_dir})
set_target_properties(${target} PROPERTIES ${lang}_STANDARD ${num} ${lang}_EXTENSIONS OFF)
endmacro()

foreach(standard C90;C99;C11;CXX11;CXX14;CXX17)
foreach(standard cxx_std_11;cxx_std_14;cxx_std_17;c_std_90;c_std_99;c_std_11)
create_compilation_test(${standard})
endforeach()

0 comments on commit 1e8e80f

Please sign in to comment.