Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support CMake system #11

Merged
merged 3 commits into from Apr 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 43 additions & 0 deletions CMakeLists.txt
@@ -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()
43 changes: 43 additions & 0 deletions test/CMakeLists.txt
@@ -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()