-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeListsTemplate.txt
142 lines (122 loc) · 4.47 KB
/
CMakeListsTemplate.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
cmake_minimum_required(VERSION 3.15)
# cmake_policy(SET CMP0077 NEW)
# cmake_policy(SET CMP0126 NEW)
project(${PROJECT_NAME} VERSION 1.1.0 LANGUAGES CXX)
################
# Dependencies #
################
# if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
# Include(FetchContent)
# FetchContent_Declare(
# Catch2
# GIT_REPOSITORY https://github.com/catchorg/Catch2.git
# GIT_TAG v3.1.0
# FIND_PACKAGE_ARGS 3 NAMES Catch2
# )
# FetchContent_MakeAvailable(Catch2)
# list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
#
# include(CTest)
# include(Catch)
# endif ()
#
# find_package(Git QUIET)
# if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/../.git")
# # Update submodules as needed
# option(GIT_SUBMODULE "Check submodules during build" ON)
# if(GIT_SUBMODULE)
# message(STATUS "Submodule update")
# execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
# RESULT_VARIABLE GIT_SUBMOD_RESULT)
# if(NOT GIT_SUBMOD_RESULT EQUAL "0")
# message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
# endif()
# endif()
# endif()
#################################
# This is to create the library #
#################################
add_library(${PROJECT_NAME} INTERFACE)
add_library(GRon::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
set_target_properties(${PROJECT_NAME} PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
PREFIX ""
)
target_include_directories(${PROJECT_NAME}
INTERFACE
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
#######################
# Set compile options #
#######################
set(SANITIZE "OFF" CACHE STRING "Set the sanitizer to pass (the value provided will be passed directly to -fsanitize)")
if (NOT CMAKE_CXX_FLAGS)
if (NOT ${SANITIZE} STREQUAL "OFF")
target_compile_options(${PROJECT_NAME} INTERFACE -fsanitize=${SANITIZE})
target_compile_options(${PROJECT_NAME} INTERFACE -fsanitize-recover=${SANITIZE})
target_compile_options(${PROJECT_NAME} INTERFACE -g)
target_link_options(${PROJECT_NAME} BEFORE INTERFACE -fsanitize=${SANITIZE})
endif ()
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
if (MSVC)
target_compile_options(${PROJECT_NAME} INTERFACE /O0)
else ()
target_compile_options(${PROJECT_NAME} INTERFACE -O0)
endif ()
else ()
if (MSVC)
target_compile_options(${PROJECT_NAME} INTERFACE /O3)
else ()
target_compile_options(${PROJECT_NAME} INTERFACE -O3)
endif ()
endif ()
message("Setting CXX flags to default for ${CMAKE_BUILD_TYPE} mode (${CMAKE_CXX_FLAGS})")
else ()
message("CXX flags are already set to ${CMAKE_CXX_FLAGS}")
endif ()
##########################
# Installing the library #
##########################
include(GNUInstallDirs)
set(INSTALL_CONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}Targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
ARCH_INDEPENDENT
)
configure_package_config_file(
${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in
${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION ${INSTALL_CONFIG_DIR}
)
install(EXPORT ${PROJECT_NAME}Targets
FILE ${PROJECT_NAME}Targets.cmake
NAMESPACE GRon::
DESTINATION ${INSTALL_CONFIG_DIR}
)
install(FILES
${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION ${INSTALL_CONFIG_DIR}
)
install(DIRECTORY include/GRon DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
export(
EXPORT ${PROJECT_NAME}Targets
NAMESPACE GRon::
FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake
)
set(CMAKE_EXPORT_PACKAGE_REGISTRY ON)
export(PACKAGE ${PROJECT_NAME})
# if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
# add_subdirectory(tests)
# endif ()