altered cmake configuration scripts

This commit is contained in:
jadebenn 2024-04-08 20:11:59 -05:00
parent 368f4ccabf
commit 24d3bc0ce6
5 changed files with 37 additions and 27 deletions

View File

@ -1,9 +1,14 @@
cmake_minimum_required(VERSION 3.25) cmake_minimum_required(VERSION 3.25)
project(Darkflame) project(Darkflame
HOMEPAGE_URL "https://github.com/DarkflameUniverse/DarkflameServer"
LANGUAGES C CXX
)
include(CTest) include(CTest)
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD 20)
set(CXX_STANDARD_REQUIRED ON) set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Export the compile commands for debugging set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Export the compile commands for debugging
set(CMAKE_POLICY_DEFAULT_CMP0063 NEW) # Set CMAKE visibility policy to NEW on project and subprojects set(CMAKE_POLICY_DEFAULT_CMP0063 NEW) # Set CMAKE visibility policy to NEW on project and subprojects
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON) # Set C and C++ symbol visibility to hide inlined functions set(CMAKE_VISIBILITY_INLINES_HIDDEN ON) # Set C and C++ symbol visibility to hide inlined functions
@ -55,23 +60,21 @@ set(RECASTNAVIGATION_EXAMPLES OFF CACHE BOOL "" FORCE)
# Disabled no-register # Disabled no-register
# Disabled unknown pragmas because Linux doesn't understand Windows pragmas. # Disabled unknown pragmas because Linux doesn't understand Windows pragmas.
if(UNIX) if(UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wuninitialized -fPIC") add_compile_options("-fPIC")
add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=0 _GLIBCXX_USE_CXX17_ABI=0) add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=0 _GLIBCXX_USE_CXX17_ABI=0)
# For all except Clang and Apple Clang # For all except Clang and Apple Clang
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang") if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -lstdc++fs") add_compile_options("-static-libgcc" "-lstdc++fs")
endif() endif()
if(${DYNAMIC} AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU") if(${DYNAMIC} AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -rdynamic") add_compile_options("-rdynamic")
endif() endif()
if(${GGDB}) if(${GGDB})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb") add_compile_options("-ggdb")
endif() endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -fPIC")
elseif(MSVC) elseif(MSVC)
# Skip warning for invalid conversion from size_t to uint32_t for all targets below for now # Skip warning for invalid conversion from size_t to uint32_t for all targets below for now
# Also disable non-portable MSVC volatile behavior # Also disable non-portable MSVC volatile behavior
@ -231,14 +234,15 @@ include_directories(
"tests/dGameTests" "tests/dGameTests"
"tests/dGameTests/dComponentsTests" "tests/dGameTests/dComponentsTests"
SYSTEM "thirdparty/magic_enum/include/magic_enum" SYSTEM
SYSTEM "thirdparty/raknet/Source" "thirdparty/magic_enum/include/magic_enum"
SYSTEM "thirdparty/tinyxml2" "thirdparty/raknet/Source"
SYSTEM "thirdparty/recastnavigation" "thirdparty/tinyxml2"
SYSTEM "thirdparty/SQLite" "thirdparty/recastnavigation"
SYSTEM "thirdparty/cpplinq" "thirdparty/SQLite"
SYSTEM "thirdparty/cpp-httplib" "thirdparty/cpplinq"
SYSTEM "thirdparty/MD5" "thirdparty/cpp-httplib"
"thirdparty/MD5"
) )
# Add system specfic includes for Apple, Windows and Other Unix OS' (including Linux) # Add system specfic includes for Apple, Windows and Other Unix OS' (including Linux)
@ -247,10 +251,16 @@ if(APPLE)
include_directories("/usr/local/include/") include_directories("/usr/local/include/")
endif() endif()
# Add linking directories: # Set warning flags
if (UNIX) if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wold-style-cast -Werror") # Warning flags add_compile_options("/WX")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
add_compile_options("-Wuninitialized" "-Wold-style-cast" "-Werror")
else()
message(WARNING "Unknown compiler: '${CMAKE_CXX_COMPILER_ID}' No warning flags enabled.")
endif() endif()
# Add linking directories:
file( file(
GLOB HEADERS_DZONEMANAGER GLOB HEADERS_DZONEMANAGER
LIST_DIRECTORIES false LIST_DIRECTORIES false

View File

@ -3,8 +3,8 @@ find_program(CLANG_C_COMPILER clang-16 | clang REQUIRED)
find_program(CLANG_CXX_COMPILER clang++-16 | clang++ REQUIRED) find_program(CLANG_CXX_COMPILER clang++-16 | clang++ REQUIRED)
# Debug messages # Debug messages
message("CLANG_C_COMPILER = ${CLANG_C_COMPILER}") message(DEBUG "CLANG_C_COMPILER = ${CLANG_C_COMPILER}")
message("CLANG_CXX_COMPILER = ${CLANG_CXX_COMPILER}") message(DEBUG "CLANG_CXX_COMPILER = ${CLANG_CXX_COMPILER}")
# Set compilers to clang # Set compilers to clang
set(CMAKE_C_COMPILER ${CLANG_C_COMPILER}) set(CMAKE_C_COMPILER ${CLANG_C_COMPILER})

View File

@ -1,10 +1,10 @@
# Try and find a gcc/g++ install # Try and find a gcc/g++ install
find_program(GNU_C_COMPILER gcc REQUIRED) find_program(GNU_C_COMPILER cc | gcc REQUIRED)
find_program(GNU_CXX_COMPILER g++ REQUIRED) find_program(GNU_CXX_COMPILER c++ | g++ REQUIRED)
# Debug messages # Debug messages
message("GNU_C_COMPILER = ${GNU_C_COMPILER}") message(DEBUG "GNU_C_COMPILER = ${GNU_C_COMPILER}")
message("GNU_CXX_COMPILER = ${GNU_C_COMPILER}") message(DEBUG "GNU_CXX_COMPILER = ${GNU_C_COMPILER}")
# Set compilers to clang # Set compilers to clang
set(CMAKE_C_COMPILER ${GNU_C_COMPILER}) set(CMAKE_C_COMPILER ${GNU_C_COMPILER})

View File

@ -6,7 +6,7 @@ set(DMASTERSERVER_SOURCES
add_library(dMasterServer ${DMASTERSERVER_SOURCES}) add_library(dMasterServer ${DMASTERSERVER_SOURCES})
add_executable(MasterServer "MasterServer.cpp") add_executable(MasterServer "MasterServer.cpp")
add_compile_definitions(MasterServer PRIVATE PROJECT_VERSION="\"${PROJECT_VERSION}\"") target_compile_definitions(MasterServer PRIVATE PROJECT_VERSION="\"${PROJECT_VERSION}\"")
target_include_directories(dMasterServer PUBLIC "." target_include_directories(dMasterServer PUBLIC "."
"${PROJECT_SOURCE_DIR}/dZoneManager" # InstanceManager.h uses dZMCommon.h "${PROJECT_SOURCE_DIR}/dZoneManager" # InstanceManager.h uses dZMCommon.h
${PROJECT_SOURCE_DIR}/dServer/ # BinaryPathFinder.h ${PROJECT_SOURCE_DIR}/dServer/ # BinaryPathFinder.h

View File

@ -24,7 +24,7 @@ if(NOT WIN32)
endif() endif()
# Need to define this on Clang and GNU for 'strdup' support # Need to define this on Clang and GNU for 'strdup' support
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
target_compile_definitions(bcrypt PRIVATE "_POSIX_C_SOURCE=200809L") target_compile_definitions(bcrypt PRIVATE "_POSIX_C_SOURCE=200809L")
endif() endif()