2023-01-02 13:17:18 -06:00
cmake_minimum_required(VERSION 3.1)
2024-09-07 00:00:15 -04:00
if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
2023-01-02 13:17:18 -06:00
message(FATAL_ERROR
"In-source builds not allowed.
Please make a new directory (called a build directory) and run CMake from there.
You may need to remove CMakeCache.txt."
)
2024-09-07 00:00:15 -04:00
endif ()
2023-01-02 13:17:18 -06:00
# OS variables
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.14" CACHE STRING "macOS Deployment Target" FORCE)
# Project
project(whoa)
2024-09-07 00:00:15 -04:00
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
2023-01-02 13:17:18 -06:00
set(CMAKE_INSTALL_PREFIX "dist" CACHE PATH "Installation prefix" FORCE)
2024-09-07 00:00:15 -04:00
endif ()
2023-01-02 13:17:18 -06:00
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)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_BUILD_TYPE Debug)
2023-01-03 00:45:25 -06:00
include(lib/system/cmake/system.cmake)
2024-07-21 20:04:32 -04:00
# Build options
# UBsan
2024-09-07 00:00:15 -04:00
set(WHOA_UB_SAN_HELP_TEXT "Disable/Enable the Undefined Behavior Sanitizer. This is turned on by default in Debug build types. Has no effect when using MSVC.")
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
2024-07-21 20:06:00 -04:00
option(WHOA_UB_SAN WHOA_UB_SAN_HELP_TEXT 1)
2024-09-07 00:00:15 -04:00
else ()
2024-07-21 20:06:00 -04:00
option(WHOA_UB_SAN WHOA_UB_SAN_HELP_TEXT 0)
2024-09-07 00:00:15 -04:00
endif ()
2024-07-21 20:04:32 -04:00
unset(WHOA_UB_SAN_HELP_TEXT)
# GLSDL
2024-09-07 00:00:15 -04:00
if (WHOA_SYSTEM_WINDOWS)
2024-07-21 20:04:32 -04:00
# GLSDL can be disabled on Windows to save time
2024-09-07 00:00:15 -04:00
option(WHOA_BUILD_GLSDL "Disable/Enable compilation of the OpenGL/SDL2 graphics rendering device on Windows." 0)
elseif (WHOA_SYSTEM_MAC)
2024-07-21 20:04:32 -04:00
# No need for this, we already have a functioning OpenGL rendering device (CGxDeviceGLL)
set(WHOA_BUILD_GLSDL 0)
2024-09-07 00:00:15 -04:00
else ()
2024-07-21 20:04:32 -04:00
# Right now GLSDL is the only rendering device for Linux
set(WHOA_BUILD_GLSDL 1)
2024-09-07 00:00:15 -04:00
endif ()
2024-07-22 00:43:39 -04:00
if (WHOA_BUILD_GLSDL)
add_definitions(-DWHOA_BUILD_GLSDL)
2024-09-07 00:00:15 -04:00
endif ()
2024-07-21 20:04:32 -04:00
# FMOD
2024-07-21 20:06:00 -04:00
option(WHOA_BUILD_FMOD "Disable/Enable the use of the FMOD sound API. This introduces a dependency on a proprietary FMOD dynamically linked library." 0)
2024-07-21 20:04:32 -04:00
2024-07-21 17:12:14 -04:00
# Compiler options
2024-09-07 00:00:15 -04:00
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
2024-07-21 17:12:14 -04:00
# Some templates abuse offsetof
2023-01-03 00:45:25 -06:00
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-offsetof")
2024-07-21 17:12:14 -04:00
2024-09-07 00:00:15 -04:00
if (CMAKE_BUILD_TYPE STREQUAL "Debug" AND WHOA_UB_SAN)
2024-07-21 17:12:14 -04:00
# Enable UBsan
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
# Allow strange alignments
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-sanitize=alignment")
2024-07-22 02:05:52 -04:00
# Make encountering UB an unrecoverable error
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-sanitize-recover=all")
2024-09-07 00:00:15 -04:00
else ()
2024-07-21 17:12:14 -04:00
# Disable UBsan completely
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-sanitize=undefined")
2024-09-07 00:00:15 -04:00
endif ()
endif ()
2023-01-02 13:17:18 -06:00
# OS defines
2024-09-07 00:00:15 -04:00
if (WHOA_SYSTEM_WIN)
2023-01-03 00:45:25 -06:00
# Avoid win32 header hell
add_compile_definitions(
NOMINMAX
WIN32_LEAN_AND_MEAN
)
2023-03-12 23:49:48 -05:00
# Make DirectXMath boring
add_definitions(
-D_XM_NO_INTRINSICS_
)
2023-01-03 00:45:25 -06:00
# Lua uses various "unsafe" C functions
2023-01-02 13:17:18 -06:00
add_definitions(
2023-01-03 00:45:25 -06:00
-D_CRT_SECURE_NO_WARNINGS
2023-01-02 13:17:18 -06:00
)
2024-09-07 00:00:15 -04:00
endif ()
2023-01-02 13:17:18 -06:00
2024-09-07 00:00:15 -04:00
if (WHOA_SYSTEM_MAC)
2023-01-03 00:45:25 -06:00
# Suppress OpenGL deprecation warnings
add_definitions(
-DGL_SILENCE_DEPRECATION
)
2024-09-07 00:00:15 -04:00
endif ()
2023-01-02 13:17:18 -06:00
# Threads
2024-09-07 00:00:15 -04:00
if (WHOA_SYSTEM_LINUX OR WHOA_SYSTEM_MAC)
2023-01-02 13:17:18 -06:00
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package(Threads REQUIRED)
2024-09-07 00:00:15 -04:00
endif ()
2023-01-02 13:17:18 -06:00
2023-10-22 22:52:05 -05:00
# Library search paths
2024-09-07 00:00:15 -04:00
if (WHOA_SYSTEM_MAC)
2023-10-22 22:52:05 -05:00
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH "@executable_path")
2024-09-07 00:00:15 -04:00
elseif (WHOA_SYSTEM_LINUX)
2023-10-22 22:52:05 -05:00
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH "$ORIGIN")
2024-09-07 00:00:15 -04:00
endif ()
2023-10-22 22:52:05 -05:00
2023-01-02 13:17:18 -06:00
add_subdirectory(lib)
add_subdirectory(src)
add_subdirectory(test)
add_subdirectory(vendor)