|
|
@ -1,79 +1,57 @@ |
|
|
|
# User config between these lines |
|
|
|
|
|
|
|
# ------------------------------------------ |
|
|
|
# ------------------------------------------ |
|
|
|
|
|
|
|
# User config between these lines |
|
|
|
|
|
|
|
|
|
|
|
# Set engine name |
|
|
|
# Set engine name |
|
|
|
set(ENGINE "inferno") |
|
|
|
set(ENGINE "inferno") |
|
|
|
# Set project name |
|
|
|
|
|
|
|
set(GAME "game") |
|
|
|
|
|
|
|
# Set debugging, ON/OFF |
|
|
|
|
|
|
|
set(DEBUG "ON") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ------------------------------------------ |
|
|
|
# Options |
|
|
|
|
|
|
|
option(BUILD_SHARED_LIBS "Build shared libraries" OFF) |
|
|
|
# Add 'make run' target |
|
|
|
option(INFERNO_BUILD_EXAMPLES "Build the Inferno example programs" OFF) |
|
|
|
add_custom_target(run |
|
|
|
|
|
|
|
COMMAND ${GAME} |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ------------------------------------------ |
|
|
|
# ------------------------------------------ |
|
|
|
|
|
|
|
|
|
|
|
cmake_minimum_required(VERSION 3.16) |
|
|
|
cmake_minimum_required(VERSION 3.16 FATAL_ERROR) |
|
|
|
|
|
|
|
project(${ENGINE} CXX C) |
|
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Check if the build should include debugging symbols |
|
|
|
# ------------------------------------------ |
|
|
|
option(DEBUG "" ${DEBUG}) |
|
|
|
# Setup C++ compiler |
|
|
|
if(DEBUG) |
|
|
|
|
|
|
|
# cmake -DDEBUG=on .. && make |
|
|
|
set(CMAKE_CXX_STANDARD 20) |
|
|
|
message("--- Debug ---") |
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON) |
|
|
|
set(CMAKE_BUILD_TYPE "Debug") |
|
|
|
set(CMAKE_CXX_EXTENSIONS OFF) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Compiler flags used for all build types |
|
|
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic") |
|
|
|
|
|
|
|
# -Wall = All warnings about contructions that are easily avoidable |
|
|
|
|
|
|
|
# -Wextra = Extra warning flags not covered by -Wall |
|
|
|
|
|
|
|
# -Wpedantic = Warnings for compiler extensions not part of the standard |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Set default build type if not specified |
|
|
|
|
|
|
|
set(DEFAULT_BUILD_TYPE Release) |
|
|
|
|
|
|
|
if(EXISTS ${CMAKE_SOURCE_DIR}/.git) |
|
|
|
|
|
|
|
set(DEFAULT_BUILD_TYPE Debug) |
|
|
|
|
|
|
|
endif() |
|
|
|
|
|
|
|
if(NOT CMAKE_BUILD_TYPE) |
|
|
|
|
|
|
|
set(CMAKE_BUILD_TYPE ${DEFAULT_BUILD_TYPE}) |
|
|
|
|
|
|
|
endif() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Set build type specific compiler flags |
|
|
|
|
|
|
|
message("--- ${CMAKE_BUILD_TYPE} ---") |
|
|
|
|
|
|
|
if(${CMAKE_BUILD_TYPE} STREQUAL Debug) |
|
|
|
|
|
|
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og -g -pg") |
|
|
|
# -Og = Optimizations that do not interfere with debugging |
|
|
|
# -Og = Optimizations that do not interfere with debugging |
|
|
|
# -Wall = All warnings about contructions that are easily avoidable |
|
|
|
|
|
|
|
# -Wextra = Extra warning flags not covered by -Wall |
|
|
|
|
|
|
|
# -g = Produce debugging information in OS's native format |
|
|
|
# -g = Produce debugging information in OS's native format |
|
|
|
# -pg = Generate profile information for analysis with gprof |
|
|
|
# -pg = Generate profile information for analysis with gprof |
|
|
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og -Wall -Wextra -g -pg") |
|
|
|
# $ gprof <PROJECT> gmon.out > profile-data.txt |
|
|
|
# gprof <GAME> gmon.out > profile-data.txt |
|
|
|
elseif(${CMAKE_BUILD_TYPE} STREQUAL Release) |
|
|
|
else() |
|
|
|
|
|
|
|
# cmake -DDEBUG=off .. && make |
|
|
|
|
|
|
|
message("--- Release ---") |
|
|
|
|
|
|
|
set(CMAKE_BUILD_TYPE "Release") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# -O3 = Optimizations that increases compilation time and performance |
|
|
|
|
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3") |
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3") |
|
|
|
|
|
|
|
# -O3 = Optimizations that increase compilation time and performance |
|
|
|
endif() |
|
|
|
endif() |
|
|
|
|
|
|
|
|
|
|
|
# Include all headers |
|
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
|
|
|
include_directories( |
|
|
|
|
|
|
|
"${ENGINE}/src" |
|
|
|
|
|
|
|
"${ENGINE}/vendor/entt/src" |
|
|
|
|
|
|
|
"${ENGINE}/vendor/glad/include" |
|
|
|
|
|
|
|
"${ENGINE}/vendor/glfw/include" |
|
|
|
|
|
|
|
"${ENGINE}/vendor/glm" |
|
|
|
|
|
|
|
"${ENGINE}/vendor/json/include" |
|
|
|
|
|
|
|
"${ENGINE}/vendor/lua" |
|
|
|
|
|
|
|
"${ENGINE}/vendor/sol2/include" |
|
|
|
|
|
|
|
"${ENGINE}/vendor/stb" |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Define engine source files |
|
|
|
|
|
|
|
file(GLOB_RECURSE GLAD "${ENGINE}/vendor/glad/*.c") |
|
|
|
|
|
|
|
file(GLOB LUA "${ENGINE}/vendor/lua/lua/*.c") |
|
|
|
|
|
|
|
list(REMOVE_ITEM LUA "${CMAKE_SOURCE_DIR}/${ENGINE}/vendor/lua/lua/onelua.c") # Do not compile single file variant |
|
|
|
|
|
|
|
list(REMOVE_ITEM LUA "${CMAKE_SOURCE_DIR}/${ENGINE}/vendor/lua/lua/ltests.c") # Do not compile internal debugging |
|
|
|
|
|
|
|
list(REMOVE_ITEM LUA "${CMAKE_SOURCE_DIR}/${ENGINE}/vendor/lua/lua/lua.c") # Do not compile interpreter |
|
|
|
|
|
|
|
file(GLOB_RECURSE ENGINE_SOURCES "${ENGINE}/src/${ENGINE}/*.cpp") |
|
|
|
|
|
|
|
set(ENGINE_SOURCES ${GLAD} ${LUA} ${ENGINE_SOURCES}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Define game source files |
|
|
|
|
|
|
|
file(GLOB_RECURSE GAME_SOURCES "${GAME}/src/*.cpp") |
|
|
|
|
|
|
|
set(GAME_SOURCES ${GAME_SOURCES}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ------------------------------------------ |
|
|
|
# ------------------------------------------ |
|
|
|
|
|
|
|
# Engine target |
|
|
|
project(${ENGINE}) |
|
|
|
|
|
|
|
set(CMAKE_CXX_STANDARD 17) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# GLFW options |
|
|
|
# GLFW options |
|
|
|
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) |
|
|
|
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) |
|
|
@ -83,16 +61,27 @@ set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) |
|
|
|
# Add GLFW target to project |
|
|
|
# Add GLFW target to project |
|
|
|
add_subdirectory(${ENGINE}/vendor/glfw) |
|
|
|
add_subdirectory(${ENGINE}/vendor/glfw) |
|
|
|
|
|
|
|
|
|
|
|
add_library(${ENGINE} STATIC ${ENGINE_SOURCES}) |
|
|
|
# Define engine source files |
|
|
|
target_link_libraries(${ENGINE} glfw) |
|
|
|
file(GLOB_RECURSE GLAD "${ENGINE}/vendor/glad/*.c") |
|
|
|
|
|
|
|
file(GLOB LUA "${ENGINE}/vendor/lua/lua/*.c") |
|
|
|
# ------------------------------------------ |
|
|
|
list(REMOVE_ITEM LUA "${CMAKE_SOURCE_DIR}/${ENGINE}/vendor/lua/lua/onelua.c") # Do not compile single file variant |
|
|
|
|
|
|
|
list(REMOVE_ITEM LUA "${CMAKE_SOURCE_DIR}/${ENGINE}/vendor/lua/lua/ltests.c") # Do not compile internal debugging |
|
|
|
project(${GAME}) |
|
|
|
list(REMOVE_ITEM LUA "${CMAKE_SOURCE_DIR}/${ENGINE}/vendor/lua/lua/lua.c") # Do not compile interpreter |
|
|
|
set(CMAKE_CXX_STANDARD 17) |
|
|
|
file(GLOB_RECURSE ENGINE_SOURCES "${ENGINE}/src/${ENGINE}/*.cpp") |
|
|
|
|
|
|
|
set(ENGINE_SOURCES ${GLAD} ${LUA} ${ENGINE_SOURCES}) |
|
|
|
|
|
|
|
|
|
|
|
add_executable(${GAME} ${GAME_SOURCES}) |
|
|
|
add_library(${ENGINE} ${ENGINE_SOURCES}) |
|
|
|
target_link_libraries(${GAME} ${ENGINE}) |
|
|
|
target_include_directories(${ENGINE} PRIVATE |
|
|
|
|
|
|
|
"${ENGINE}/src" |
|
|
|
|
|
|
|
"${ENGINE}/vendor/entt/src" |
|
|
|
|
|
|
|
"${ENGINE}/vendor/glad/include" |
|
|
|
|
|
|
|
"${ENGINE}/vendor/glfw/include" |
|
|
|
|
|
|
|
"${ENGINE}/vendor/glm" |
|
|
|
|
|
|
|
"${ENGINE}/vendor/json/include" |
|
|
|
|
|
|
|
"${ENGINE}/vendor/lua" |
|
|
|
|
|
|
|
"${ENGINE}/vendor/sol2/include" |
|
|
|
|
|
|
|
"${ENGINE}/vendor/stb") |
|
|
|
|
|
|
|
target_link_libraries(${ENGINE} glfw) |
|
|
|
|
|
|
|
|
|
|
|
# ------------------------------------------ |
|
|
|
# ------------------------------------------ |
|
|
|
|
|
|
|
|
|
|
@ -114,4 +103,10 @@ target_precompile_headers(${ENGINE} PRIVATE |
|
|
|
"$<$<COMPILE_LANGUAGE:CXX>:<vector$<ANGLE-R>>" |
|
|
|
"$<$<COMPILE_LANGUAGE:CXX>:<vector$<ANGLE-R>>" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
target_precompile_headers(${GAME} REUSE_FROM ${ENGINE}) |
|
|
|
# ------------------------------------------ |
|
|
|
|
|
|
|
# Examples target |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (INFERNO_BUILD_EXAMPLES) |
|
|
|
|
|
|
|
# Add examples target to project |
|
|
|
|
|
|
|
add_subdirectory("${CMAKE_SOURCE_DIR}/example") |
|
|
|
|
|
|
|
endif() |
|
|
|