-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
134 lines (112 loc) · 3.91 KB
/
CMakeLists.txt
File metadata and controls
134 lines (112 loc) · 3.91 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# Copyright (c) 2015-2026 Morwenn
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.11.0)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
project(cpp-sort VERSION 2.1.0 LANGUAGES CXX)
include(CMakePackageConfigHelpers)
include(cpp-sort-utils)
include(GNUInstallDirs)
# Project options
option(CPPSORT_BUILD_TESTING "Build the cpp-sort test suite" ${BUILD_TESTING})
option(CPPSORT_BUILD_EXAMPLES "Build the cpp-sort examples" OFF)
option(CPPSORT_ENABLE_AUDITS "Enable assertions in the library" OFF)
option(CPPSORT_ENABLE_ASSERTIONS "Enable assertions in the library" ${CPPSORT_ENABLE_AUDITS})
option(CPPSORT_USE_LIBASSERT "Use libassert for assertions (experimental)" OFF)
# Optionally use libassert for assertions
if (CPPSORT_USE_LIBASSERT)
include(FetchContent)
FetchContent_Declare(
libassert
GIT_REPOSITORY https://github.com/jeremy-rifkin/libassert
GIT_TAG bd33ba116f209bf71761c58dccc2f3bf277e0824 # v2.2.1
)
FetchContent_GetProperties(libassert)
if (NOT libassert_POPULATED)
FetchContent_Populate(libassert)
add_subdirectory(${libassert_SOURCE_DIR} ${libassert_BINARY_DIR})
mark_system_library(libassert-lib)
endif()
endif()
# 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_17)
# MSVC won't work without a stricter standard compliance
if (MSVC)
target_compile_options(cpp-sort INTERFACE
$<$<COMPILE_LANGUAGE:CXX>:/permissive->
$<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler="/permissive-">
)
endif()
# Handle diagnostic options
if (CPPSORT_ENABLE_ASSERTIONS)
target_compile_definitions(cpp-sort INTERFACE CPPSORT_ENABLE_ASSERTIONS)
endif()
if (CPPSORT_ENABLE_AUDITS)
target_compile_definitions(cpp-sort INTERFACE CPPSORT_ENABLE_AUDITS)
endif()
# Optionally link to libassert
if (CPPSORT_USE_LIBASSERT)
target_link_libraries(cpp-sort INTERFACE libassert::assert)
target_compile_definitions(cpp-sort INTERFACE CPPSORT_USE_LIBASSERT)
if (MSVC)
target_compile_options(cpp-sort INTERFACE /Zc:preprocessor)
endif()
endif()
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_CURRENT_SOURCE_DIR}/cmake/cpp-sort-config.cmake.in
${CMAKE_CURRENT_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_CURRENT_BINARY_DIR}/cmake/cpp-sort-config-version.cmake
COMPATIBILITY
SameMajorVersion
)
set(CMAKE_SIZEOF_VOID_P ${CPPSORT_SIZEOF_VOID_P})
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/cmake/cpp-sort-config.cmake
${CMAKE_CURRENT_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_CURRENT_BINARY_DIR}/cmake/cpp-sort-targets.cmake
NAMESPACE cpp-sort::
)
# Build tests and/or examples if this is the main project
if (PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
if (CPPSORT_BUILD_TESTING)
enable_testing()
add_subdirectory(tests)
endif()
if (CPPSORT_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
endif()