-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathframework.cmake
More file actions
163 lines (138 loc) · 5.91 KB
/
Copy pathframework.cmake
File metadata and controls
163 lines (138 loc) · 5.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
include_guard(GLOBAL)
# Shared feature/platform setup and environment checks
include(${cmake_root}/tools.cmake)
include(${cmake_root}/fetchContents.cmake)
include(${cmake_root}/addLibrary.cmake)
include(${cmake_root}/check_environment.cmake)
include(${cmake_root}/sqlish.cmake)
# The environment check validates OUTPUT_DIR etc.; call once globally
check_environment("${CMAKE_SOURCE_DIR}")
# Generate the ABI version from the major version, unless already set from APP_SOVERSION
if(APP_SOVERSION)
set(SO_VERSION "${APP_SOVERSION}")
else ()
SplitAt("${APP_VERSION}" "." SO_VERSION dc1)
endif ()
# Capture compiler version information (used for flags below)
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} -v
ERROR_VARIABLE compiler_version
OUTPUT_QUIET
)
# Global policy/verbosity/tooling
set(CMAKE_WARN_UNINITIALIZED ON)
set(CMAKE_MESSAGE_LOG_LEVEL VERBOSE CACHE STRING "Log Level")
# Disable automatic RPATH to avoid circular dependencies
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
# Set explicit RPATH for build and install
set(CMAKE_BUILD_RPATH "${OUTPUT_DIR}/bin;${OUTPUT_DIR}/lib;${OUTPUT_DIR}/dll")
if (LINUX)
# Use $ORIGIN so staged libs find their siblings regardless of install prefix.
# Executables override this per-target (e.g. $ORIGIN/../lib64).
set(CMAKE_INSTALL_RPATH "$ORIGIN")
else()
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
endif()
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g")
#set(CMAKE_CXX_SCAN_FOR_MODULES ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if (APPLE)
set(CMAKE_CXX_VISIBILITY_PRESET default)
set(CMAKE_VISIBILITY_INLINES_HIDDEN OFF)
else()
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
endif()
set(CMAKE_VERBOSE_MAKEFILE ON)
# Global accumulators provided by framework users
set(extra_CompileOptions)
set(extra_Definitions)
set(extra_IncludePaths)
set(extra_LibrariesList)
set(extra_LibraryPaths)
set(extra_LinkOptions)
# std::stacktrace (C++23) needs a runtime backend, not just the header.
# On Linux we build against libstdc++'s implementation (even under Clang), whose
# symbols (std::__stacktrace_impl::...) live in libstdc++exp, a static archive
# shipped next to libstdc++ itself and already on the compiler's library search
# path -- it bundles its own copy of libbacktrace, so nothing else is needed.
# HS_STACKTRACE_AVAILABLE gates the <stacktrace> usage in Core/include/Core/Core.h;
# without it PRINT_STACKTRACE()/VERIFY_MSG()/ASSERT_MSG() fall back to a stub.
if (LINUX)
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=libstdc++exp.a
OUTPUT_VARIABLE STDCXXEXP_LIB
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (EXISTS "${STDCXXEXP_LIB}")
list(APPEND extra_LibrariesList "${STDCXXEXP_LIB}")
list(APPEND extra_Definitions HS_STACKTRACE_AVAILABLE)
else ()
message(WARNING "libstdc++exp.a not found; std::stacktrace will be unavailable (PRINT_STACKTRACE will print a stub message)")
endif ()
endif ()
# Extra compile flags for clang module handling
if ("${compiler_version}" MATCHES "clang")
list(APPEND extra_CompileOptions
-fno-implicit-modules
-fno-implicit-module-maps
)
endif ()
add_compile_options($<$<CXX_COMPILER_ID:Clang>:-Wno-unused-command-line-argument>)
add_compile_options($<$<CXX_COMPILER_ID:Clang>:-Wno-enum-compare-switch>)
add_compile_options($<$<CXX_COMPILER_ID:Clang>:-Wno-deprecated-declarations>)
add_compile_options($<$<CXX_COMPILER_ID:Clang>:-Wno-unused-lambda-capture>)
add_compile_options($<$<CXX_COMPILER_ID:Clang>:-Wno-deprecated-enum-enum-conversion>)
add_compile_options($<$<CXX_COMPILER_ID:Clang>:-Wno-ignored-attributes>)
include(${cmake_root}/platform.cmake)
# Make CMake find_package prefer our install libdir
list(PREPEND CMAKE_MODULE_PATH
${CMAKE_INSTALL_LIBDIR})
# Testing helpers available globally
include(GoogleTest)
function(commonInit pkg discovery_phase)
string(TOUPPER "${pkg}" _PKG)
set(findex -1)
set(foundFind -1)
set(foundUse -1)
globalObjGet(GLOBAL_FEATURES _FEATURES)
if(discovery_phase)
foreach (feet IN LISTS _FEATURES)
math(EXPR findex "${findex} + 1")
separate_arguments(_feet NATIVE_COMMAND "${feet}")
cmake_parse_arguments("AAZ" "REQUIRED;OPTIONAL" "PACKAGE;NAMESPACE" "PATHS;HINTS" ${_feet})
if (AAZ_UNPARSED_ARGUMENTS)
list(GET AAZ_UNPARSED_ARGUMENTS 0 AAZ_FEATURE)
if (AAZ_FEATURE STREQUAL _PKG AND AAZ_PACKAGE STREQUAL Find${pkg})
set(foundFind ${findex})
elseif (AAZ_FEATURE STREQUAL _PKG AND AAZ_PACKAGE STREQUAL ${pkg})
set(foundUse ${findex})
endif ()
endif ()
endforeach ()
if(foundFind GREATER_EQUAL 0 AND foundFind GREATER foundUse)
list(REMOVE_AT _FEATURES ${foundFind})
if (foundUse GREATER_EQUAL 0)
list(REMOVE_AT _FEATURES ${foundUse})
endif ()
elseif(foundUse GREATER_EQUAL 0 AND foundUse GREATER foundFind)
list(REMOVE_AT _FEATURES ${foundUse})
if(foundFind GREATER_EQUAL 0)
list(REMOVE_AT _FEATURES ${foundFind})
endif ()
else ()
# They can only be the same if they are both -1, and in that case we do nothing
endif ()
if (foundFind GREATER_EQUAL 0 AND foundUse LESS 0)
list(INSERT _FEATURES ${foundFind} "${_PKG} PACKAGE ${pkg} ARGS PATHS {${pkg}}")
# list(PREPEND _FEATURES "${_PKG} PACKAGE ${pkg} ARGS PATHS {${pkg}}")
endif ()
globalObjSet(GLOBAL_FEATURES "${_FEATURES}")
set(fn "add${pkg}Features")
cmake_language(CALL registerPackageCallback "${fn}" ${discovery_phase})
endif ()
set(HANDLED ON)
endfunction()