From 09864fe578dfe8b55486e401ddbf933156f82099 Mon Sep 17 00:00:00 2001 From: neargye Date: Tue, 12 Mar 2019 18:55:56 +0500 Subject: [PATCH] update cmake --- CMakeLists.txt | 14 ++------------ example/CMakeLists.txt | 19 +++++++++++-------- test/CMakeLists.txt | 32 +++++++++++++++++++------------- 3 files changed, 32 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c94b4bb..d9b687e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,18 +1,10 @@ -cmake_minimum_required(VERSION 3.2) +cmake_minimum_required(VERSION 3.6) -include(GNUInstallDirs) - -project(nameof LANGUAGES CXX) -set(${PROJECT_NAME}_version "0.5.0") -set(package_name ${PROJECT_NAME}) -set(include_source_dir "${CMAKE_SOURCE_DIR}/include") +project(nameof VERSION "0.3.0" LANGUAGES CXX) option(NAMEOF_OPT_BUILD_EXAMPLES "Build nameof examples" ON) option(NAMEOF_OPT_BUILD_TESTS "Build and perform nameof tests" ON) -add_library(${package_name} INTERFACE) -target_include_directories(${package_name} INTERFACE "$") - if(NAMEOF_OPT_BUILD_EXAMPLES) add_subdirectory(example) endif() @@ -21,5 +13,3 @@ if(NAMEOF_OPT_BUILD_TESTS) enable_testing() add_subdirectory(test) endif() - -install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index e60b0b8..975e54b 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -1,16 +1,19 @@ -set(SOURCES example.cpp ${CMAKE_SOURCE_DIR}/include/nameof.hpp) +include_directories(${CMAKE_SOURCE_DIR}/include) -include_directories(${CMAKE_SOURCE_DIR}/include) - -add_executable(example ${SOURCES}) +set(OPTIONS "") if((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) set(CMAKE_VERBOSE_MAKEFILE ON) - target_compile_options(example PRIVATE -Wall -Wextra -pedantic-errors) - target_compile_options(example PRIVATE -std=c++11) + set(OPTIONS -Wall -Wextra -pedantic-errors) + set(OPTIONS ${OPTIONS} -std=c++11) elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") - target_compile_options(example PRIVATE /W4) + set(OPTIONS /W4) if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.11) - target_compile_options(example PRIVATE /permissive-) + set(OPTIONS ${OPTIONS} /permissive-) endif() endif() + +add_executable(example + example.cpp + ${CMAKE_SOURCE_DIR}/include/nameof.hpp) +target_compile_options(example PRIVATE ${OPTIONS}) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8f5737d..1b736e2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,8 +1,8 @@ -set(SOURCES test.cpp) - -include_directories(3rdparty/Catch2) +include_directories(3rdparty/Catch2) include_directories(${CMAKE_SOURCE_DIR}/include) +set(SOURCES test.cpp) + set(OPTIONS "") set(HAS_CPP11_FLAG FALSE) @@ -14,6 +14,8 @@ set(HAS_CPPLATEST_FLAG FALSE) if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") set(OPTIONS /W4) + set(HAS_CPP11_FLAG TRUE) + if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.00) set(HAS_CPP14_FLAG TRUE) set(HAS_CPPLATEST_FLAG TRUE) @@ -23,6 +25,8 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") set(HAS_CPP17_FLAG TRUE) set(OPTIONS ${OPTIONS} /permissive-) endif() + + set(OPTIONS ${OPTIONS} /wd4702) # Disable warning C4702: unreachable code elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") set(CMAKE_VERBOSE_MAKEFILE ON) set(OPTIONS -Wall -Wextra -pedantic-errors) @@ -65,15 +69,17 @@ function(make_target target std) endfunction() if(HAS_CPP11_FLAG) - make_target(nameof-cpp11.t c++11) -elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") - make_target(nameof-cpp11.t "") + if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + make_target(${CMAKE_PROJECT_NAME}-cpp11.t "") + else() + make_target(${CMAKE_PROJECT_NAME}-cpp11.t c++11) + endif() + add_test(NAME ${CMAKE_PROJECT_NAME}-cpp11.t COMMAND ${CMAKE_PROJECT_NAME}-cpp11.t) endif() -add_test(NAME nameof-cpp11.t COMMAND nameof-cpp11.t) if(HAS_CPP14_FLAG) - make_target(nameof-cpp14.t c++14) - add_test(NAME nameof-cpp14.t COMMAND nameof-cpp14.t) + make_target(${CMAKE_PROJECT_NAME}-cpp14.t c++14) + add_test(NAME ${CMAKE_PROJECT_NAME}-cpp14.t COMMAND ${CMAKE_PROJECT_NAME}-cpp14.t) endif() if(HAS_CPP17_FLAG) @@ -81,11 +87,11 @@ if(HAS_CPP17_FLAG) if(CMAKE_CXX_COMPILER_ID MATCHES "AppleClang") set(std17 c++1z) endif() - make_target(nameof-cpp17.t ${std17}) - add_test(NAME nameof-cpp17.t COMMAND nameof-cpp17.t) + make_target(${CMAKE_PROJECT_NAME}-cpp17.t ${std17}) + add_test(NAME ${CMAKE_PROJECT_NAME}-cpp17.t COMMAND ${CMAKE_PROJECT_NAME}-cpp17.t) endif() if(HAS_CPPLATEST_FLAG) - make_target(nameof-cpplatest.t c++latest) - add_test(NAME nameof-cpplatest.t COMMAND nameof-cpplatest.t) + make_target(${CMAKE_PROJECT_NAME}-cpplatest.t c++latest) + add_test(NAME ${CMAKE_PROJECT_NAME}-cpplatest.t COMMAND ${CMAKE_PROJECT_NAME}-cpplatest.t) endif()