-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from heavywatal/cmake
CMake Support
- Loading branch information
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
cmake_minimum_required(VERSION 3.8) | ||
project(clipp | ||
VERSION 1.2.3 | ||
LANGUAGES CXX) | ||
|
||
include(GNUInstallDirs) | ||
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 | ||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> | ||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> | ||
) | ||
|
||
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} | ||
NAMESPACE ${PROJECT_NAME}:: | ||
) | ||
install(FILES ${CONFIG_VERSION_FILE} | ||
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME} | ||
) | ||
|
||
option(BUILD_TESTING "Do not build tests by default" OFF) | ||
include(CTest) | ||
if(BUILD_TESTING AND ${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR}) | ||
add_subdirectory(test) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
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}) | ||
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 $<TARGET_FILE:test-${name_we}>) | ||
endforeach() |