2020-08-23 02:30:12 +00:00
|
|
|
# Top Level CMakeLists.txt
|
2021-02-04 02:29:46 +00:00
|
|
|
cmake_minimum_required(VERSION 3.10)
|
2020-12-26 16:09:59 +00:00
|
|
|
|
2024-02-17 19:14:23 +00:00
|
|
|
set(CMAKE_CXX_STANDARD 20)
|
2020-08-23 02:30:12 +00:00
|
|
|
project(jak)
|
2021-02-04 02:29:46 +00:00
|
|
|
include(CTest)
|
2022-02-08 00:15:37 +00:00
|
|
|
|
2022-07-03 21:35:39 +00:00
|
|
|
# Include third-party modules
|
|
|
|
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/third-party/cmake/modules/)
|
|
|
|
|
|
|
|
# Default to Release mode
|
2020-10-03 13:39:04 +00:00
|
|
|
if(NOT CMAKE_BUILD_TYPE)
|
2022-02-08 00:15:37 +00:00
|
|
|
set(CMAKE_BUILD_TYPE "Release")
|
2020-10-03 13:39:04 +00:00
|
|
|
endif()
|
2020-08-23 02:30:12 +00:00
|
|
|
|
2022-07-03 21:35:39 +00:00
|
|
|
# Potentially statically build the project
|
|
|
|
option(STATICALLY_LINK "Build for release purposes (statically link everything)" OFF)
|
2022-07-04 00:26:04 +00:00
|
|
|
message(STATUS "Statically Link? ${STATICALLY_LINK}")
|
2022-07-03 21:35:39 +00:00
|
|
|
if(STATICALLY_LINK)
|
2022-03-30 02:47:08 +00:00
|
|
|
set(BUILD_SHARED_LIBS OFF)
|
2023-11-02 23:57:34 +00:00
|
|
|
set(BUILD_STATIC_LIBS ON)
|
2022-03-30 02:47:08 +00:00
|
|
|
else()
|
|
|
|
set(BUILD_SHARED_LIBS ON)
|
2023-11-02 23:57:34 +00:00
|
|
|
set(BUILD_STATIC_LIBS OFF)
|
2022-03-30 02:47:08 +00:00
|
|
|
endif()
|
|
|
|
|
2023-07-16 15:13:48 +00:00
|
|
|
# For clangd
|
|
|
|
if (EXISTS "${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json" )
|
|
|
|
configure_file(
|
2023-10-12 00:43:55 +00:00
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json"
|
2023-07-16 15:13:48 +00:00
|
|
|
"${PROJECT_SOURCE_DIR}/build/compile_commands.json")
|
|
|
|
endif()
|
|
|
|
|
2022-07-03 21:35:39 +00:00
|
|
|
# Setup compiler flags
|
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
|
|
|
message(STATUS "Clang Detected - Setting Defaults")
|
2022-02-08 00:15:37 +00:00
|
|
|
set(CMAKE_CXX_FLAGS
|
2022-04-15 22:32:37 +00:00
|
|
|
"${CMAKE_CXX_FLAGS} \
|
2022-07-03 21:35:39 +00:00
|
|
|
-fcxx-exceptions \
|
|
|
|
-fexceptions \
|
|
|
|
-fdiagnostics-color=always \
|
|
|
|
-mavx \
|
|
|
|
-Wall \
|
|
|
|
-Wno-c++11-narrowing \
|
|
|
|
-Wno-c++98-compat \
|
2023-03-30 21:49:07 +00:00
|
|
|
-O3 \
|
|
|
|
-D_CRT_SECURE_NO_WARNINGS")
|
2022-07-03 21:35:39 +00:00
|
|
|
|
|
|
|
# Increase stack size for windows, who's default is too low
|
|
|
|
if(WIN32)
|
|
|
|
# Increase the reserved stack size for all threads to 16MB
|
|
|
|
# Note: this is only _reserved_ memory, not necessarily _committed_ memory
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LDFLAGS} -Xlinker /STACK:16000000")
|
2022-08-05 16:25:35 +00:00
|
|
|
else()
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb -g -Wextra")
|
2022-07-03 21:35:39 +00:00
|
|
|
endif()
|
2022-04-15 22:32:37 +00:00
|
|
|
|
|
|
|
# additional c++ and linker flags for release mode for our projects
|
2022-07-03 21:35:39 +00:00
|
|
|
if(CMAKE_BUILD_TYPE MATCHES "Release" OR CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo")
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LDFLAGS} -Xlinker /debug")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Fuzzing
|
|
|
|
if(NOT STATICALLY_LINK AND ASAN_BUILD)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -O1")
|
|
|
|
message(STATUS "Doing ASAN build")
|
2022-02-08 00:15:37 +00:00
|
|
|
endif()
|
|
|
|
|
2022-07-03 21:35:39 +00:00
|
|
|
# Warnings
|
|
|
|
set(THIRDPARTY_IGNORED_WARNINGS "-Wno-everything")
|
|
|
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
|
|
|
message(STATUS "GCC detected - Setting Defaults")
|
2020-09-06 20:58:25 +00:00
|
|
|
set(CMAKE_CXX_FLAGS
|
2020-09-14 01:10:43 +00:00
|
|
|
"${CMAKE_CXX_FLAGS} \
|
2020-09-04 02:37:00 +00:00
|
|
|
-Wall \
|
2020-09-14 01:10:43 +00:00
|
|
|
-Winit-self \
|
|
|
|
-ggdb \
|
2020-09-04 02:37:00 +00:00
|
|
|
-Wextra \
|
2020-12-03 00:51:42 +00:00
|
|
|
-Wno-cast-align \
|
2020-09-04 02:37:00 +00:00
|
|
|
-Wcast-qual \
|
|
|
|
-Wdisabled-optimization \
|
2020-12-03 00:51:42 +00:00
|
|
|
-Wformat \
|
2022-08-05 16:25:35 +00:00
|
|
|
-Wextra \
|
2020-09-04 02:37:00 +00:00
|
|
|
-Woverloaded-virtual \
|
|
|
|
-Wredundant-decls \
|
2020-10-10 01:28:41 +00:00
|
|
|
-Wshadow \
|
2021-09-26 15:41:58 +00:00
|
|
|
-Wsign-promo \
|
2022-02-08 00:15:37 +00:00
|
|
|
-fdiagnostics-color=always \
|
2022-02-19 18:10:10 +00:00
|
|
|
-mavx")
|
2022-02-08 00:15:37 +00:00
|
|
|
|
|
|
|
# additional c++ flags for release mode for our projects
|
|
|
|
if(CMAKE_BUILD_TYPE MATCHES "Release")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
|
|
|
endif()
|
2022-07-03 21:35:39 +00:00
|
|
|
set(THIRDPARTY_IGNORED_WARNINGS "-w")
|
2022-12-22 22:12:05 +00:00
|
|
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
|
|
|
|
message(STATUS "AppleClang detected - Setting Defaults")
|
|
|
|
set(CMAKE_CXX_FLAGS
|
|
|
|
"${CMAKE_CXX_FLAGS} \
|
|
|
|
-Wall \
|
|
|
|
-Winit-self \
|
|
|
|
-ggdb \
|
|
|
|
-Wextra \
|
|
|
|
-Wno-cast-align \
|
|
|
|
-Wcast-qual \
|
|
|
|
-Wdisabled-optimization \
|
|
|
|
-Wformat \
|
|
|
|
-Wextra \
|
|
|
|
-Woverloaded-virtual \
|
|
|
|
-Wredundant-decls \
|
|
|
|
-Wshadow \
|
|
|
|
-Wsign-promo \
|
|
|
|
-fdiagnostics-color=always"
|
|
|
|
)
|
2024-05-02 02:00:56 +00:00
|
|
|
|
|
|
|
# pin to AVX for macOS, hopefully all macOS runners have atleast this architecture
|
|
|
|
# technically speaking, SSE4 is the cutoff for Apple Silicon so...only a matter of time!
|
|
|
|
if(NOT CMAKE_CXX_COMPILER_TARGET STREQUAL "arm64-apple-darwin")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx")
|
|
|
|
endif()
|
2022-12-22 22:12:05 +00:00
|
|
|
|
|
|
|
# additional c++ flags for release mode for our projects
|
|
|
|
if(CMAKE_BUILD_TYPE MATCHES "Release")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
|
|
|
endif()
|
|
|
|
set(THIRDPARTY_IGNORED_WARNINGS "-w")
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-stack_size -Wl,0x20000000")
|
2022-07-03 21:35:39 +00:00
|
|
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
|
|
|
message(STATUS "MSVC detected - Setting Defaults")
|
2022-02-08 00:15:37 +00:00
|
|
|
|
2022-04-15 22:32:37 +00:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /utf-8 /arch:AVX")
|
2022-04-05 00:50:08 +00:00
|
|
|
|
2022-07-03 21:35:39 +00:00
|
|
|
# Increase stack size for windows, who's default is too low
|
|
|
|
# Increase the reserved stack size for all threads to 16MB
|
2022-04-15 22:32:37 +00:00
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:16000000,16384")
|
2022-07-03 21:35:39 +00:00
|
|
|
|
2022-04-15 22:32:37 +00:00
|
|
|
# additional c++ and linker flags for specific build types
|
2022-07-03 21:35:39 +00:00
|
|
|
if(CMAKE_BUILD_TYPE MATCHES "Release" OR CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo")
|
2022-04-15 22:32:37 +00:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /Ob2")
|
2022-07-03 21:35:39 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo")
|
2022-04-15 22:32:37 +00:00
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DEBUG")
|
|
|
|
endif()
|
2022-07-03 21:35:39 +00:00
|
|
|
set(THIRDPARTY_IGNORED_WARNINGS "/w")
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Unknown Compiler '${CMAKE_CXX_COMPILER_ID}', get out!")
|
2022-02-08 00:15:37 +00:00
|
|
|
endif()
|
2020-08-23 02:30:12 +00:00
|
|
|
|
2022-07-03 21:35:39 +00:00
|
|
|
# Platform Specific Settings
|
2021-02-04 02:29:46 +00:00
|
|
|
if(WIN32)
|
2020-09-06 20:58:25 +00:00
|
|
|
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
|
|
|
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
|
|
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
2021-02-04 02:29:46 +00:00
|
|
|
endif()
|
2020-08-27 02:23:16 +00:00
|
|
|
|
2022-07-03 21:35:39 +00:00
|
|
|
# Code Coverage
|
2020-09-08 23:15:38 +00:00
|
|
|
option(CODE_COVERAGE "Enable Code Coverage Compiler Flags" OFF)
|
2020-09-08 18:39:16 +00:00
|
|
|
|
2022-07-03 21:35:39 +00:00
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CODE_COVERAGE)
|
|
|
|
include(CodeCoverage)
|
|
|
|
append_coverage_compiler_flags()
|
|
|
|
message(STATUS "Code Coverage build is enabled!")
|
2020-09-08 20:19:05 +00:00
|
|
|
endif()
|
2020-08-27 02:23:16 +00:00
|
|
|
|
2023-08-09 00:53:16 +00:00
|
|
|
function(build_third_party_lib dir_name target_name)
|
|
|
|
add_subdirectory(third-party/${dir_name} EXCLUDE_FROM_ALL)
|
|
|
|
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
|
|
|
# For Microsoft Visual C++ Compiler (MSVC)
|
|
|
|
target_compile_options(${target_name} PRIVATE /w)
|
|
|
|
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
|
|
|
|
# For GNU Compiler Collection (GCC) or Clang
|
|
|
|
target_compile_options(${target_name} PRIVATE -w)
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
|
2022-07-03 21:35:39 +00:00
|
|
|
# Dependencies and Libraries
|
2020-08-23 02:30:12 +00:00
|
|
|
# includes relative to top level jak-project folder
|
|
|
|
include_directories(./)
|
|
|
|
|
2022-07-03 21:35:39 +00:00
|
|
|
# build templating engine library
|
2020-10-10 01:28:41 +00:00
|
|
|
include_directories(SYSTEM third-party/inja)
|
|
|
|
|
2023-10-12 00:43:55 +00:00
|
|
|
# libcurl for HTTP requests
|
|
|
|
# Enable SSL Support, most URLs now-a-days use SSL!
|
2023-11-02 23:57:34 +00:00
|
|
|
# TODO - probably integrate with ZSTD since we have it already
|
|
|
|
set(CURL_USE_LIBSSH2 OFF)
|
|
|
|
set(CURL_ZLIB OFF)
|
2023-10-12 00:43:55 +00:00
|
|
|
if(WIN32)
|
|
|
|
set(CURL_USE_SCHANNEL ON) # native Windows SSL support
|
|
|
|
elseif(APPLE)
|
|
|
|
set(CURL_USE_SECTRANSP ON) # native macOS SSL support
|
|
|
|
else()
|
2023-11-05 21:30:25 +00:00
|
|
|
if(STATICALLY_LINK)
|
|
|
|
set(OPENSSL_USE_STATIC_LIBS TRUE)
|
|
|
|
endif()
|
2023-10-12 00:43:55 +00:00
|
|
|
set(CURL_USE_OPENSSL ON) # not native, but seems to be the best choice for linux
|
|
|
|
endif()
|
|
|
|
include_directories(third-party/curl/include)
|
|
|
|
if(STATICALLY_LINK)
|
|
|
|
build_third_party_lib(curl libcurl_static)
|
|
|
|
else()
|
|
|
|
build_third_party_lib(curl libcurl_shared)
|
|
|
|
endif()
|
|
|
|
|
2021-03-08 04:41:21 +00:00
|
|
|
# build repl library
|
2023-08-09 00:53:16 +00:00
|
|
|
build_third_party_lib(replxx replxx)
|
2022-11-20 04:28:20 +00:00
|
|
|
|
|
|
|
# SQLite - Jak 2/3's built in editor
|
|
|
|
add_definitions(-DHAVE_USLEEP=1)
|
|
|
|
add_definitions(-DSQLITE_THREADSAFE=1)
|
2023-06-25 20:51:46 +00:00
|
|
|
add_definitions(-DSQLITE_ENABLE_JSON1)
|
2022-11-20 04:28:20 +00:00
|
|
|
add_definitions(-DSQLITE_ENABLE_RTREE)
|
2023-08-09 00:53:16 +00:00
|
|
|
build_third_party_lib(sqlite3 sqlite3)
|
2021-03-08 04:41:21 +00:00
|
|
|
|
2023-04-25 03:46:55 +00:00
|
|
|
# build tree-sitter parser
|
|
|
|
include_directories(third-party/tree-sitter/tree-sitter/lib/include)
|
2023-08-09 00:53:16 +00:00
|
|
|
build_third_party_lib(tree-sitter tree-sitter)
|
2023-04-25 03:46:55 +00:00
|
|
|
|
2023-07-01 01:05:58 +00:00
|
|
|
# native OS dialogs for error messages
|
2023-08-09 00:53:16 +00:00
|
|
|
build_third_party_lib(libtinyfiledialogs libtinyfiledialogs)
|
2023-06-25 20:51:46 +00:00
|
|
|
|
2024-03-06 03:11:52 +00:00
|
|
|
# build format library
|
|
|
|
include_directories(third-party/fmt/include)
|
|
|
|
build_third_party_lib(fmt fmt)
|
|
|
|
|
2021-01-06 17:16:39 +00:00
|
|
|
# build common library
|
|
|
|
add_subdirectory(common)
|
2020-10-31 18:07:43 +00:00
|
|
|
|
2020-08-23 02:30:12 +00:00
|
|
|
# build decompiler
|
|
|
|
add_subdirectory(decompiler)
|
|
|
|
|
2023-08-09 00:53:16 +00:00
|
|
|
# cubeb - audio
|
|
|
|
build_third_party_lib(cubeb cubeb)
|
2022-05-19 20:54:36 +00:00
|
|
|
|
2022-07-18 22:26:57 +00:00
|
|
|
# build LSP
|
|
|
|
add_subdirectory(lsp)
|
|
|
|
|
2023-08-09 00:53:16 +00:00
|
|
|
# build libco and zstd
|
|
|
|
build_third_party_lib(libco libco)
|
|
|
|
build_third_party_lib(zstd libzstd_static)
|
2021-09-22 02:52:18 +00:00
|
|
|
|
2023-06-04 19:34:37 +00:00
|
|
|
# build SDL
|
|
|
|
include(SDLOptions)
|
2023-08-09 02:00:26 +00:00
|
|
|
if(STATICALLY_LINK)
|
|
|
|
build_third_party_lib(SDL SDL2-static)
|
|
|
|
else()
|
|
|
|
build_third_party_lib(SDL SDL2)
|
|
|
|
endif()
|
2023-06-04 19:34:37 +00:00
|
|
|
|
2021-08-29 18:54:16 +00:00
|
|
|
# build imgui
|
2021-03-10 04:51:28 +00:00
|
|
|
include_directories(third-party/glad/include)
|
2023-06-04 19:34:37 +00:00
|
|
|
include_directories(third-party/SDL/include)
|
2023-08-09 00:53:16 +00:00
|
|
|
build_third_party_lib(imgui imgui)
|
2021-08-29 18:54:16 +00:00
|
|
|
|
|
|
|
# build the game code in C++
|
2020-08-23 02:30:12 +00:00
|
|
|
add_subdirectory(game)
|
|
|
|
|
|
|
|
# build the compiler
|
|
|
|
add_subdirectory(goalc)
|
|
|
|
|
2021-01-28 01:46:58 +00:00
|
|
|
# build standalone tools
|
|
|
|
add_subdirectory(tools)
|
|
|
|
|
2020-08-23 02:30:12 +00:00
|
|
|
# build the gtest libraries
|
2021-02-04 02:29:46 +00:00
|
|
|
if(WIN32)
|
2022-07-03 21:35:39 +00:00
|
|
|
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
2021-02-04 02:29:46 +00:00
|
|
|
endif()
|
2022-07-03 21:35:39 +00:00
|
|
|
|
2023-08-09 00:53:16 +00:00
|
|
|
build_third_party_lib(googletest gtest)
|
2021-02-04 02:29:46 +00:00
|
|
|
include(GoogleTest)
|
2020-08-23 02:30:12 +00:00
|
|
|
|
|
|
|
# build tests
|
2021-02-04 02:29:46 +00:00
|
|
|
include(test/CMakeLists.txt)
|
2020-08-23 03:16:48 +00:00
|
|
|
|
2021-02-06 14:54:23 +00:00
|
|
|
# build lzokay library
|
2023-08-09 00:53:16 +00:00
|
|
|
build_third_party_lib(lzokay lzokay)
|
2020-08-24 03:43:11 +00:00
|
|
|
|
2023-08-09 00:53:16 +00:00
|
|
|
build_third_party_lib(stb_image stb_image)
|
|
|
|
build_third_party_lib(tiny_gltf tiny_gltf)
|
|
|
|
build_third_party_lib(xdelta3 xdelta3)
|
2022-06-18 19:07:40 +00:00
|
|
|
|
2022-02-08 04:53:36 +00:00
|
|
|
# discord rich presence
|
|
|
|
include_directories(third-party/discord-rpc/include)
|
2023-08-09 00:53:16 +00:00
|
|
|
build_third_party_lib(discord-rpc discord-rpc)
|
2022-02-08 04:53:36 +00:00
|
|
|
|
2020-10-31 18:31:13 +00:00
|
|
|
# build zydis third party library for disassembling x86
|
2022-07-03 21:35:39 +00:00
|
|
|
# TODO - Once under CMake 3.13's policy CMP0077, override with `set()` instead
|
2021-02-04 02:29:46 +00:00
|
|
|
option(ZYDIS_BUILD_TOOLS "Zydis: Build tools" OFF)
|
|
|
|
option(ZYDIS_BUILD_EXAMPLES "Zydis: Build examples" OFF)
|
2022-07-03 21:35:39 +00:00
|
|
|
|
2022-07-04 00:26:04 +00:00
|
|
|
if(STATICALLY_LINK)
|
|
|
|
message(STATUS "Statically linking zydis")
|
2022-03-30 02:47:08 +00:00
|
|
|
option(ZYDIS_BUILD_SHARED_LIB "Zydis: Build shared library" OFF)
|
2022-07-04 00:26:04 +00:00
|
|
|
else()
|
|
|
|
message(STATUS "dynamically linking zydis")
|
|
|
|
option(ZYDIS_BUILD_SHARED_LIB "Zydis: Build shared library" ON)
|
2022-03-30 02:47:08 +00:00
|
|
|
endif()
|
2022-07-03 21:35:39 +00:00
|
|
|
|
2023-08-09 00:53:16 +00:00
|
|
|
build_third_party_lib(zydis Zydis)
|
2020-10-31 18:31:13 +00:00
|
|
|
|
2020-08-27 02:23:16 +00:00
|
|
|
# windows memory management lib
|
2021-02-04 02:29:46 +00:00
|
|
|
if(WIN32)
|
2023-08-09 00:53:16 +00:00
|
|
|
build_third_party_lib(mman mman)
|
2021-02-04 02:29:46 +00:00
|
|
|
endif()
|