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 77fe2745fe)
This commit is contained in:
Shauren
2024-07-15 15:24:35 +02:00
committed by Ovahlord
parent 5e3a42ee82
commit c12f669fc5
24 changed files with 110 additions and 108 deletions

View File

@@ -35,7 +35,7 @@ if (NOT CLANG_HAVE_PROPER_CHARCONV)
message(STATUS "Clang: Detected from_chars bug for 64-bit integers, workaround enabled")
target_compile_definitions(trinity-compile-option-interface
INTERFACE
-DTRINITY_NEED_CHARCONV_WORKAROUND)
TRINITY_NEED_CHARCONV_WORKAROUND)
endif()
if(WITH_WARNINGS)

View File

@@ -6,6 +6,10 @@ else()
message(STATUS "GCC: Minimum version required is ${GCC_EXPECTED_VERSION}, found ${CMAKE_CXX_COMPILER_VERSION} - ok!")
endif()
target_compile_options(trinity-compile-option-interface
INTERFACE
-fno-delete-null-pointer-checks)
if(PLATFORM EQUAL 32)
# Required on 32-bit systems to enable SSE2 (standard on x64)
target_compile_options(trinity-compile-option-interface
@@ -16,8 +20,8 @@ endif()
if(TRINITY_SYSTEM_PROCESSOR MATCHES "x86|amd64")
target_compile_definitions(trinity-compile-option-interface
INTERFACE
-DHAVE_SSE2
-D__SSE2__)
HAVE_SSE2
__SSE2__)
message(STATUS "GCC: SFMT enabled, SSE2 flags forced")
endif()

View File

@@ -1,7 +1,3 @@
target_compile_definitions(trinity-compile-option-interface
INTERFACE
-D_BUILD_DIRECTIVE="$<CONFIG>")
if(PLATFORM EQUAL 32)
target_compile_options(trinity-compile-option-interface
INTERFACE

View File

@@ -34,7 +34,7 @@ if(PLATFORM EQUAL 64)
# debugger functionality.
target_compile_definitions(trinity-compile-option-interface
INTERFACE
-D_WIN64)
_WIN64)
message(STATUS "MSVC: 64-bit platform, enforced -D_WIN64 parameter")
@@ -88,24 +88,24 @@ endif()
# Define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES - eliminates the warning by changing the strcpy call to strcpy_s, which prevents buffer overruns
target_compile_definitions(trinity-compile-option-interface
INTERFACE
-D_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES)
_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES)
message(STATUS "MSVC: Overloaded standard names")
# Ignore warnings about older, less secure functions
target_compile_definitions(trinity-compile-option-interface
INTERFACE
-D_CRT_SECURE_NO_WARNINGS)
_CRT_SECURE_NO_WARNINGS)
message(STATUS "MSVC: Disabled NON-SECURE warnings")
# Ignore warnings about POSIX deprecation
target_compile_definitions(trinity-compile-option-interface
INTERFACE
-D_CRT_NONSTDC_NO_WARNINGS)
_CRT_NONSTDC_NO_WARNINGS)
# Force math constants like M_PI to be available
target_compile_definitions(trinity-compile-option-interface
INTERFACE
-D_USE_MATH_DEFINES)
_USE_MATH_DEFINES)
message(STATUS "MSVC: Disabled POSIX warnings")
@@ -157,8 +157,8 @@ target_compile_options(trinity-compile-option-interface
if(ASAN)
target_compile_definitions(trinity-compile-option-interface
INTERFACE
-D_DISABLE_STRING_ANNOTATION
-D_DISABLE_VECTOR_ANNOTATION)
_DISABLE_STRING_ANNOTATION
_DISABLE_VECTOR_ANNOTATION)
target_compile_options(trinity-compile-option-interface
INTERFACE

View File

@@ -18,7 +18,7 @@ set(CMAKE_CXX_STANDARD 20)
# Set build-directive (used in core to tell which buildtype we used)
target_compile_definitions(trinity-compile-option-interface
INTERFACE
-D_BUILD_DIRECTIVE="$<CONFIG>")
_BUILD_DIRECTIVE="$<CONFIG>")
# An interface library to make the target features available to other targets
add_library(trinity-feature-interface INTERFACE)

View File

