update cmake

This commit is contained in:
neargye 2019-03-12 18:55:56 +05:00
parent 9faad26eb1
commit 09864fe578
3 changed files with 32 additions and 33 deletions

View file

@ -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 "$<BUILD_INTERFACE:${include_source_dir}>")
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})

View file

@ -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})

View file

@ -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()