Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CMakeLists.txt #220

Merged
merged 5 commits into from
Apr 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 43 additions & 59 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
cmake_minimum_required(VERSION 3.20) # For using CMAKE_<LANG>_BYTE_ORDER

project(Descent3 VERSION 1.5.500)

if(NOT MSVC) # GCC/clang or compatible, hopefully
option(FORCE_COLORED_OUTPUT "Always produce ANSI-colored compiler warnings/errors (GCC/Clang only; esp. useful with ninja)." OFF)
# set default cmake build type to Debug (None Debug Release RelWithDebInfo MinSizeRel)
if(NOT CMAKE_BUILD_TYPE AND NOT DEFINED ENV{CMAKE_BUILD_TYPE})
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "default build type")
endif()

project(Descent3
LANGUAGES C CXX
VERSION 1.5.500
)

option(FORCE_COLORED_OUTPUT "Always produce ANSI-colored compiler warnings/errors (GCC/Clang only; esp. useful with ninja)." OFF)
option(LOGGER "Enable logging to the terminal" OFF)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_EXTENSIONS OFF)

if(FORCE_COLORED_OUTPUT)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24)
set(CMAKE_COLOR_DIAGNOSTICS ON)
else()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options (-fdiagnostics-color=always)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options (-fcolor-diagnostics)
endif()
endif()
endif()

if(CMAKE_CXX_BYTE_ORDER STREQUAL "BIG_ENDIAN")
message(STATUS "Big Endian system detected.")
add_definitions("-DOUTRAGE_BIG_ENDIAN")
add_compile_definitions("OUTRAGE_BIG_ENDIAN")
endif()

if(BUILD_TESTING)
Expand All @@ -25,39 +42,17 @@ if(BUILD_TESTING)
add_subdirectory(tests)
endif()

if(NOT MSVC)
# check if this is some kind of clang (Clang, AppleClang, whatever)
# (convert compiler ID to lowercase so we match Clang, clang, AppleClang etc, regardless of case)
string(TOLOWER ${CMAKE_CXX_COMPILER_ID} compiler_id_lower)
if(compiler_id_lower MATCHES ".*clang.*")
message(STATUS "Compiler \"${CMAKE_CXX_COMPILER_ID}\" detected as some kind of clang")
set(D3_COMPILER_IS_CLANG TRUE)
set(D3_COMPILER_IS_GCC_OR_CLANG TRUE)
elseif(CMAKE_COMPILER_IS_GNUCC)
set(D3_COMPILER_IS_GCC_OR_CLANG TRUE)
endif()
unset(compiler_id_lower)

if(FORCE_COLORED_OUTPUT)
if(CMAKE_COMPILER_IS_GNUCC)
add_compile_options (-fdiagnostics-color=always)
elseif(D3_COMPILER_IS_CLANG)
add_compile_options (-fcolor-diagnostics)
endif ()
endif ()
endif()

if(UNIX)
set(D3_GAMEDIR "~/Descent3/")

string(APPEND CMAKE_CXX_FLAGS " -Wno-write-strings -Wno-multichar ${BITS} ${EXTRA_CXX_FLAGS}")
string(APPEND CMAKE_C_FLAGS " ${BITS}")
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:-Wno-write-strings;-Wno-multichar;${BITS};${EXTRA_CXX_FLAGS}>")
add_compile_options("$<$<COMPILE_LANGUAGE:C>:${BITS}>")

find_package(SDL REQUIRED)
if(APPLE)
# Provide FIND_PACKAGE( SDL_image ) below with an include dir and library that work with brew-installed sdl2_image
find_path(SDL_IMAGE_INCLUDE_DIR SDL_image.h PATH_SUFFIXES include/SDL2)
find_library(SDL_IMAGE_LIBRARY SDL2_image)
find_path(SDL_IMAGE_INCLUDE_DIR NAMES SDL_image.h PATH_SUFFIXES include/SDL2)
find_library(SDL_IMAGE_LIBRARY NAMES SDL2_image)
endif()

find_package(SDL_image REQUIRED)
Expand All @@ -66,36 +61,32 @@ if(UNIX)
message("SDL Include Dir is " ${SDL_INCLUDE_DIR})
endif()

if(UNIX AND NOT APPLE)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
message("Building for Linux")
add_definitions(-D__LINUX__ -DLINUX -D_MAX_PATH=260 -D_MAX_FNAME=256 -D_REENRANT -D__32BIT__ -DHAVEALLOCA_H -D_USE_OGL_ACTIVE_TEXTURES)
add_compile_definitions(__LINUX__ LINUX _MAX_PATH=260 _MAX_FNAME=256 _REENRANT __32BIT__ HAVEALLOCA_H _USE_OGL_ACTIVE_TEXTURES)
set(PLATFORM_INCLUDES "lib/linux" ${SDL_INCLUDE_DIR})
endif()