@@ -1,8 +1,10 @@
add_definitions(-D_WIN32_WINNT=0x0A00) # Windows 10
add_definitions(-DNTDDI_VERSION=0x0A000007) # 19H1 (1903)
add_definitions(-DWIN32_LEAN_AND_MEAN)
add_definitions(-DNOMINMAX)
add_definitions(-DTRINITY_REQUIRED_WINDOWS_BUILD=18362)
target_compile_definitions(trinity-compile-option-interface
INTERFACE
_WIN32_WINNT=0x0A00 # Windows 10
NTDDI_VERSION=0x0A000007 # 19H1 (1903)
WIN32_LEAN_AND_MEAN
NOMINMAX
TRINITY_REQUIRED_WINDOWS_BUILD=18362)
# set up output paths for executable binaries (.exe-files, and .dll-files on DLL-capable platforms)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/$<CONFIG>")

View File

@@ -1,7 +1,8 @@
# output generic information about the core and buildtype chosen
message("")
message("* TrinityCore revision : ${rev_hash} ${rev_date} (${rev_branch} branch)")
if(NOT ("${CMAKE_GENERATOR}" MATCHES "Visual Studio" OR "${CMAKE_GENERATOR}" STREQUAL "Ninja Multi-Config"))
get_property(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(NOT IS_MULTI_CONFIG)
message("* TrinityCore buildtype : ${CMAKE_BUILD_TYPE}")
endif()
message("")
@@ -72,7 +73,9 @@ if(WITH_COREDEBUG)
message(" *** -DCMAKE_BUILD_TYPE=RelWithDebInfo")
message(" *** DO NOT ENABLE IT UNLESS YOU KNOW WHAT YOU'RE DOING!")
message("* Use coreside debug : Yes")
add_definitions(-DTRINITY_DEBUG)
target_compile_definitions(trinity-compile-option-interface
INTERFACE
TRINITY_DEBUG)
else()
message("* Use coreside debug : No (default)")
endif()
@@ -111,60 +114,70 @@ if(HELGRIND)
message(" *** HELGRIND - WARNING!")
message(" *** Please specify the valgrind include directory in VALGRIND_INCLUDE_DIR option if you get build errors")
message(" *** Please note that this is for DEBUGGING WITH HELGRIND only!")
add_definitions(-DHELGRIND)
target_compile_definitions(trinity-compile-option-interface
INTERFACE
HELGRIND)
endif()
if(ASAN)
message("")
message(" *** ASAN - WARNING!")
message(" *** Please note that this is for DEBUGGING WITH ADDRESS SANITIZER only!")
add_definitions(-DASAN)
target_compile_definitions(trinity-compile-option-interface
INTERFACE
ASAN)
endif()
if(MSAN)
message("")
message(" *** MSAN - WARNING!")
message(" *** Please note that this is for DEBUGGING WITH MEMORY SANITIZER only!")
add_definitions(-DMSAN)
target_compile_definitions(trinity-compile-option-interface
INTERFACE
MSAN)
endif()
if(UBSAN)
message("")
message(" *** UBSAN - WARNING!")
message(" *** Please note that this is for DEBUGGING WITH UNDEFINED BEHAVIOR SANITIZER only!")
add_definitions(-DUBSAN)
target_compile_definitions(trinity-compile-option-interface
INTERFACE
UBSAN)
endif()
if(TSAN)
message("")
message(" *** TSAN - WARNING!")
message(" *** Please note that this is for DEBUGGING WITH THREAD SANITIZER only!")
add_definitions(-DTSAN -DNO_BUFFERPOOL)
target_compile_definitions(trinity-compile-option-interface
INTERFACE
TSAN)
endif()
if(PERFORMANCE_PROFILING)
message("")
message(" *** PERFORMANCE_PROFILING - WARNING!")
message(" *** Please note that this is for PERFORMANCE PROFILING only! Do NOT report any issue when enabling this configuration!")
add_definitions(-DPERFORMANCE_PROFILING)
target_compile_definitions(trinity-compile-option-interface
INTERFACE
PERFORMANCE_PROFILING)
endif()
if(WITHOUT_METRICS)
message("")
message(" *** WITHOUT_METRICS - WARNING!")
message(" *** Please note that this will disable all metrics output (i.e. InfluxDB and Grafana)")
add_definitions(-DWITHOUT_METRICS)
target_compile_definitions(trinity-compile-option-interface
INTERFACE
WITHOUT_METRICS)
elseif (WITH_DETAILED_METRICS)
message("")
message(" *** WITH_DETAILED_METRICS - WARNING!")
message(" *** Please note that this will enable detailed metrics output (i.e. time each session takes to update)")
add_definitions(-DWITH_DETAILED_METRICS)
endif()
if(WITH_BOOST_STACKTRACE)
if (BOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE)
add_definitions(-DBOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE="${BOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE}")
endif()
target_compile_definitions(trinity-compile-option-interface
INTERFACE
WITH_DETAILED_METRICS)
endif()
if(BUILD_SHARED_LIBS)
@@ -176,7 +189,9 @@ if(BUILD_SHARED_LIBS)
message("")
message(" *** Dynamic linking was enforced through a dynamic script module!")
endif()
add_definitions(-DTRINITY_API_USE_DYNAMIC_LINKING)
target_compile_definitions(trinity-compile-option-interface
INTERFACE
TRINITY_API_USE_DYNAMIC_LINKING)
WarnAboutSpacesInBuildPath()
endif()

View File

@@ -59,7 +59,7 @@ target_include_directories(casc
PRIVATE
${CMAKE_SOURCE_DIR}/dep)
target_compile_definitions(casc PUBLIC -D__SYS_ZLIB -DCASCLIB_NO_AUTO_LINK_LIBRARY -DCASCLIB_NODEBUG)
target_compile_definitions(casc PUBLIC __SYS_ZLIB CASCLIB_NO_AUTO_LINK_LIBRARY CASCLIB_NODEBUG)
target_link_libraries(casc
PRIVATE

View File

@@ -36,7 +36,7 @@ target_include_directories(sfmt
${CMAKE_CURRENT_SOURCE_DIR})
# using the standard Mersenne exponent 19937
target_compile_definitions(sfmt PUBLIC -DSFMT_MEXP=19937)
target_compile_definitions(sfmt PUBLIC SFMT_MEXP=19937)
# enable SIMD instructions if available
include(CheckCXXCompilerFlag)
@@ -67,11 +67,11 @@ else ()
endif ()
if (HAVE_NEON)
target_compile_definitions(sfmt PUBLIC -DHAVE_NEON)
target_compile_definitions(sfmt PUBLIC HAVE_NEON)
endif ()
if (HAVE_SSE2)
target_compile_definitions(sfmt PUBLIC -DHAVE_SSE2)
target_compile_definitions(sfmt PUBLIC HAVE_SSE2)
endif ()
set_target_properties(sfmt PROPERTIES LINKER_LANGUAGE CXX)

View File

@@ -23,7 +23,7 @@ add_library(argon2 STATIC
target_compile_definitions(argon2
PRIVATE
-DARGON2_NO_THREADS)
ARGON2_NO_THREADS)
set_target_properties(argon2 PROPERTIES LINKER_LANGUAGE CXX)

View File

@@ -20,8 +20,6 @@ endif()
set(Boost_NO_WARN_NEW_VERSIONS ON)
include (CheckCXXSourceCompiles)
if (WIN32)
# On windows the requirements are higher according to the wiki.
set(BOOST_REQUIRED_VERSION 1.78)
@@ -49,19 +47,24 @@ target_include_directories(boost
target_compile_definitions(boost
INTERFACE
-DBOOST_ALL_NO_LIB
-DBOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE
-DBOOST_ASIO_NO_DEPRECATED
-DBOOST_BIND_NO_PLACEHOLDERS
-DBOOST_SYSTEM_USE_UTF8)
BOOST_ALL_NO_LIB
BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE
BOOST_ASIO_NO_DEPRECATED
BOOST_BIND_NO_PLACEHOLDERS
BOOST_SYSTEM_USE_UTF8)
if (WITH_BOOST_STACKTRACE AND NOT WIN32)
message("*** libbacktrace will be linked")
message(STATUS "libbacktrace will be linked")
include(CheckIncludeFile)
if (BOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE)
CHECK_INCLUDE_FILE(${BOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE} HAS_BACKTRACE)
check_include_file("${BOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE}" HAS_BACKTRACE)
target_compile_definitions(boost
INTERFACE
BOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE=${BOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE})
else()
CHECK_INCLUDE_FILE("backtrace.h" HAS_BACKTRACE)
check_include_file("backtrace.h" HAS_BACKTRACE)
endif()
if (NOT HAS_BACKTRACE)
@@ -70,7 +73,7 @@ if (WITH_BOOST_STACKTRACE AND NOT WIN32)
target_compile_definitions(boost
INTERFACE
-DBOOST_STACKTRACE_USE_BACKTRACE)
BOOST_STACKTRACE_USE_BACKTRACE)
target_link_libraries(boost
INTERFACE

View File

@@ -60,6 +60,12 @@ target_include_directories(g3dlib
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include)
if((CMAKE_SYSTEM_NAME MATCHES "Linux" AND NOT NOJEM) OR TSAN)
target_compile_definitions(g3dlib
PRIVATE
NO_BUFFERPOOL)
endif()
target_link_libraries(g3dlib
PRIVATE
trinity-dependency-interface

View File

@@ -20,7 +20,7 @@ target_include_directories(gsoap
target_compile_definitions(gsoap
PUBLIC
-DWITH_OPENSSL)
WITH_OPENSSL)
target_link_libraries(gsoap
PRIVATE
@@ -37,5 +37,5 @@ if (MSVC)
# Little fix for MSVC / Windows platforms
target_compile_definitions(gsoap
PRIVATE
-D_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=0)
_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=0)
endif()

View File

@@ -91,11 +91,9 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux" AND NOT NOJEM)
${CMAKE_CURRENT_SOURCE_DIR}/include)
target_compile_definitions(jemalloc
PUBLIC
-DNO_BUFFERPOOL
PRIVATE
-D_GNU_SOURCE
-D_REENTRAN)
_GNU_SOURCE
_REENTRAN)
target_link_libraries(jemalloc
PRIVATE

View File

@@ -25,7 +25,7 @@ target_include_directories(openssl_ed25519
target_compile_definitions(openssl_ed25519
PRIVATE
-DOPENSSL_ED25519_EXPORT
OPENSSL_ED25519_EXPORT
)
target_link_libraries(openssl_ed25519

View File

@@ -74,10 +74,10 @@ target_link_libraries(protobuf
if (BUILD_SHARED_LIBS)
target_compile_definitions(protobuf
PRIVATE
-DLIBPROTOBUF_EXPORTS
-DLIBPROTOC_EXPORTS
LIBPROTOBUF_EXPORTS
LIBPROTOC_EXPORTS
PUBLIC
-DPROTOBUF_USE_DLLS)
PROTOBUF_USE_DLLS)
endif()
if (MSVC)
@@ -87,7 +87,7 @@ if (MSVC)
target_compile_definitions(protobuf
PRIVATE
-D_SCL_SECURE_NO_WARNINGS)
_SCL_SECURE_NO_WARNINGS)
endif()
set_target_properties(protobuf

View File

@@ -16,9 +16,9 @@ target_include_directories(rapidjson
target_compile_definitions(rapidjson
INTERFACE
-DRAPIDJSON_HAS_STDSTRING
-DRAPIDJSON_48BITPOINTER_OPTIMIZATION=0
-DRAPIDJSON_ASSERT=WPAssert)
RAPIDJSON_HAS_STDSTRING
RAPIDJSON_48BITPOINTER_OPTIMIZATION=0
RAPIDJSON_ASSERT=WPAssert)
if(TRINITY_SYSTEM_PROCESSOR MATCHES "x86|amd64")
target_compile_definitions(rapidjson INTERFACE -DRAPIDJSON_SSE2)

View File

@@ -29,21 +29,10 @@ endif(USE_COREPCH)
GroupSources(${CMAKE_CURRENT_SOURCE_DIR})
add_definitions(-DTRINITY_API_EXPORT_COMMON)
add_library(common
${PRIVATE_SOURCES}
)
# Do NOT add any extra include directory here, as we don't want the common
# library to depend on anything else than TC deps, and itself.
# This way we ensure that if either a PR does that without modifying this file,
# a compile error will be generated, either this file will be modified so it
# is detected more easily.
# While it is OK to include files from other libs as long as they don't require
# linkage (enums, defines...) it is discouraged to do so unless necessary, as it will pullute
# include_directories leading to further unnoticed dependency aditions
# Linker Depencency requirements: none
CollectIncludeDirectories(
${CMAKE_CURRENT_SOURCE_DIR}
PUBLIC_INCLUDES
@@ -58,6 +47,10 @@ target_include_directories(common
PRIVATE
${CMAKE_CURRENT_BINARY_DIR})
target_compile_definitions(common
PRIVATE
TRINITY_API_EXPORT_COMMON)
target_link_libraries(common
PRIVATE
trinity-core-interface

View File

@@ -8,14 +8,6 @@
# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# Enforce compileparameters for corebuilds under GCC
# This to stop a few silly crashes that could have been avoided IF people
# weren't doing some -O3 psychooptimizations etc.
if(CMAKE_COMPILER_IS_GNUCXX AND NOT MINGW)
add_definitions(-fno-delete-null-pointer-checks)
endif()
if(WIN32)
list(APPEND sources_windows
${CMAKE_SOURCE_DIR}/src/common/Platform/ServiceWin32.cpp

View File

@@ -24,15 +24,6 @@ add_library(database
${PRIVATE_SOURCES}
)
# Do NOT add any extra include directory unless it does not create unneeded extra dependencies,
# and specially, not add any dependency to neither of these: shared, game, scripts
# This way we ensure that if either a PR does that without modifying this file,
# a compile error will be generated, either this file will be modified so it
# is detected more easily.
# While it is OK to include files from other libs as long as they don't require
# linkage (enums, defines...) it is discouraged to do so unless necessary, as it will pullute
# include_directories leading to further unnoticed dependency aditions
# Linker Depencency requirements: common
CollectIncludeDirectories(
${CMAKE_CURRENT_SOURCE_DIR}
PUBLIC_INCLUDES
@@ -45,7 +36,9 @@ target_include_directories(database
PRIVATE
${CMAKE_CURRENT_BINARY_DIR})
add_definitions(-DTRINITY_API_EXPORT_DATABASE)
target_compile_definitions(database
PRIVATE
TRINITY_API_EXPORT_DATABASE)
target_link_libraries(database
PRIVATE

View File

@@ -20,8 +20,6 @@ endif()
GroupSources(${CMAKE_CURRENT_SOURCE_DIR})
add_definitions(-DTRINITY_API_EXPORT_GAME)
CollectIncludeDirectories(
${CMAKE_CURRENT_SOURCE_DIR}
PUBLIC_INCLUDES
@@ -48,6 +46,10 @@ target_include_directories(game
PRIVATE
${CMAKE_CURRENT_BINARY_DIR})
target_compile_definitions(game
PRIVATE
TRINITY_API_EXPORT_GAME)
target_link_libraries(game
PRIVATE
trinity-core-interface

View File

@@ -20,8 +20,6 @@ endif()
GroupSources(${CMAKE_CURRENT_SOURCE_DIR})
add_definitions(-DTRINITY_API_EXPORT_PROTO)
add_library(proto
${PRIVATE_SOURCES}
)
@@ -40,6 +38,10 @@ target_include_directories(proto
PRIVATE
${CMAKE_CURRENT_BINARY_DIR})
target_compile_definitions(proto
PRIVATE
TRINITY_API_EXPORT_PROTO)
target_link_libraries(proto
PRIVATE
trinity-default-interface

View File

@@ -20,8 +20,6 @@ endif()
GroupSources(${CMAKE_CURRENT_SOURCE_DIR})
add_definitions(-DTRINITY_API_EXPORT_SHARED)
add_library(shared
${PRIVATE_SOURCES}
)
@@ -38,6 +36,10 @@ target_include_directories(shared
PRIVATE
${CMAKE_CURRENT_BINARY_DIR})
target_compile_definitions(shared
PRIVATE
TRINITY_API_EXPORT_SHARED)
target_link_libraries(shared
PRIVATE
trinity-core-interface

View File

@@ -39,12 +39,6 @@ if(NOT WIN32)
)
endif()
if(UNIX AND NOT NOJEM AND NOT APPLE)
set(worldserver_LINK_FLAGS "-pthread -lncurses ${worldserver_LINK_FLAGS}")
endif()
set_target_properties(worldserver PROPERTIES LINK_FLAGS "${worldserver_LINK_FLAGS}")
target_link_libraries(worldserver
PRIVATE
trinity-core-interface