From fd7dbcc07b82cb1f78ddce51df9108b04199db1e Mon Sep 17 00:00:00 2001 From: "Watal M. Iwasaki" Date: Wed, 1 Aug 2018 18:07:39 +0900 Subject: [PATCH 1/3] Support CMake system --- CMakeLists.txt | 34 ++++++++++++++++++++++++++++++++++ test/CMakeLists.txt | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 test/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..ea82b61 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,34 @@ +cmake_minimum_required(VERSION 3.1) +project(clipp CXX) + +include(GNUInstallDirs) +set(CMAKE_VERBOSE_MAKEFILE TRUE) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED TRUE) +set(CMAKE_CXX_EXTENSIONS FALSE) + +message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}") + +install(DIRECTORY include/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING PATTERN "*.h" +) + +add_library(${PROJECT_NAME} INTERFACE) +target_include_directories(${PROJECT_NAME} INTERFACE + $ + $ +) +install(TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME}-config +) +install(EXPORT ${PROJECT_NAME}-config + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME} +) + +option(BUILD_TESTING "Do not build tests by default" FALSE) +include(CTest) +if(BUILD_TESTING) + add_subdirectory(test) +endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..5d4f867 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,38 @@ +if (NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Debug) +endif() +message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") + +message(STATUS "CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}") +if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") + add_compile_options(-stdlib=libc++) +else() + add_compile_options(-Wlogical-op) + add_compile_options(-Wnoexcept) + add_compile_options(-Wstrict-null-sentinel) + add_compile_options(-Wuseless-cast) +endif() +add_compile_options(-Wall -Wextra -Wpedantic) +add_compile_options(-Wcast-align -Wcast-qual) +add_compile_options(-Wctor-dtor-privacy) +add_compile_options(-Wconversion -Wno-sign-conversion) +add_compile_options(-Wdisabled-optimization) +add_compile_options(-Wdouble-promotion) +add_compile_options(-Wformat=2) +add_compile_options(-Winit-self) +add_compile_options(-Wmissing-include-dirs) +add_compile_options(-Wold-style-cast) +add_compile_options(-Woverloaded-virtual) +add_compile_options(-Wredundant-decls) +add_compile_options(-Wshadow) +add_compile_options(-Wstrict-aliasing=1) +add_compile_options(-Wstrict-overflow=5) +add_compile_options(-Wswitch-default) +add_compile_options(-Wundef) + +aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} source_files) +foreach(src IN LISTS source_files) + get_filename_component(name_we ${src} NAME_WE) + add_executable(test-${name_we} ${src}) + add_test(NAME ${name_we} COMMAND $) +endforeach() From 657105822187b662b7f5b09f58b943e9b072d513 Mon Sep 17 00:00:00 2001 From: "Watal M. Iwasaki" Date: Sun, 9 Sep 2018 15:24:59 +0900 Subject: [PATCH 2/3] Manage version number in CMake system --- CMakeLists.txt | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ea82b61..ff9ec08 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,7 @@ cmake_minimum_required(VERSION 3.1) -project(clipp CXX) +project(clipp + VERSION 1.2.0 + LANGUAGES CXX) include(GNUInstallDirs) set(CMAKE_VERBOSE_MAKEFILE TRUE) @@ -9,23 +11,31 @@ set(CMAKE_CXX_STANDARD_REQUIRED TRUE) set(CMAKE_CXX_EXTENSIONS FALSE) message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}") - -install(DIRECTORY include/ - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} - FILES_MATCHING PATTERN "*.h" -) - add_library(${PROJECT_NAME} INTERFACE) target_include_directories(${PROJECT_NAME} INTERFACE $ $ ) + +set(CONFIG_VERSION_FILE ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake) +include(CMakePackageConfigHelpers) +write_basic_package_version_file( + ${CONFIG_VERSION_FILE} COMPATIBILITY AnyNewerVersion +) + +install(DIRECTORY include/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING PATTERN "*.h" +) install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}-config ) install(EXPORT ${PROJECT_NAME}-config DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME} ) +install(FILES ${CONFIG_VERSION_FILE} + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME} +) option(BUILD_TESTING "Do not build tests by default" FALSE) include(CTest) From 65f23f941cd65077cecb32f07639b9a63d73d9a9 Mon Sep 17 00:00:00 2001 From: "Watal M. Iwasaki" Date: Tue, 30 Apr 2019 16:02:07 +0900 Subject: [PATCH 3/3] Modernize CMakeLists.txt - Replace CMAKE_CXX_STANDARD with target_compile_features() - Require CMake version 3.8 for the meta flag "cxx_std_11" - Export namespace - Support sub_directory(): include_directory, namespace alias - Update version to 1.2.3 - Fix some commands and variables for testing --- CMakeLists.txt | 19 +++++++++---------- test/CMakeLists.txt | 5 +++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ff9ec08..5fd1b5c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,19 +1,17 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.8) project(clipp - VERSION 1.2.0 + VERSION 1.2.3 LANGUAGES CXX) include(GNUInstallDirs) -set(CMAKE_VERBOSE_MAKEFILE TRUE) - -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED TRUE) -set(CMAKE_CXX_EXTENSIONS FALSE) +set(CMAKE_VERBOSE_MAKEFILE ON) message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}") add_library(${PROJECT_NAME} INTERFACE) +add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) +target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_11) target_include_directories(${PROJECT_NAME} INTERFACE - $ + $ $ ) @@ -32,13 +30,14 @@ install(TARGETS ${PROJECT_NAME} ) install(EXPORT ${PROJECT_NAME}-config DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME} + NAMESPACE ${PROJECT_NAME}:: ) install(FILES ${CONFIG_VERSION_FILE} DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME} ) -option(BUILD_TESTING "Do not build tests by default" FALSE) +option(BUILD_TESTING "Do not build tests by default" OFF) include(CTest) -if(BUILD_TESTING) +if(BUILD_TESTING AND ${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR}) add_subdirectory(test) endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5d4f867..3fececc 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -34,5 +34,10 @@ aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} source_files) foreach(src IN LISTS source_files) get_filename_component(name_we ${src} NAME_WE) add_executable(test-${name_we} ${src}) + target_link_libraries(test-${name_we} ${PROJECT_NAME}::${PROJECT_NAME}) + set_target_properties(test-${name_we} PROPERTIES + CXX_STANDARD_REQUIRED ON + CXX_EXTENSIONS OFF + ) add_test(NAME ${name_we} COMMAND $) endforeach()