-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
90 lines (72 loc) · 3.11 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
cmake_minimum_required(VERSION 3.16)
project(termcontrol
LANGUAGES CXX
VERSION 0.3.0)
include(external/external.cmake)
include(CTest)
add_library(termcontrol INTERFACE)
add_library(termcontrol::termcontrol ALIAS termcontrol)
option(TERMCONTROL_BUILD_TESTS "Build tests" ON)
option(TERMCONTROL_INSTALL "Create an install target" ON)
target_compile_features(termcontrol INTERFACE cxx_std_20)
target_include_directories(${PROJECT_NAME} INTERFACE
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
target_link_libraries(termcontrol
INTERFACE
fmt::fmt-header-only
gsl::gsl-lite-v1
ctre::ctre)
if (TERMCONTROL_BUILD_TESTS)
add_subdirectory(tests)
endif()
if (TERMCONTROL_INSTALL)
set(termcontrol_target termcontrol)
set(termcontrol_cmake_install_dir ${CMAKE_INSTALL_LIBDIR}/cmake/termcontrol)
set(termcontrol_version_config ${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake)
set(termcontrol_project_config ${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake)
set(termcontrol_project_config_template ${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}-config.cmake.in)
set(termcontrol_targets_export_name ${PROJECT_NAME}-targets)
set(termcontrol_targets_file ${termcontrol_targets_export_name}.cmake)
set(termcontrol_include_build_dir ${PROJECT_SOURCE_DIR}/include/)
set(termcontrol_namespace ${PROJECT_NAME})
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${termcontrol_version_config}
VERSION ${PACKAGE_VERSION}
COMPATIBILITY AnyNewerVersion
)
configure_package_config_file(
${termcontrol_project_config_template}
${termcontrol_project_config}
INSTALL_DESTINATION ${termcontrol_cmake_install_dir})
# install headers
install(DIRECTORY ${termcontrol_include_build_dir}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
# install project config file and config version file
install(FILES ${termcontrol_project_config}
${termcontrol_version_config}
DESTINATION ${termcontrol_cmake_install_dir}
)
# install targets to an export set
install(TARGETS ${termcontrol_target}
EXPORT ${termcontrol_targets_export_name}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# Install the export set to enable importing targets from the build tree
export(EXPORT ${termcontrol_targets_export_name}
FILE ${termcontrol_targets_file}
NAMESPACE ${termcontrol_namespace}::)
# Install the export set to enable importing targets from the install tree
install(EXPORT ${termcontrol_targets_export_name}
FILE ${termcontrol_targets_file}
NAMESPACE ${termcontrol_namespace}::
DESTINATION ${termcontrol_cmake_install_dir})
endif()
if (NOT ctre_FOUND)
# export ctre target from the build dir
export(EXPORT ctre-targets
FILE ctre-targets.cmake
NAMESPACE ctre::)
endif()