2024-04-23 18:10:18 +00:00
cmake_minimum_required ( VERSION 3.20 ) # For using CMAKE_<LANG>_BYTE_ORDER
2024-04-21 09:02:27 +00:00
2024-04-22 03:40:03 +00:00
# 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 ( )
2024-10-12 16:32:27 +00:00
# toolchain setup for vcpkg must be done before the 'project' call
2024-06-26 04:06:02 +00:00
set ( USE_VCPKG "DEFAULT" CACHE STRING "Use vcpkg for dependency management. DEFAULT defers to existence of $VCPKG_ROOT environment variable." )
set_property ( CACHE USE_VCPKG PROPERTY STRINGS "DEFAULT" "ON" "OFF" )
2024-04-23 17:53:00 +00:00
2024-06-26 04:06:02 +00:00
if ( USE_VCPKG )
if ( DEFINED ENV{VCPKG_ROOT} )
if ( CMAKE_TOOLCHAIN_FILE )
cmake_path ( ABSOLUTE_PATH CMAKE_TOOLCHAIN_FILE NORMALIZE OUTPUT_VARIABLE VCPKG_CHAINLOAD_TOOLCHAIN_FILE )
endif ( )
set ( VCPKG_TOOLCHAIN_FILE "scripts/buildsystems/vcpkg.cmake" )
cmake_path ( ABSOLUTE_PATH VCPKG_TOOLCHAIN_FILE BASE_DIRECTORY $ENV{ VCPKG_ROOT } NORMALIZE OUTPUT_VARIABLE CMAKE_TOOLCHAIN_FILE )
if ( CMAKE_TOOLCHAIN_FILE STREQUAL VCPKG_CHAINLOAD_TOOLCHAIN_FILE )
# prevent endless recursion
unset ( VCPKG_CHAINLOAD_TOOLCHAIN_FILE )
endif ( )
elseif ( NOT USE_VCPKG STREQUAL "DEFAULT" )
message ( WARNING "USE_VCPKG=${USE_VCPKG} but ENV{VCPKG_ROOT} not set; will use system-provided libraries. Did you forget to set VCPKG_ROOT in your environment?" )
endif ( )
endif ( )
project ( Descent3
L A N G U A G E S C C X X
2024-08-17 21:04:34 +00:00
V E R S I O N 1 . 6 . 0
2024-06-26 04:06:02 +00:00
)
2024-10-12 16:32:27 +00:00
option ( BUILD_TESTING "Enable testing. Requires GTest." OFF )
option ( ENABLE_LOGGER "Enable logging to the terminal" OFF )
option ( ENABLE_MEM_RTL "Enable Real-time library memory management functions (disable to verbose memory allocations)" ON )
option ( FATAL_GL_ERRORS "Check OpenGL calls and raise exceptions on errors." OFF )
option ( FORCE_COLORED_OUTPUT "Always produce ANSI-colored compiler warnings/errors (GCC/Clang only; esp. useful with Ninja)." OFF )
option ( FORCE_PORTABLE_INSTALL "Install all files into local directory defined by CMAKE_INSTALL_PREFIX" ON )
option ( USE_EXTERNAL_PLOG "Use system plog library instead bundled" OFF )
if ( CMAKE_SYSTEM_NAME STREQUAL "Windows" )
option ( BUILD_EDITOR "Build internal editor" OFF )
endif ( )
2024-04-21 09:02:27 +00:00
set ( CMAKE_CXX_STANDARD 17 )
set ( CMAKE_CXX_STANDARD_REQUIRED ON )
set ( CMAKE_POSITION_INDEPENDENT_CODE ON )
set ( CMAKE_CXX_EXTENSIONS OFF )
2024-06-22 01:19:30 +00:00
set ( CMAKE_EXPORT_COMPILE_COMMANDS ON )
2024-04-21 09:02:27 +00:00
2024-07-03 17:55:04 +00:00
set_property ( GLOBAL PROPERTY USE_FOLDERS ON )
2024-07-07 12:51:54 +00:00
if ( MSVC )
Explicitly declare execution character set
Consider this program:
#include <cstdio>
int main(void) {
const char *example_string = "ディセント3";
for (size_t i = 0; example_string[i] != '\0'; ++i) {
printf("%02hhx ", example_string[i]);
}
puts("");
return 0;
}
What will that program output? The answer is: it depends. If that
program is compiled with a UTF-8 execution character set, then it will
print this:
e3 83 87 e3 82 a3 e3 82 bb e3 83 b3 e3 83 88 33
If that program is compiled with a Shift JIS execution character set,
then it will print this:
83 66 83 42 83 5a 83 93 83 67 33
This is especially a problem when using MSVC. MSVC doesn’t necessarily
default to using UTF-8 as a program’s execution character set [1].
---
Before this change, Descent 3 would use whatever the default execution
character set was. This commit ensures that the execution character set
is UTF-8 as long as Descent 3 gets compiled with MSVC, GCC or Clang. If
Descent 3 is compiled with a different compiler, then a different
execution character set might get used, but as far as I know, we only
support MSVC, GCC and Clang.
I’m not sure whether or not this change has any noticeable effects. If
using different execution character sets do have noticeable effects,
then this change will hopefully ensure that those effects are the same
for everyone.
[1]: <https://learn.microsoft.com/en-us/answers/questions/1805730/what-is-msvc-s-default-execution-character-set>
2024-07-07 16:54:52 +00:00
add_compile_options ( /source-charset:UTF-8 /execution-charset:UTF-8 )
2024-07-07 12:51:54 +00:00
else ( )
add_compile_options ( -finput-charset=UTF-8 )
Explicitly declare execution character set
Consider this program:
#include <cstdio>
int main(void) {
const char *example_string = "ディセント3";
for (size_t i = 0; example_string[i] != '\0'; ++i) {
printf("%02hhx ", example_string[i]);
}
puts("");
return 0;
}
What will that program output? The answer is: it depends. If that
program is compiled with a UTF-8 execution character set, then it will
print this:
e3 83 87 e3 82 a3 e3 82 bb e3 83 b3 e3 83 88 33
If that program is compiled with a Shift JIS execution character set,
then it will print this:
83 66 83 42 83 5a 83 93 83 67 33
This is especially a problem when using MSVC. MSVC doesn’t necessarily
default to using UTF-8 as a program’s execution character set [1].
---
Before this change, Descent 3 would use whatever the default execution
character set was. This commit ensures that the execution character set
is UTF-8 as long as Descent 3 gets compiled with MSVC, GCC or Clang. If
Descent 3 is compiled with a different compiler, then a different
execution character set might get used, but as far as I know, we only
support MSVC, GCC and Clang.
I’m not sure whether or not this change has any noticeable effects. If
using different execution character sets do have noticeable effects,
then this change will hopefully ensure that those effects are the same
for everyone.
[1]: <https://learn.microsoft.com/en-us/answers/questions/1805730/what-is-msvc-s-default-execution-character-set>
2024-07-07 16:54:52 +00:00
# Unfortunately, Clang doesn’ t support -fexec-charset yet so this next part
# is GCC only. Luckily, Clang defaults to using UTF-8 for the execution
# character set [1], so we’ re fine. Once Clang gets support for
# -fexec-charset, we should probably start using it.
#
# [1]: <https://discourse.llvm.org/t/rfc-enabling-fexec-charset-support-to-llvm-and-clang-reposting/71512>
if ( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
add_compile_options ( -fexec-charset=UTF-8 )
endif ( )
2024-07-07 12:51:54 +00:00
endif ( )
2024-04-22 17:25:55 +00:00
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" )
2024-04-29 19:52:42 +00:00
add_compile_options ( -fdiagnostics-color=always )
2024-04-22 17:25:55 +00:00
elseif ( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
2024-04-29 19:52:42 +00:00
add_compile_options ( -fcolor-diagnostics )
2024-04-22 17:25:55 +00:00
endif ( )
endif ( )
endif ( )
2024-10-20 18:55:46 +00:00
list ( APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" )
2024-05-08 20:27:25 +00:00
include ( GNUInstallDirs )
if ( FORCE_PORTABLE_INSTALL )
set ( CMAKE_INSTALL_BINDIR "." )
set ( CMAKE_INSTALL_LIBDIR "." )
set ( CMAKE_INSTALL_DATADIR "." )
set ( CMAKE_INSTALL_DOCDIR "." )
endif ( )
2024-10-26 12:36:37 +00:00
# Get info about multi-config environment
get_property ( IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG )
# Properly determine output directory for generated files
if ( IS_MULTI_CONFIG )
set ( D3_GENERATED_FILES_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/build/$<CONFIG>" )
else ( )
set ( D3_GENERATED_FILES_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/build" )
endif ( )
2024-05-08 20:27:25 +00:00
if ( CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT )
set ( CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/installed" CACHE PATH "Default install path" FORCE )
endif ( )
2024-04-23 18:10:18 +00:00
if ( CMAKE_CXX_BYTE_ORDER STREQUAL "BIG_ENDIAN" )
message ( STATUS "Big Endian system detected." )
2024-04-28 11:24:10 +00:00
add_compile_definitions ( "OUTRAGE_BIG_ENDIAN" )
2024-04-23 18:10:18 +00:00
endif ( )
2024-04-25 16:58:11 +00:00
# 64 bit machines have a different game checksum than 32 bit machines
if ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
2024-04-25 17:54:29 +00:00
add_definitions ( -DCHECKSUM=2273889835UL )
2024-04-25 16:58:11 +00:00
else ( )
add_definitions ( -DCHECKSUM=2273873307UL )
endif ( )
2024-04-23 18:10:18 +00:00
if ( BUILD_TESTING )
find_package ( GTest REQUIRED )
enable_testing ( )
include ( GoogleTest )
add_subdirectory ( tests )
endif ( )
2024-10-20 18:55:46 +00:00
# Define names for HOG files
if ( CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" )
set ( HOG_NAME "linux" )
elseif ( CMAKE_SYSTEM_NAME STREQUAL "Darwin" )
set ( HOG_NAME "osx" )
elseif ( CMAKE_SYSTEM_NAME STREQUAL "Windows" )
set ( HOG_NAME "win" )
endif ( )
2024-06-20 20:51:18 +00:00
# rebuild d3_version.h every time
add_custom_target ( get_git_hash ALL )
2024-04-28 18:42:02 +00:00
add_custom_command (
2024-06-20 20:51:18 +00:00
T A R G E T g e t _ g i t _ h a s h
2024-04-28 18:42:02 +00:00
C O M M A N D $ { C M A K E _ C O M M A N D }
- D S O U R C E _ D I R = $ { P R O J E C T _ S O U R C E _ D I R }
- D T A R G E T _ D I R = $ { P R O J E C T _ B I N A R Y _ D I R }
- D P R O J E C T _ V E R S I O N _ M A J O R = $ { P R O J E C T _ V E R S I O N _ M A J O R }
- D P R O J E C T _ V E R S I O N _ M I N O R = $ { P R O J E C T _ V E R S I O N _ M I N O R }
- D P R O J E C T _ V E R S I O N _ P A T C H = $ { P R O J E C T _ V E R S I O N _ P A T C H }
- P $ { P R O J E C T _ S O U R C E _ D I R } / c m a k e / C h e c k G i t . c m a k e
W O R K I N G _ D I R E C T O R Y $ { P R O J E C T _ S O U R C E _ D I R }
)
2024-06-12 15:33:27 +00:00
install (
2024-08-09 22:57:47 +00:00
F I L E S C H A N G E L O G . m d U S A G E . m d R E A D M E . m d B U I L D . m d L I C E N S E T H I R D _ P A R T Y . m d
2024-06-12 15:33:27 +00:00
D E S T I N A T I O N $ { C M A K E _ I N S T A L L _ D O C D I R }
)
2024-05-08 20:27:25 +00:00
2024-06-29 00:07:45 +00:00
if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
add_compile_options ( "-Wno-multichar;-Wall" )
2024-04-21 09:02:27 +00:00
endif ( )
2024-07-28 09:18:54 +00:00
find_package ( glm REQUIRED )
2024-06-21 16:46:53 +00:00
find_package ( SDL2 REQUIRED )
# Some versions of the SDL2 find_package set SDL2_INCLUDE_DIR and some set a plural SDL2_INCLUDE_DIRS. Check both.
message ( "SDL2 Include Dir is ${SDL2_INCLUDE_DIR} ${SDL2_INCLUDE_DIRS}" )
2024-08-19 19:45:29 +00:00
if ( USE_EXTERNAL_PLOG )
find_package ( plog REQUIRED )
endif ( )
2024-06-21 16:46:53 +00:00
2024-08-20 14:03:24 +00:00
if ( CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" )
2024-04-21 09:02:27 +00:00
message ( "Building for Linux" )
2024-07-12 23:33:08 +00:00
add_compile_definitions ( POSIX __LINUX__ _USE_OGL_ACTIVE_TEXTURES PRIMARY_HOG=\ "d3-linux.hog\" )
2024-04-30 16:36:52 +00:00
set ( PLATFORM_INCLUDES "lib/linux" ${ SDL2_INCLUDE_DIR } ${ SDL2_INCLUDE_DIRS } )
2024-04-22 17:23:47 +00:00
elseif ( CMAKE_SYSTEM_NAME STREQUAL "Darwin" )
2024-04-21 09:02:27 +00:00
message ( "Building for MAC OSX" )
2024-07-12 23:33:08 +00:00
add_compile_definitions ( POSIX MACOSX=1 _USE_OGL_ACTIVE_TEXTURES PRIMARY_HOG=\ "d3-osx.hog\" )
2024-04-30 16:36:52 +00:00
set ( PLATFORM_INCLUDES "lib/linux" ${ SDL2_INCLUDE_DIR } ${ SDL2_INCLUDE_DIRS } )
2024-04-22 17:23:47 +00:00
elseif ( CMAKE_SYSTEM_NAME STREQUAL "Windows" )
2024-05-07 21:37:06 +00:00
# Windows.h defines to avoid as many issues as possible.
2024-06-03 20:38:39 +00:00
add_compile_definitions ( WIN32_LEAN_AND_MEAN NOMINMAX NODRAWTEXT NOBITMAP NOMCX NOSERVICE PRIMARY_HOG=\ "d3-win.hog\"
2024-05-07 21:37:06 +00:00
#[[NOGDI]] # We need GDI for now, enable when GDI is actually not needed (or when all windows.h mentions are gone)
)
2024-05-22 09:59:07 +00:00
list ( APPEND CMAKE_LIBRARY_PATH "lib/win" "lib/win/DirectX/${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" )
2024-04-22 03:40:03 +00:00
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>" )
2024-04-21 09:02:27 +00:00
2024-07-28 16:33:57 +00:00
add_link_options ( "/SAFESEH:NO;/NODEFAULTLIB:LIBC" )
2024-07-28 16:38:02 +00:00
add_link_options ( "$<$<CONFIG:Release>:/LTCG>" )
2024-07-28 16:33:57 +00:00
2024-07-28 16:39:05 +00:00
add_compile_definitions ( WIN32 _CRT_SECURE_NO_WARNINGS _CRT_SECURE_NO_DEPRECATE _CRT_NONSTDC_NO_DEPRECATE )
2024-04-21 09:02:27 +00:00
2024-05-22 09:59:07 +00:00
set ( PLATFORM_INCLUDES "lib/win/DirectX" "lib/win" )
2024-04-21 09:02:27 +00:00
set ( CMAKE_FIND_LIBRARY_PREFIXES "" )
set ( CMAKE_FIND_LIBRARY_SUFFIXES ".lib" )
2024-05-15 17:39:01 +00:00
add_compile_definitions ( DIRECTINPUT_VERSION=0x0500 )
find_library ( DSOUND_LIBRARY NAMES dsound REQUIRED )
find_library ( DINPUT_LIBRARY NAMES dinput REQUIRED )
find_library ( DXGUID_LIBRARY NAMES dxguid REQUIRED )
find_library ( DDRAW_LIBRARY NAMES ddraw REQUIRED )
2024-04-21 09:02:27 +00:00
if ( MSVC AND CMAKE_CXX_SIMULATE_ID STREQUAL "" )
add_compile_options ( "/we4150" ) # deletion of pointer to incomplete type 'type'; no destructor called
# add_compile_options("/we4305") # truncation from 'X' to 'Y'
add_compile_options ( "/we4474" ) # too many arguments passed for format string
add_compile_options ( "/we4700" ) # uninitialized local variable 'X' used
add_compile_options ( "/we4804" ) # unsafe use of type 'bool' in operation
add_compile_options ( "/we4806" ) # unsafe operation: no value of type 'bool' promoted to type 'int' can equal the given constant
add_compile_options ( "/we4473" ) # not enough arguments passed for format string
add_compile_options ( "/we4477" ) # format string requires argument of type X but variadic argument Y has type Z
add_compile_options ( "/we4715" ) # 'function' : not all control paths return a value
add_compile_options ( "/we4834" ) # discarding return value of function with [[nodiscard]] attribute
endif ( )
2024-04-28 23:11:45 +00:00
add_compile_options ( "/MP" ) # so msbuild builds with multiple processes
2024-04-21 09:02:27 +00:00
endif ( )
2024-04-21 12:11:45 +00:00
add_compile_definitions ( $< $<CONFIG:Release > :RELEASE> )
2024-04-21 13:14:31 +00:00
add_compile_definitions ( $< $<CONFIG:Debug > :_DEBUG> )
2024-04-21 12:11:45 +00:00
2024-04-21 18:49:16 +00:00
find_package ( ZLIB REQUIRED )
2024-04-29 19:52:42 +00:00
if ( ENABLE_LOGGER )
2024-04-23 17:53:00 +00:00
message ( "Enabling Logging" )
2024-04-28 11:24:10 +00:00
add_compile_definitions ( LOGGER )
2024-04-23 17:53:00 +00:00
endif ( )
2024-08-14 14:34:13 +00:00
if ( FATAL_GL_ERRORS )
message ( "Raising exceptions on OpenGL errors" )
add_compile_definitions ( FATAL_GL_ERRORS )
endif ( )
2024-04-21 20:54:02 +00:00
include_directories (
" c f i l e " # TODO: Remove after untying all modules
2024-04-27 16:22:29 +00:00
" d d e b u g " # -*-
2024-04-26 21:01:23 +00:00
" f i x " # -*-
2024-04-21 20:54:02 +00:00
" l i b " # TODO: Remove after untying all modules
2024-05-18 23:48:26 +00:00
" l i n u x " # -*-
2024-04-21 20:54:02 +00:00
" D e s c e n t 3 "
$ { P L A T F O R M _ I N C L U D E S }
)
2024-04-21 09:02:27 +00:00
2024-05-09 21:38:54 +00:00
add_subdirectory ( third_party )
2024-04-21 09:02:27 +00:00
add_subdirectory ( 2dlib )
add_subdirectory ( AudioEncode )
add_subdirectory ( bitmap )
add_subdirectory ( cfile )
2024-04-27 16:22:29 +00:00
add_subdirectory ( ddebug )
2024-06-21 16:46:53 +00:00
add_subdirectory ( linux )
2024-05-22 21:59:23 +00:00
add_subdirectory ( ddio )
2024-04-21 09:02:27 +00:00
add_subdirectory ( fix )
2024-09-10 09:40:19 +00:00
add_subdirectory ( logger )
2024-04-21 09:02:27 +00:00
add_subdirectory ( manage )
add_subdirectory ( grtext )
add_subdirectory ( mem )
add_subdirectory ( misc )
add_subdirectory ( model )
add_subdirectory ( module )
add_subdirectory ( music )
add_subdirectory ( networking )
add_subdirectory ( physics )
add_subdirectory ( renderer )
add_subdirectory ( rtperformance )
add_subdirectory ( sndlib )
add_subdirectory ( stream_audio )
add_subdirectory ( ui )
add_subdirectory ( unzip )
add_subdirectory ( vecmat )
add_subdirectory ( libmve )
add_subdirectory ( md5 )
2024-05-23 06:06:24 +00:00
if ( BUILD_EDITOR AND CMAKE_SYSTEM_NAME STREQUAL "Windows" )
2024-10-12 16:32:27 +00:00
add_subdirectory ( dd_grwin32 )
add_subdirectory ( win32 )
2024-05-20 19:12:07 +00:00
add_subdirectory ( editor )
endif ( )
2024-05-23 06:06:24 +00:00
2024-04-21 09:02:27 +00:00
add_subdirectory ( Descent3 )
2024-10-27 19:16:17 +00:00
if ( CMAKE_CROSSCOMPILING )
find_package ( HogMaker REQUIRED )
else ( )
add_subdirectory ( tools )
endif ( )
2024-05-06 18:43:19 +00:00
add_subdirectory ( netcon )
2024-05-15 18:00:39 +00:00
add_subdirectory ( netgames )
add_subdirectory ( scripts )
2024-08-12 14:07:44 +00:00
# Packaging stuff
set ( CPACK_SOURCE_GENERATOR "TXZ" )
set ( CPACK_SOURCE_IGNORE_FILES
" . g i t / "
" . g i t h u b / "
" . i d e a "
b u i l d [ s ] /
c m a k e - b u i l d - *
" . * ~ $ "
)
set ( CPACK_VERBATIM_VARIABLES YES )
include ( CPack )