if(APPLE)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
message("Building for MAC OSX")
add_definitions(-D__LINUX__ -DLINUX -D_MAX_PATH=260 -D_MAX_FNAME=256 -D_REENRANT -DMACOSX=1 -D_USE_OGL_ACTIVE_TEXTURES)
add_compile_definitions(__LINUX__ LINUX _MAX_PATH=260 _MAX_FNAME=256 _REENRANT MACOSX=1 _USE_OGL_ACTIVE_TEXTURES)
set(PLATFORM_INCLUDES "lib/linux" ${SDL_INCLUDE_DIR} "/usr/X11/include")
endif()

if(WIN32)
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "lib/win" "lib/win/directx")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /EHsc /RTC1 /W3 /nologo /c /Zi /TP /errorReport:prompt")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GL /FD /EHsc /W3 /nologo /c /Zi /TP /errorReport:prompt")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
list(APPEND CMAKE_LIBRARY_PATH "lib/win" "lib/win/directx")
add_compile_options("$<$<AND:$<CONFIG:Debug>,$<COMPILE_LANGUAGE:CXX>>:/EHsc;/RTC1;/W3;/nologo;/c;/Zi;/TP;/errorReport:prompt>")
add_compile_options("$<$<AND:$<CONFIG:Release>,$<COMPILE_LANGUAGE:CXX>>:/GL;/FD;/EHsc;/W3;/nologo;/c;/Zi;/TP;/errorReport:prompt>")

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO /SUBSYSTEM:WINDOWS /NODEFAULTLIB:LIBC")
string(APPEND CMAKE_EXE_LINKER_FLAGS " /SAFESEH:NO /SUBSYSTEM:WINDOWS /NODEFAULTLIB:LIBC")
set(CMAKE_MODULE_LINKER_FLAGS "/SAFESEH:NO /SUBSYSTEM:WINDOWS /NODEFAULTLIB:LIBC")
add_definitions(-DIS_WINDOWS -D_CRT_SECURE_NO_WARNINGS -DWIN32 -D_CRT_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -DNOMINMAX)
add_compile_definitions(IS_WINDOWS _CRT_SECURE_NO_WARNINGS WIN32 _CRT_SECURE_NO_WARNINGS _CRT_SECURE_NO_DEPRECATE _CRT_NONSTDC_NO_DEPRECATE NOMINMAX)

set(PLATFORM_INCLUDES "lib/win/directx" "lib/win")

set(CMAKE_FIND_LIBRARY_PREFIXES "")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib")

find_library(DSOUND_LIBRARY NAMES dsound "${CMAKE_SOURCE_DIR}/lib/win" "${CMAKE_SOURCE_DIR}/lib/win/directx")
find_library(DINPUT_LIBRARY NAMES dinput "${CMAKE_SOURCE_DIR}/lib/win" "${CMAKE_SOURCE_DIR}/lib/win/directx")
find_library(DXGUID_LIBRARY NAMES dxguid "${CMAKE_SOURCE_DIR}/lib/win" "${CMAKE_SOURCE_DIR}/lib/win/directx")
find_library(DDRAW_LIBRARY NAMES ddraw "${CMAKE_SOURCE_DIR}/lib/win" "${CMAKE_SOURCE_DIR}/lib/win/directx")
find_library(DSOUND_LIBRARY NAMES dsound REQUIRED PATHS "${CMAKE_SOURCE_DIR}/lib/win" "${CMAKE_SOURCE_DIR}/lib/win/directx")
find_library(DINPUT_LIBRARY NAMES dinput REQUIRED PATHS "${CMAKE_SOURCE_DIR}/lib/win" "${CMAKE_SOURCE_DIR}/lib/win/directx")
find_library(DXGUID_LIBRARY NAMES dxguid REQUIRED PATHS "${CMAKE_SOURCE_DIR}/lib/win" "${CMAKE_SOURCE_DIR}/lib/win/directx")
find_library(DDRAW_LIBRARY NAMES ddraw REQUIRED PATHS "${CMAKE_SOURCE_DIR}/lib/win" "${CMAKE_SOURCE_DIR}/lib/win/directx")

if(MSVC AND CMAKE_CXX_SIMULATE_ID STREQUAL "")
add_compile_options("/we4150") # deletion of pointer to incomplete type 'type'; no destructor called
Expand All @@ -118,7 +109,7 @@ find_package(ZLIB REQUIRED)

if(LOGGER)
message("Enabling Logging")
add_definitions(-DLOGGER)
add_compile_definitions(LOGGER)
endif()

include_directories(
Expand All @@ -137,15 +128,13 @@ add_subdirectory(cfile)
add_subdirectory(czip)
add_subdirectory(d3music)

if(WIN32)
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
add_subdirectory(dd_grwin32)
add_subdirectory(dd_vidwin32)
add_subdirectory(win32)
add_subdirectory(dd_sndlib)
add_subdirectory(ddio_win)
endif()

if(UNIX)
else()
add_subdirectory(linux)
add_subdirectory(ddvid_lnx)
add_subdirectory(dd_lnxsound)
Expand Down Expand Up @@ -186,8 +175,3 @@ if(UNIX)
add_subdirectory(netcon)
add_subdirectory(scripts)
endif()

# set default cmake build type to Debug (None Debug Release RelWithDebInfo MinSizeRel)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()