Skip to content

Commit 8cbb263

Browse files
committed
Build: CMake cleanup
* Migrate all add_definitions to target_compile_definitions * Remove -D from preprocessor definitions added by target_compile_definitions (unneccessary, cmake strips it anyway) * Fixed NO_BUFFERPOOL not being set on g3d if jemalloc is used * Moved library/compiler specific compile flag settings spread all over various CMakeLists to their related library/compiler file * Remove ancient manual link flag settings for worldserver (cherry picked from commit 77fe2745febab9e4362b09750093d831325e6091)
1 parent 5269de5 commit 8cbb263

File tree

19 files changed

+96
-99
lines changed

19 files changed

+96
-99
lines changed

cmake/compiler/clang/settings.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ if (NOT CLANG_HAVE_PROPER_CHARCONV)
3333
message(STATUS "Clang: Detected from_chars bug for 64-bit integers, workaround enabled")
3434
target_compile_definitions(trinity-compile-option-interface
3535
INTERFACE
36-
-DTRINITY_NEED_CHARCONV_WORKAROUND)
36+
TRINITY_NEED_CHARCONV_WORKAROUND)
3737
endif()
3838

3939
if(WITH_WARNINGS)

cmake/compiler/gcc/settings.cmake

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ else()
66
message(STATUS "GCC: Minimum version required is ${GCC_EXPECTED_VERSION}, found ${CMAKE_CXX_COMPILER_VERSION} - ok!")
77
endif()
88

9+
target_compile_options(trinity-compile-option-interface
10+
INTERFACE
11+
-fno-delete-null-pointer-checks)
12+
913
if(PLATFORM EQUAL 32)
1014
# Required on 32-bit systems to enable SSE2 (standard on x64)
1115
target_compile_options(trinity-compile-option-interface
@@ -16,8 +20,8 @@ endif()
1620
if(TRINITY_SYSTEM_PROCESSOR MATCHES "x86|amd64")
1721
target_compile_definitions(trinity-compile-option-interface
1822
INTERFACE
19-
-DHAVE_SSE2
20-
-D__SSE2__)
23+
HAVE_SSE2
24+
__SSE2__)
2125
message(STATUS "GCC: SFMT enabled, SSE2 flags forced")
2226
endif()
2327

cmake/compiler/icc/settings.cmake

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
target_compile_definitions(trinity-compile-option-interface
2-
INTERFACE
3-
-D_BUILD_DIRECTIVE="$<CONFIG>")
4-
51
if(PLATFORM EQUAL 32)
62
target_compile_options(trinity-compile-option-interface
73
INTERFACE

cmake/compiler/msvc/settings.cmake

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ if(PLATFORM EQUAL 64)
3434
# debugger functionality.
3535
target_compile_definitions(trinity-compile-option-interface
3636
INTERFACE
37-
-D_WIN64)
37+
_WIN64)
3838

3939
message(STATUS "MSVC: 64-bit platform, enforced -D_WIN64 parameter")
4040

@@ -88,24 +88,24 @@ endif()
8888
# Define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES - eliminates the warning by changing the strcpy call to strcpy_s, which prevents buffer overruns
8989
target_compile_definitions(trinity-compile-option-interface
9090
INTERFACE
91-
-D_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES)
91+
_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES)
9292
message(STATUS "MSVC: Overloaded standard names")
9393

9494
# Ignore warnings about older, less secure functions
9595
target_compile_definitions(trinity-compile-option-interface
9696
INTERFACE
97-
-D_CRT_SECURE_NO_WARNINGS)
97+
_CRT_SECURE_NO_WARNINGS)
9898
message(STATUS "MSVC: Disabled NON-SECURE warnings")
9999

100100
# Ignore warnings about POSIX deprecation
101101
target_compile_definitions(trinity-compile-option-interface
102102
INTERFACE
103-
-D_CRT_NONSTDC_NO_WARNINGS)
103+
_CRT_NONSTDC_NO_WARNINGS)
104104

