This repository has been archived by the owner on Nov 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
114 lines (88 loc) · 3.5 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
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
cmake_minimum_required(VERSION 3.15)
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/version.txt" projectVersion)
project(ssp VERSION ${projectVersion})
message("Current ${PROJECT_NAME} version: ${CMAKE_PROJECT_VERSION}\n")
# ==============================================================================
# Build settings
# ==============================================================================
option(SSP_BUILD_TESTS "Build tests" OFF)
# ==============================================================================
# Global internal configuration
# ==============================================================================
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
# Prepare for export and installation.
set(SSP_HEADER_INSTALL_DIR "include")
if (WIN32)
set(SSP_CMAKE_INSTALL_DIR "cmake")
else ()
set(SSP_CMAKE_INSTALL_DIR "share/${PROJECT_NAME}/cmake")
endif ()
set(SSP_INSTALL_DESTINATIONS
ARCHIVE DESTINATION "lib"
LIBRARY DESTINATION "lib"
RUNTIME DESTINATION "bin"
INCLUDES DESTINATION "${SSP_HEADER_INSTALL_DIR}")
set(SSP_EXPORT_TARGET "${PROJECT_NAME}-targets")
# ==============================================================================
# Dependencies
# ==============================================================================
if (CONAN_EXPORTED) # in conan local cache
# standard conan installation, deps will be defined in conanfile.py
# and not necessary to call conan again, conan is already running
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
else ()
include(cmake/conan.cmake)
conan_cmake_run(
CONANFILE conanfile.py
BUILD missing
BASIC_SETUP CMAKE_TARGETS)
endif ()
if (SSP_BUILD_TESTS)
Include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v2.13.8
)
FetchContent_MakeAvailable(Catch2)
endif ()
# ==============================================================================
# Targets
# ==============================================================================
add_subdirectory(src)
if (SSP_BUILD_TESTS)
file(COPY data DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
enable_testing()
add_subdirectory(tests)
endif ()
# ==============================================================================
# Exports and remaining installation
# ==============================================================================
install(
EXPORT "${SSP_EXPORT_TARGET}"
DESTINATION "${SSP_CMAKE_INSTALL_DIR}"
NAMESPACE "${PROJECT_NAME}::"
)
include(CMakePackageConfigHelpers)
# Generate and install package-config file.
set(configFile "${CMAKE_BINARY_DIR}/${PROJECT_NAME}-config.cmake")
set(targetsFile "${SSP_CMAKE_INSTALL_DIR}/${SSP_EXPORT_TARGET}.cmake")
configure_package_config_file(
"${CMAKE_SOURCE_DIR}/cmake/project-config.cmake.in"
"${configFile}"
INSTALL_DESTINATION "${SSP_CMAKE_INSTALL_DIR}"
PATH_VARS targetsFile
)
install(FILES "${configFile}" DESTINATION "${SSP_CMAKE_INSTALL_DIR}")
# Generate and install package-version file
set(versionFile "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake")
write_basic_package_version_file(
"${versionFile}"
VERSION "${PROJECT_VERSION}"
COMPATIBILITY "SameMajorVersion")
install(FILES "${versionFile}" DESTINATION "${SSP_CMAKE_INSTALL_DIR}")