-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
119 lines (100 loc) · 4.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
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
# Minimum version follows the current Ubuntu LTS and RHEL version
cmake_minimum_required(VERSION 3.25...3.29)
#[=============================================================================[
# Basic project definition #
]=============================================================================]
list(APPEND CMAKE_MESSAGE_CONTEXT JsonType)
# Define basic parameters
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif ()
project(JsonType
VERSION 0.1.0
DESCRIPTION "CMake project template"
HOMEPAGE_URL https://github.com/LecrisUT/JsonType
LANGUAGES CXX
)
# Specify C++ standard used in the project.
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
#[=============================================================================[
# Options #
]=============================================================================]
include(CMakeDependentOption)
include(FeatureSummary)
option(JSONTYPE_TEST "JsonType: Build test-suite" ${PROJECT_IS_TOP_LEVEL})
option(JSONTYPE_SHARED_LIBS "JsonType: Build as a shared library" ${PROJECT_IS_TOP_LEVEL})
option(JSONTYPE_INSTALL "JsonType: Install project" ${PROJECT_IS_TOP_LEVEL})
#[=============================================================================[
# Project configuration #
]=============================================================================]
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
# Include basic tools
include(FetchContent)
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
set(BUILD_SHARED_LIBS ${JSONTYPE_SHARED_LIBS})
#[=============================================================================[
# External packages #
]=============================================================================]
#[=============================================================================[
# Main definition #
]=============================================================================]
# Main project
add_library(JsonType_Lib)
set_target_properties(JsonType_Lib PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
EXPORT_NAME JsonType
OUTPUT_NAME json_type
)
add_library(JsonType::JsonType ALIAS JsonType_Lib)
# Main definitions inside src
add_subdirectory(src)
# Testing
if (JSONTYPE_TEST)
enable_testing()
add_subdirectory(test)
endif ()
#[=============================================================================[
# Install or Export #
]=============================================================================]
# Installation
if (JSONTYPE_INSTALL)
# cmake export files
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/JsonTypeConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
configure_package_config_file(
cmake/JsonTypeConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/JsonTypeConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/JsonType
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/JsonTypeConfigVersion.cmake
${CMAKE_CURRENT_BINARY_DIR}/JsonTypeConfig.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/JsonType
)
export(EXPORT JsonTypeTargets
FILE JsonTypeTargets.cmake
NAMESPACE JsonType::
)
install(EXPORT JsonTypeTargets
FILE JsonTypeTargets.cmake
NAMESPACE JsonType::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/JsonType
)
endif ()
# Make project available for FetchContent
if(NOT PROJECT_IS_TOP_LEVEL)
# Propagate variables
return(PROPAGATE
JsonType_VERSION
JsonType_VERSION_MAJOR
JsonType_VERSION_MINOR
JsonType_VERSION_PATCH
JsonType_VERSION_TWEAK
)
endif ()