-
Notifications
You must be signed in to change notification settings - Fork 57
/
CMakeLists.txt
80 lines (65 loc) · 2.18 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
cmake_minimum_required(VERSION 3.8.0)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
project(cpp-sort VERSION 1.5.0 LANGUAGES CXX)
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
# Project options
option(BUILD_TESTING "Build the cpp-sort test suite" ON)
option(ENABLE_COVERAGE "Whether to make suitable build for code coverage" OFF)
option(USE_VALGRIND "Whether to run the tests with Valgrind" OFF)
# Create cpp-sort library and configure it
add_library(cpp-sort INTERFACE)
target_include_directories(cpp-sort INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_compile_features(cpp-sort INTERFACE cxx_std_14)
add_library(cpp-sort::cpp-sort ALIAS cpp-sort)
# Install targets and files
install(
TARGETS cpp-sort
EXPORT cpp-sort-targets
DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(
EXPORT cpp-sort-targets
NAMESPACE cpp-sort::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cpp-sort"
)
install(
DIRECTORY "include/"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
configure_package_config_file(
${CMAKE_SOURCE_DIR}/cmake/cpp-sort-config.cmake.in
${CMAKE_BINARY_DIR}/cmake/cpp-sort-config.cmake
INSTALL_DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/cpp-sort
)
# Bypass automatic architeture check introduced by CMake,
# use the ARCH_INDEPENDENT option for this in the future
set(CPPSORT_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
unset(CMAKE_SIZEOF_VOID_P)
write_basic_package_version_file(
${CMAKE_BINARY_DIR}/cmake/cpp-sort-config-version.cmake
COMPATIBILITY
SameMajorVersion
)
set(CMAKE_SIZEOF_VOID_P ${CPPSORT_SIZEOF_VOID_P})
install(
FILES
${CMAKE_BINARY_DIR}/cmake/cpp-sort-config.cmake
${CMAKE_BINARY_DIR}/cmake/cpp-sort-config-version.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cpp-sort
)
# Export target so that it can be used in subdirectories
export(
EXPORT cpp-sort-targets
FILE ${CMAKE_BINARY_DIR}/cmake/cpp-sort-targets.cmake
NAMESPACE cpp-sort::
)
# Build tests if this is the main project
if (BUILD_TESTING AND (PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR))
enable_testing()
add_subdirectory(testsuite)
endif()