105105
# Force math constants like M_PI to be available
106106
target_compile_definitions(trinity-compile-option-interface
107107
INTERFACE
108-
-D_USE_MATH_DEFINES)
108+
_USE_MATH_DEFINES)
109109

110110
message(STATUS "MSVC: Disabled POSIX warnings")
111111

@@ -157,8 +157,8 @@ target_compile_options(trinity-compile-option-interface
157157
if(ASAN)
158158
target_compile_definitions(trinity-compile-option-interface
159159
INTERFACE
160-
-D_DISABLE_STRING_ANNOTATION
161-
-D_DISABLE_VECTOR_ANNOTATION)
160+
_DISABLE_STRING_ANNOTATION
161+
_DISABLE_VECTOR_ANNOTATION)
162162

163163
target_compile_options(trinity-compile-option-interface
164164
INTERFACE

cmake/macros/ConfigureBaseTargets.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ set(CMAKE_CXX_STANDARD 20)
1818
# Set build-directive (used in core to tell which buildtype we used)
1919
target_compile_definitions(trinity-compile-option-interface
2020
INTERFACE
21-
-D_BUILD_DIRECTIVE="$<CONFIG>")
21+
_BUILD_DIRECTIVE="$<CONFIG>")
2222

2323
# An interface library to make the target features available to other targets
2424
add_library(trinity-feature-interface INTERFACE)

cmake/platform/win/settings.cmake

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
add_definitions(-D_WIN32_WINNT=0x0A00) # Windows 10
2-
add_definitions(-DNTDDI_VERSION=0x0A000007) # 19H1 (1903)
3-
add_definitions(-DWIN32_LEAN_AND_MEAN)
4-
add_definitions(-DNOMINMAX)
5-
add_definitions(-DTRINITY_REQUIRED_WINDOWS_BUILD=18362)
1+
target_compile_definitions(trinity-compile-option-interface
2+
INTERFACE
3+
_WIN32_WINNT=0x0A00 # Windows 10
4+
NTDDI_VERSION=0x0A000007 # 19H1 (1903)
5+
WIN32_LEAN_AND_MEAN
6+
NOMINMAX
7+
TRINITY_REQUIRED_WINDOWS_BUILD=18362)
68

79
# set up output paths for executable binaries (.exe-files, and .dll-files on DLL-capable platforms)
810
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/$<CONFIG>")

