228 lines
8.6 KiB
CMake
228 lines
8.6 KiB
CMake
cmake_minimum_required(VERSION 3.25.1)
|
|
project(powerplay)
|
|
|
|
# Options below are laid out so that running cmake with all "OFF" results in the "release" / "user" build
|
|
|
|
option(RTC "Should the build compile with runtime checks enabled (asserts, asan, etc.) - REQUIRES CRTLIB ON" OFF)
|
|
option(CRTLIB "Should the build link with the CRTLIB" OFF)
|
|
option(DEBINFO "Should the build compile with debug info" OFF)
|
|
option(DEVELOPER "Should the build compile with developer mode enabled" OFF)
|
|
option(PROFILING "Should the build compile with profiling enabled - REQUIRES CRTLIB ON" OFF)
|
|
option(UNOPTIMIZED "Should the build compile with optimization disabled" OFF)
|
|
|
|
################################################################################
|
|
# Source files
|
|
################################################################################
|
|
|
|
# Glob source files
|
|
file(GLOB_RECURSE sources CONFIGURE_DEPENDS src/*.c src/*.cpp src/*.h)
|
|
|
|
# Filter platform specific
|
|
list(FILTER sources EXCLUDE REGEX "sys_|renderer_|playback_|mp3_|ttf_")
|
|
if(PLATFORM_WIN32)
|
|
set(sources ${sources} src/sys_win32.c)
|
|
set(sources ${sources} src/renderer_d3d11.c)
|
|
set(sources ${sources} src/playback_wasapi.c)
|
|
set(sources ${sources} src/mp3_mmf.c)
|
|
set(sources ${sources} src/ttf_dwrite.cpp)
|
|
set(sources ${sources} .natvis)
|
|
endif()
|
|
|
|
# Add tracy
|
|
list(FILTER sources EXCLUDE REGEX "third_party")
|
|
if(PROFILING)
|
|
set(sources ${sources} src/third_party/tracy/TracyClient.cpp)
|
|
endif()
|
|
|
|
list(FILTER sources EXCLUDE REGEX "WIP")
|
|
|
|
################################################################################
|
|
# Resource embedding
|
|
################################################################################
|
|
|
|
set(inc_dependencies "")
|
|
|
|
# Only archive & embed "res" dir if not compiling a developer build
|
|
if(NOT DEVELOPER)
|
|
# Generate resource archive
|
|
set(resource_archive_path "${CMAKE_BINARY_DIR}/res.tar")
|
|
file(GLOB_RECURSE resource_sources CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/res/*)
|
|
add_custom_command(
|
|
OUTPUT ${resource_archive_path}
|
|
COMMAND cmake -E tar cvf ${resource_archive_path} .
|
|
DEPENDS ${resource_sources}
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/res
|
|
)
|
|
list(APPEND inc_dependencies ${resource_archive_path})
|
|
endif()
|
|
|
|
# Generate shaders archive
|
|
set(shaders_archive_path "${CMAKE_BINARY_DIR}/shaders.tar")
|
|
file(GLOB_RECURSE shader_sources CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/src/shaders/*)
|
|
add_custom_command(
|
|
OUTPUT ${shaders_archive_path}
|
|
COMMAND cmake -E tar cvf ${shaders_archive_path} .
|
|
DEPENDS ${shader_sources}
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src/shaders
|
|
)
|
|
list(APPEND inc_dependencies ${shaders_archive_path})
|
|
|
|
set_source_files_properties(src/inc.c OBJECT_DEPENDS "${inc_dependencies}")
|
|
|
|
################################################################################
|
|
# RC file (windows)
|
|
################################################################################
|
|
|
|
set(rc_res_sources "")
|
|
if(PLATFORM_WIN32)
|
|
set(RC_PATH "${CMAKE_BINARY_DIR}/rc.rc")
|
|
set(RC_RES_PATH "${CMAKE_BINARY_DIR}/rc.res")
|
|
|
|
# Add icon resource to .rc
|
|
set(ICON_SOURCE_PATH "${CMAKE_SOURCE_DIR}/icon.ico")
|
|
set(ICON_COPY_PATH "${CMAKE_BINARY_DIR}/icon.ico")
|
|
if(EXISTS ${ICON_SOURCE_PATH})
|
|
# Copy icon to output dir
|
|
add_custom_command(
|
|
OUTPUT ${ICON_COPY_PATH}
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${ICON_SOURCE_PATH} ${ICON_COPY_PATH}
|
|
DEPENDS ${ICON_SOURCE_PATH}
|
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
|
)
|
|
|
|
# Insert icon into .rc
|
|
add_custom_command(
|
|
OUTPUT ${RC_PATH}
|
|
COMMAND break > ${RC_PATH}
|
|
COMMAND echo IDI_ICON ICON DISCARDABLE icon.ico >> ${RC_PATH}
|
|
DEPENDS ${ICON_COPY_PATH}
|
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
|
)
|
|
|
|
# Compile rc.rc -> rc.res
|
|
add_custom_command(
|
|
OUTPUT ${RC_RES_PATH}
|
|
COMMAND llvm-rc ${RC_PATH}
|
|
DEPENDS ${ICON_COPY_PATH} ${RC_PATH}
|
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
|
)
|
|
add_custom_target(build_rc_res ALL DEPENDS ${RC_RES_PATH})
|
|
|
|
# Add to list of res_sources
|
|
set(rc_res_sources ${rc_res_sources} ${RC_RES_PATH})
|
|
endif()
|
|
endif()
|
|
|
|
################################################################################
|
|
# Executable
|
|
################################################################################
|
|
|
|
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)
|
|
|
|
# Add executable
|
|
add_executable(powerplay_exe ${sources})
|
|
set_target_properties(
|
|
powerplay_exe PROPERTIES
|
|
C_STANDARD 99
|
|
OUTPUT_NAME "PowerPlay.exe"
|
|
)
|
|
|
|
# Add precompiled header
|
|
target_precompile_headers(powerplay_exe PRIVATE src/common.h)
|
|
|
|
################################################################################
|
|
# Compiler flags
|
|
################################################################################
|
|
|
|
# TODO:
|
|
# Enable -
|
|
# -Wconversion \
|
|
# -Wno-sign-conversion \
|
|
|
|
# Common flags
|
|
set(COMPILER_FLAGS "
|
|
-fno-strict-aliasing \
|
|
-msse4.2 \
|
|
")
|
|
|
|
set(COMPILER_WARNINGS " \
|
|
-Weverything -Werror \
|
|
-Wno-unused-macros -Wno-gnu-zero-variadic-macro-arguments -Wno-documentation \
|
|
-Wno-old-style-cast -Wno-reserved-identifier -Wno-reserved-macro-identifier \
|
|
-Wno-conversion -Wno-sign-conversion -Wno-declaration-after-statement -Wno-extra-semi \
|
|
-Wno-extra-semi-stmt -Wno-bad-function-cast -Wno-class-varargs \
|
|
-Wno-unreachable-code-break -Wno-cast-align -Wno-float-equal \
|
|
-Wno-zero-as-null-pointer-constant -Wno-cast-qual -Wno-missing-noreturn \
|
|
-Wno-missing-field-initializers -Wno-missing-braces -Wno-initializer-overrides \
|
|
-Wno-c99-extensions -Wno-c++98-compat-pedantic -Wno-c++98-compat \
|
|
-Wno-switch-enum -Wno-unsafe-buffer-usage \
|
|
")
|
|
# -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-parameter
|
|
|
|
|
|
set(LINKER_FLAGS " \
|
|
-fuse-ld=lld-link \
|
|
${rc_res_sources} \
|
|
-luser32.lib -lkernel32.lib -lgdi32.lib -lshell32.lib -ldwmapi.lib -lole32.lib -ld3d11.lib -ld3dcompiler.lib -ldxgi.lib -ldxguid.lib -ldwrite.lib -lwinmm.lib -ladvapi32.lib -lmfplat.lib -lmfreadwrite.lib -lavrt.lib -lshlwapi.lib \
|
|
")
|
|
|
|
# RTC (Runtime checks)
|
|
if (RTC)
|
|
if (NOT CRTLIB)
|
|
message(FATAL_ERROR "CRTLIB (C runtime library) Must be enabled when compiling with RTC (runtime checks)")
|
|
endif()
|
|
# NOTE: Adress sanitizer is disable for now because for some reason it's hiding local variables in debug mode.
|
|
set(COMPILER_FLAGS "${COMPILER_FLAGS} -DRTC=1")
|
|
# set(COMPILER_FLAGS "${COMPILER_FLAGS} -fsanitize=undefined -fno-sanitize=alignment -DRTC=1")
|
|
# set(COMPILER_FLAGS "${COMPILER_FLAGS} -fsanitize=undefined -fsanitize-trap=undefined -fno-sanitize=alignment -DRTC=1")
|
|
# set(COMPILER_FLAGS "${COMPILER_FLAGS} -fsanitize=address -fsanitize=undefined -fno-sanitize=alignment -DRTC=1")
|
|
endif()
|
|
|
|
# CRTLIB (C runtime library)
|
|
if (CRTLIB)
|
|
set(COMPILER_FLAGS "${COMPILER_FLAGS} -DCRTLIB=1")
|
|
else()
|
|
set(COMPILER_FLAGS "${COMPILER_FLAGS} -mno-stack-arg-probe -fno-builtin")
|
|
set(LINKER_FLAGS "${LINKER_FLAGS} -nostdlib")
|
|
endif()
|
|
|
|
# Optimization
|
|
if (UNOPTIMIZED)
|
|
set(COMPILER_FLAGS "${COMPILER_FLAGS} -O0 -DUNOPTIMIZED=1")
|
|
set(LINKER_FLAGS "${LINKER_FLAGS} -O0 -DUNOPTIMIZED=1")
|
|
else()
|
|
set(COMPILER_FLAGS "${COMPILER_FLAGS} -O3 -flto")
|
|
set(LINKER_FLAGS "${LINKER_FLAGS} -O3 -flto -fwhole-program")
|
|
endif()
|
|
|
|
# Debug info
|
|
if (DEBINFO)
|
|
set(COMPILER_FLAGS "${COMPILER_FLAGS} -g -DDEBINFO=1")
|
|
endif()
|
|
|
|
# Developer mode
|
|
if(DEVELOPER)
|
|
set(COMPILER_FLAGS "${COMPILER_FLAGS} -DDEVELOPER=1")
|
|
endif()
|
|
|
|
# Profiling
|
|
if(PROFILING)
|
|
if (NOT CRTLIB)
|
|
message(FATAL_ERROR "CRTLIB (C runtime library) Must be enabled when compiling with PROFILING")
|
|
endif()
|
|
set(COMPILER_FLAGS "${COMPILER_FLAGS} -DPROFILING=1")
|
|
# Tracy flags
|
|
set(COMPILER_FLAGS "${COMPILER_FLAGS} -DTRACY_ENABLE=1")
|
|
set(COMPILER_FLAGS "${COMPILER_FLAGS} -DTRACY_NO_SAMPLING=1")
|
|
set(COMPILER_FLAGS "${COMPILER_FLAGS} -DTRACY_NO_SYSTEM_TRACING=1")
|
|
set(COMPILER_FLAGS "${COMPILER_FLAGS} -DTRACY_NO_CALLSTACK=1")
|
|
# Disable warnings when compiling tracy client
|
|
set(COMPILER_WARNINGS "-Wno-everything")
|
|
endif()
|
|
|
|
set(CMAKE_C_FLAGS "${COMPILER_FLAGS} ${COMPILER_WARNINGS} -std=c99")
|
|
set(CMAKE_CXX_FLAGS "${COMPILER_FLAGS} ${COMPILER_WARNINGS} -std=c++14")
|
|
set(CMAKE_EXE_LINKER_FLAGS "${LINKER_FLAGS}")
|