From cb08b67e9db3f90bd2394a7318dbb09a6cf271d0 Mon Sep 17 00:00:00 2001 From: neargye Date: Thu, 1 Aug 2019 00:48:50 +0500 Subject: [PATCH] clean-up cmake: * formating * remove set(CMAKE_VERBOSE_MAKEFILE * use function to simplify test --- CMakeLists.txt | 26 +++++++++++++------------- example/CMakeLists.txt | 4 +--- test/CMakeLists.txt | 33 ++++++++++++--------------------- 3 files changed, 26 insertions(+), 37 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index de1001c..728e101 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,12 +8,12 @@ option(NAMEOF_OPT_BUILD_EXAMPLES "Build nameof examples" OFF) option(NAMEOF_OPT_BUILD_TESTS "Build and perform nameof tests" OFF) if(NAMEOF_OPT_BUILD_EXAMPLES) - add_subdirectory(example) + add_subdirectory(example) endif() if(NAMEOF_OPT_BUILD_TESTS) - enable_testing() - add_subdirectory(test) + enable_testing() + add_subdirectory(test) endif() include(CMakePackageConfigHelpers) @@ -22,23 +22,23 @@ add_library(${PROJECT_NAME} INTERFACE) add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17) target_include_directories(${PROJECT_NAME} - INTERFACE - $ - $) + INTERFACE + $ + $) write_basic_package_version_file(${PROJECT_NAME}ConfigVersion.cmake - VERSION ${PROJECT_VERSION} - COMPATIBILITY AnyNewerVersion) + VERSION ${PROJECT_VERSION} + COMPATIBILITY AnyNewerVersion) install(TARGETS ${PROJECT_NAME} - EXPORT ${PROJECT_NAME}Config) + EXPORT ${PROJECT_NAME}Config) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake - DESTINATION lib/cmake/${PROJECT_NAME}) + DESTINATION lib/cmake/${PROJECT_NAME}) install(EXPORT ${PROJECT_NAME}Config - NAMESPACE ${PROJECT_NAME}:: - DESTINATION lib/cmake/${PROJECT_NAME}) + NAMESPACE ${PROJECT_NAME}:: + DESTINATION lib/cmake/${PROJECT_NAME}) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include - DESTINATION .) + DESTINATION .) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 7166004..4ccaf1d 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -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) set_target_properties(example PROPERTIES CXX_EXTENSIONS OFF) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9a44569..4f08822 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -3,34 +3,25 @@ include(CheckCXXCompilerFlag) check_cxx_compiler_flag(-std=c++20 HAS_GNU_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)) +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_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 - $<$,$,$>: - -Wall -Wextra -pedantic-errors -Werror> - $<$: - /W4 /WX> -) - -if(HAS_CPP20 AND (cxx_std_20 IN_LIST CMAKE_CXX_COMPILE_FEATURES)) - add_executable(test-20 test.cpp) - 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 + target_compile_options(${target} PRIVATE $<$,$,$>: -Wall -Wextra -pedantic-errors -Werror> $<$: /W4 /WX> ) +endfunction() + +make_test(nameof-cpp17.t cxx_std_17) + +if(HAS_CPP20 AND (cxx_std_20 IN_LIST CMAKE_CXX_COMPILE_FEATURES)) + make_test(nameof-cpp20.t cxx_std_20) endif()