cmake/showoptions.cmake

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# output generic information about the core and buildtype chosen
22
message("")
33
message("* TrinityCore revision : ${rev_hash} ${rev_date} (${rev_branch} branch)")
4-
if(NOT ("${CMAKE_GENERATOR}" MATCHES "Visual Studio" OR "${CMAKE_GENERATOR}" STREQUAL "Ninja Multi-Config"))
4+
get_property(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
5+
if(NOT IS_MULTI_CONFIG)
56
message("* TrinityCore buildtype : ${CMAKE_BUILD_TYPE}")
67
endif()
78
message("")
@@ -72,7 +73,9 @@ if(WITH_COREDEBUG)
7273
message(" *** -DCMAKE_BUILD_TYPE=RelWithDebInfo")
7374
message(" *** DO NOT ENABLE IT UNLESS YOU KNOW WHAT YOU'RE DOING!")
7475
message("* Use coreside debug : Yes")
75-
add_definitions(-DTRINITY_DEBUG)
76+
target_compile_definitions(trinity-compile-option-interface
77+
INTERFACE
78+
TRINITY_DEBUG)
7679
else()
7780
message("* Use coreside debug : No (default)")
7881
endif()
@@ -111,60 +114,70 @@ if(HELGRIND)
111114
message(" *** HELGRIND - WARNING!")
112115
message(" *** Please specify the valgrind include directory in VALGRIND_INCLUDE_DIR option if you get build errors")
113116
message(" *** Please note that this is for DEBUGGING WITH HELGRIND only!")
114-
add_definitions(-DHELGRIND)
117+
target_compile_definitions(trinity-compile-option-interface
118+
INTERFACE
119+
HELGRIND)
115120
endif()
116121

117122
if(ASAN)
118123
message("")
119124
message(" *** ASAN - WARNING!")
120125
message(" *** Please note that this is for DEBUGGING WITH ADDRESS SANITIZER only!")
121-
add_definitions(-DASAN)
126+
target_compile_definitions(trinity-compile-option-interface
127+
INTERFACE
128+
ASAN)
122129
endif()
123130

124131
if(MSAN)
125132
message("")
126133
message(" *** MSAN - WARNING!")
127134
message(" *** Please note that this is for DEBUGGING WITH MEMORY SANITIZER only!")
128-
add_definitions(-DMSAN)
135+
target_compile_definitions(trinity-compile-option-interface
136+
INTERFACE
137+
MSAN)
129138
endif()
130139

131140
if(UBSAN)
132141
message("")
133142
message(" *** UBSAN - WARNING!")
134143
message(" *** Please note that this is for DEBUGGING WITH UNDEFINED BEHAVIOR SANITIZER only!")
135-
add_definitions(-DUBSAN)
144+
target_compile_definitions(trinity-compile-option-interface
145+
INTERFACE
146+
UBSAN)
136147
endif()
137148

138149
if(TSAN)
139150
message("")
140151
message(" *** TSAN - WARNING!")
141152
message(" *** Please note that this is for DEBUGGING WITH THREAD SANITIZER only!")
142-
add_definitions(-DTSAN -DNO_BUFFERPOOL)
153+
target_compile_definitions(trinity-compile-option-interface
154+
INTERFACE
155+
TSAN)
143156
endif()
144157

145158
if(PERFORMANCE_PROFILING)
146159
message("")
147160
message(" *** PERFORMANCE_PROFILING - WARNING!")
148161
message(" *** Please note that this is for PERFORMANCE PROFILING only! Do NOT report any issue when enabling this configuration!")
149-
add_definitions(-DPERFORMANCE_PROFILING)
162+
target_compile_definitions(trinity-compile-option-interface
163+
INTERFACE
164+
PERFORMANCE_PROFILING)
150165
endif()
151166

152167
if(WITHOUT_METRICS)
153168
message("")
154169
message(" *** WITHOUT_METRICS - WARNING!")
155170
message(" *** Please note that this will disable all metrics output (i.e. InfluxDB and Grafana)")
156-
add_definitions(-DWITHOUT_METRICS)
171+
target_compile_definitions(trinity-compile-option-interface
172+
INTERFACE
173+
WITHOUT_METRICS)
157174
elseif (WITH_DETAILED_METRICS)
158175
message("")
159176
message(" *** WITH_DETAILED_METRICS - WARNING!")
160177
message(" *** Please note that this will enable detailed metrics output (i.e. time each session takes to update)")
161-
add_definitions(-DWITH_DETAILED_METRICS)
162-
endif()
163-
164-
if(WITH_BOOST_STACKTRACE)
165-
if (BOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE)
166-
add_definitions(-DBOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE="${BOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE}")
167-
endif()
178+
target_compile_definitions(trinity-compile-option-interface
179+
INTERFACE
180+
WITH_DETAILED_METRICS)
168181
endif()
169182

170183
if(BUILD_SHARED_LIBS)
@@ -176,7 +189,9 @@ if(BUILD_SHARED_LIBS)
176189
message("")
177190
message(" *** Dynamic linking was enforced through a dynamic script module!")
178191
endif()
179-
add_definitions(-DTRINITY_API_USE_DYNAMIC_LINKING)
192+
target_compile_definitions(trinity-compile-option-interface
193+
INTERFACE
194+
TRINITY_API_USE_DYNAMIC_LINKING)
180195

181196
WarnAboutSpacesInBuildPath()
182197
endif()

dep/SFMT/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ target_include_directories(sfmt
3636
${CMAKE_CURRENT_SOURCE_DIR})
3737

3838
# using the standard Mersenne exponent 19937
39-
target_compile_definitions(sfmt PUBLIC -DSFMT_MEXP=19937)
39+
target_compile_definitions(sfmt PUBLIC SFMT_MEXP=19937)
4040

4141
# enable SIMD instructions if available
4242
include(CheckCXXCompilerFlag)
@@ -67,11 +67,11 @@ else ()
6767
endif ()
6868

6969
if (HAVE_NEON)
70-
target_compile_definitions(sfmt PUBLIC -DHAVE_NEON)
70+
target_compile_definitions(sfmt PUBLIC HAVE_NEON)
7171
endif ()
7272

7373
if (HAVE_SSE2)
74-
target_compile_definitions(sfmt PUBLIC -DHAVE_SSE2)
74+
target_compile_definitions(sfmt PUBLIC HAVE_SSE2)
7575
endif ()
7676

7777
set_target_properties(sfmt PROPERTIES LINKER_LANGUAGE CXX)

dep/argon2/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ add_library(argon2 STATIC
2323

2424
target_compile_definitions(argon2
2525
PRIVATE
26-
-DARGON2_NO_THREADS)
26+
ARGON2_NO_THREADS)
2727

2828
set_target_properties(argon2 PROPERTIES LINKER_LANGUAGE CXX)
2929

dep/boost/CMakeLists.txt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ endif()
2020

2121
set(Boost_NO_WARN_NEW_VERSIONS ON)
2222

23-
include (CheckCXXSourceCompiles)
24-
2523
if (WIN32)
2624
# On windows the requirements are higher according to the wiki.
2725
set(BOOST_REQUIRED_VERSION 1.78)
@@ -49,22 +47,24 @@ target_include_directories(boost
4947

5048
target_compile_definitions(boost
5149
INTERFACE
52-
-DBOOST_DATE_TIME_NO_LIB
53-
-DBOOST_REGEX_NO_LIB
54-
-DBOOST_CHRONO_NO_LIB
55-
-DBOOST_SERIALIZATION_NO_LIB
56-
-DBOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE
57-
-DBOOST_ASIO_NO_DEPRECATED
58-
-DBOOST_SYSTEM_USE_UTF8
59-
-DBOOST_BIND_NO_PLACEHOLDERS)
50+
BOOST_ALL_NO_LIB
51+
BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE
52+
BOOST_ASIO_NO_DEPRECATED
53+
BOOST_BIND_NO_PLACEHOLDERS
54+
BOOST_SYSTEM_USE_UTF8)
6055

6156
if (WITH_BOOST_STACKTRACE AND NOT WIN32)
62-
message("*** libbacktrace will be linked")
57+
message(STATUS "libbacktrace will be linked")
58+
59+
include(CheckIncludeFile)
6360

6461
if (BOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE)
65-
CHECK_INCLUDE_FILE(${BOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE} HAS_BACKTRACE)
62+
check_include_file("${BOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE}" HAS_BACKTRACE)
63+
target_compile_definitions(boost
64+
INTERFACE
65+
BOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE=${BOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE})
6666
else()
67-
CHECK_INCLUDE_FILE("backtrace.h" HAS_BACKTRACE)
67+
check_include_file("backtrace.h" HAS_BACKTRACE)
6868
endif()
6969

7070
if (NOT HAS_BACKTRACE)
@@ -73,7 +73,7 @@ if (WITH_BOOST_STACKTRACE AND NOT WIN32)
7373

7474
target_compile_definitions(boost
7575
INTERFACE
76-
-DBOOST_STACKTRACE_USE_BACKTRACE)
76+
BOOST_STACKTRACE_USE_BACKTRACE)
7777

7878
target_link_libraries(boost
7979
INTERFACE

0 commit comments

Comments
 (0)