Skip to content

Commit 2c32b2f

Browse files
authored
Merge pull request muellan#11 from heavywatal/cmake
CMake Support
2 parents 14212e9 + 65f23f9 commit 2c32b2f

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
cmake_minimum_required(VERSION 3.8)
2+
project(clipp
3+
VERSION 1.2.3
4+
LANGUAGES CXX)
5+
6+
include(GNUInstallDirs)
7+
set(CMAKE_VERBOSE_MAKEFILE ON)
8+
9+
message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
10+
add_library(${PROJECT_NAME} INTERFACE)
11+
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
12+
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_11)
13+
target_include_directories(${PROJECT_NAME} INTERFACE
14+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
15+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
16+
)
17+
18+
set(CONFIG_VERSION_FILE ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake)
19+
include(CMakePackageConfigHelpers)
20+
write_basic_package_version_file(
21+
${CONFIG_VERSION_FILE} COMPATIBILITY AnyNewerVersion
22+
)
23+
24+
install(DIRECTORY include/
25+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
26+
FILES_MATCHING PATTERN "*.h"
27+
)
28+
install(TARGETS ${PROJECT_NAME}
29+
EXPORT ${PROJECT_NAME}-config
30+
)
31+
install(EXPORT ${PROJECT_NAME}-config
32+
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}
33+
NAMESPACE ${PROJECT_NAME}::
34+
)
35+
install(FILES ${CONFIG_VERSION_FILE}
36+
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}
37+
)
38+
39+
option(BUILD_TESTING "Do not build tests by default" OFF)
40+
include(CTest)
41+
if(BUILD_TESTING AND ${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
42+
add_subdirectory(test)
43+
endif()

test/CMakeLists.txt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
if (NOT CMAKE_BUILD_TYPE)
2+
set(CMAKE_BUILD_TYPE Debug)
3+
endif()
4+
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
5+
6+
message(STATUS "CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}")
7+
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
8+
add_compile_options(-stdlib=libc++)
9+
else()
10+
add_compile_options(-Wlogical-op)
11+
add_compile_options(-Wnoexcept)
12+
add_compile_options(-Wstrict-null-sentinel)
13+
add_compile_options(-Wuseless-cast)
14+
endif()
15+
add_compile_options(-Wall -Wextra -Wpedantic)
16+
add_compile_options(-Wcast-align -Wcast-qual)
17+
add_compile_options(-Wctor-dtor-privacy)
18+
add_compile_options(-Wconversion -Wno-sign-conversion)
19+
add_compile_options(-Wdisabled-optimization)
20+
add_compile_options(-Wdouble-promotion)
21+
add_compile_options(-Wformat=2)
22+
add_compile_options(-Winit-self)
23+
add_compile_options(-Wmissing-include-dirs)
24+
add_compile_options(-Wold-style-cast)
25+
add_compile_options(-Woverloaded-virtual)
26+
add_compile_options(-Wredundant-decls)
27+
add_compile_options(-Wshadow)
28+
add_compile_options(-Wstrict-aliasing=1)
29+
add_compile_options(-Wstrict-overflow=5)
30+
add_compile_options(-Wswitch-default)
31+
add_compile_options(-Wundef)
32+
33+
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} source_files)
34+
foreach(src IN LISTS source_files)
35+
get_filename_component(name_we ${src} NAME_WE)
36+
add_executable(test-${name_we} ${src})
37+
target_link_libraries(test-${name_we} ${PROJECT_NAME}::${PROJECT_NAME})
38+
set_target_properties(test-${name_we} PROPERTIES
39+
CXX_STANDARD_REQUIRED ON
40+
CXX_EXTENSIONS OFF
41+
)
42+
add_test(NAME ${name_we} COMMAND $<TARGET_FILE:test-${name_we}>)
43+
endforeach()

0 commit comments

Comments
 (0)