@@ -14,7 +14,27 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
1414
1515option (CLICE_ENABLE_LTO "Enable ThinLTO for all targets" OFF )
1616
17- # Make sure all third libraries are affected by ABI related options
17+ # Global flags that apply to all targets (including FetchContent dependencies).
18+ if (NOT MSVC )
19+ add_compile_options (-ffunction-sections -fdata-sections )
20+ endif ()
21+
22+ if (APPLE )
23+ # https://conda-forge.org/docs/maintainer/knowledge_base/#newer-c-features-with-old-sdk
24+ add_compile_definitions (_LIBCPP_DISABLE_AVAILABILITY=1 )
25+ endif ()
26+
27+ if (WIN32 )
28+ string (APPEND CMAKE_EXE_LINKER_FLAGS " -Wl,/OPT:REF" )
29+ string (APPEND CMAKE_SHARED_LINKER_FLAGS " -Wl,/OPT:REF" )
30+ elseif (APPLE )
31+ string (APPEND CMAKE_EXE_LINKER_FLAGS " -Wl,-dead_strip" )
32+ string (APPEND CMAKE_SHARED_LINKER_FLAGS " -Wl,-dead_strip" )
33+ else ()
34+ string (APPEND CMAKE_EXE_LINKER_FLAGS " -static-libstdc++ -static-libgcc -Wl,--gc-sections" )
35+ string (APPEND CMAKE_SHARED_LINKER_FLAGS " -Wl,--gc-sections" )
36+ endif ()
37+
1838if (CLICE_USE_LIBCXX)
1939 string (APPEND CMAKE_CXX_FLAGS " -stdlib=libc++" )
2040 string (APPEND CMAKE_EXE_LINKER_FLAGS " -stdlib=libc++" )
@@ -33,7 +53,6 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
3353 add_compile_options (-fsanitize=address )
3454
3555 if (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC" )
36- # clang-cl (MSVC frontend): manually link ASan runtime.
3756 execute_process (
3857 COMMAND ${CMAKE_CXX_COMPILER} --print-resource-dir
3958 OUTPUT_VARIABLE CLANG_RESOURCE_DIR
@@ -47,81 +66,50 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
4766 list (APPEND ASAN_LINK_FLAGS "/wholearchive:clang_rt.asan_dynamic_runtime_thunk-x86_64.lib" )
4867
4968 foreach (flag ${ASAN_LINK_FLAGS} )
50- set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${flag} " )
51- set ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${flag} " )
52- set ( CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${flag} " )
69+ string ( APPEND CMAKE_EXE_LINKER_FLAGS " ${flag} " )
70+ string ( APPEND CMAKE_SHARED_LINKER_FLAGS " ${flag} " )
71+ string ( APPEND CMAKE_MODULE_LINKER_FLAGS " ${flag} " )
5372 endforeach ()
5473 else ()
55- # GNU frontend (clang++/gcc): -fsanitize=address handles linking automatically.
5674 string (APPEND CMAKE_EXE_LINKER_FLAGS " -fsanitize=address" )
5775 string (APPEND CMAKE_SHARED_LINKER_FLAGS " -fsanitize=address" )
5876 endif ()
5977
6078 if (WIN32 )
61- # Disable Identical COMDAT Folding in Debug to avoid ASan ODR false positives.
6279 string (APPEND CMAKE_EXE_LINKER_FLAGS " -Wl,/OPT:NOICF" )
6380 string (APPEND CMAKE_SHARED_LINKER_FLAGS " -Wl,/OPT:NOICF" )
6481 endif ()
6582endif ()
6683
67- if (APPLE )
68- # https://conda-forge.org/docs/maintainer/knowledge_base/#newer-c-features-with-old-sdk
69- string (APPEND CMAKE_CXX_FLAGS " -D_LIBCPP_DISABLE_AVAILABILITY=1" )
70- endif ()
71-
7284include ("${PROJECT_SOURCE_DIR} /cmake/package.cmake" )
7385
86+ # Project-specific options (not applied to third-party deps).
7487add_library (clice_options INTERFACE )
7588
76- if (CLICE_ENABLE_TEST)
77- target_compile_definitions (clice_options INTERFACE CLICE_ENABLE_TEST=1 )
78- endif ()
79-
80- if (CLICE_CI_ENVIRONMENT)
81- target_compile_definitions (clice_options INTERFACE CLICE_CI_ENVIRONMENT=1 )
82- endif ()
83-
84- if (WIN32 )
85- target_link_libraries (clice_options INTERFACE version ntdll )
86- endif ()
87-
88- if (WIN32 )
89- set (CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL" )
90- target_link_options (clice_options INTERFACE
91- -fuse-ld=lld-link
92- -Wl,/OPT:REF
93- #,/OPT:NOICF
94- )
95- elseif (APPLE )
96- target_link_options (clice_options INTERFACE
97- -fuse-ld=lld
98- -Wl,-dead_strip
99- )
100- elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux" )
101- target_link_options (clice_options INTERFACE
102- -fuse-ld=lld
103- -static-libstdc++ -static-libgcc
104- -Wl,--gc-sections
105- )
106- endif ()
107-
10889if (MSVC OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND
10990 CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC" ))
110- target_compile_options (clice_options INTERFACE
111- /GR-
112- /EHsc-
113- /Zc:preprocessor
114- )
91+ target_compile_options (clice_options INTERFACE /GR- /EHsc- /Zc:preprocessor )
11592else ()
11693 target_compile_options (clice_options INTERFACE
11794 -fno-rtti
95+ -fno-exceptions
11896 -Wno-deprecated-declarations
119- -ffunction-sections
120- -fdata-sections
12197 $<$<COMPILE_LANG_AND_ID :CXX ,Clang ,AppleClang >:-Wno -undefined -inline >
12298 )
12399endif ()
124100
101+ if (WIN32 )
102+ target_link_libraries (clice_options INTERFACE version ntdll )
103+ endif ()
104+
105+ if (CLICE_ENABLE_TEST)
106+ target_compile_definitions (clice_options INTERFACE CLICE_ENABLE_TEST=1 )
107+ endif ()
108+
109+ if (CLICE_CI_ENVIRONMENT)
110+ target_compile_definitions (clice_options INTERFACE CLICE_CI_ENVIRONMENT=1 )
111+ endif ()
112+
125113set (FBS_SCHEMA_FILE "${PROJECT_SOURCE_DIR} /src/index/schema.fbs" )
126114set (GENERATED_HEADER "${PROJECT_BINARY_DIR} /generated/schema_generated.h" )
127115
0 commit comments