clean-up cmake:

* formating
* remove set(CMAKE_VERBOSE_MAKEFILE
* use function to simplify test
This commit is contained in:
neargye 2019-08-01 00:48:50 +05:00
parent 0639b4b0c4
commit cb08b67e9d
3 changed files with 26 additions and 37 deletions

View file

@ -1,6 +1,4 @@
# set(CMAKE_VERBOSE_MAKEFILE ON) add_executable(example example.cpp)
add_executable(example example.cpp)
target_link_libraries(example PRIVATE nameof::nameof) target_link_libraries(example PRIVATE nameof::nameof)
set_target_properties(example PROPERTIES CXX_EXTENSIONS OFF) set_target_properties(example PROPERTIES CXX_EXTENSIONS OFF)

View file

@ -3,34 +3,25 @@
include(CheckCXXCompilerFlag) include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(-std=c++20 HAS_GNU_CPP20_FLAG) check_cxx_compiler_flag(-std=c++20 HAS_GNU_CPP20_FLAG)
check_cxx_compiler_flag(/std:c++20 HAS_MSVC_CPP20_FLAG) check_cxx_compiler_flag(/std:c++20 HAS_MSVC_CPP20_FLAG)
set(HAS_CPP20 (HAS_GNU_CPP20_FLAG OR HAS_MSVC_CPP20_FLAG)) set(HAS_CPP20 (HAS_GNU_CPP20_FLAG OR HAS_MSVC_CPP20_FLAG))
function(make_test target std)
add_executable(${target} test.cpp)
target_link_libraries(${target} PRIVATE Catch2::Catch2 nameof::nameof)
set_target_properties(${target} PROPERTIES CXX_EXTENSIONS OFF)
target_compile_features(${target} PRIVATE ${std})
add_executable(test-17 test.cpp) target_compile_options(${target}
target_link_libraries(test-17 PRIVATE Catch2::Catch2 nameof::nameof)
set_target_properties(test-17 PROPERTIES CXX_EXTENSIONS OFF)
target_compile_features(test-17 PRIVATE cxx_std_17)
target_compile_options(test-17
PRIVATE PRIVATE
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>: $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-Wall -Wextra -pedantic-errors -Werror> -Wall -Wextra -pedantic-errors -Werror>
$<$<CXX_COMPILER_ID:MSVC>: $<$<CXX_COMPILER_ID:MSVC>:
/W4 /WX> /W4 /WX>
) )
endfunction()
make_test(nameof-cpp17.t cxx_std_17)
if(HAS_CPP20 AND (cxx_std_20 IN_LIST CMAKE_CXX_COMPILE_FEATURES)) if(HAS_CPP20 AND (cxx_std_20 IN_LIST CMAKE_CXX_COMPILE_FEATURES))
add_executable(test-20 test.cpp) make_test(nameof-cpp20.t cxx_std_20)
target_link_libraries(test-20 PRIVATE Catch2::Catch2 nameof::nameof)
set_target_properties(test-20 PROPERTIES CXX_EXTENSIONS OFF)
target_compile_features(test-20 PRIVATE cxx_std_20)
target_compile_options(test-20
PRIVATE
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-Wall -Wextra -pedantic-errors -Werror>
$<$<CXX_COMPILER_ID:MSVC>:
/W4 /WX>
)
endif() endif()