KekEngine/CMakeLists.txt
2023-10-18 18:39:04 +02:00

147 lines
5.3 KiB
CMake

cmake_minimum_required(VERSION 3.13)
project(KekEngine VERSION 1.0)
option(KEKENGINE_DEBUG "Build with debug information" OFF)
option(KEKENGINE_VR "Include VR support" OFF)
option(KEKENGINE_BUILD_KEKGAME "Build kekgame" OFF)
option(KEKENGINE_DISABLE_ERRORDIALOG "Disable error dialogs" OFF)
if(UNIX)
set(KEKENGINE_TARGET_PLATFORM Linux)
endif()
if(WIN32)
set(KEKENGINE_TARGET_PLATFORM Windows)
#set(BUILD_SHARED_LIBS OFF)
endif()
message("Debug: ${KEKENGINE_DEBUG}")
message("Build kekgame: ${KEKENGINE_BUILD_KEKGAME}")
message("Build with VR support: ${KEKENGINE_VR}")
message("Target platform: ${KEKENGINE_TARGET_PLATFORM}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set(KEKENGINE_RESOURCE_DIR "${PROJECT_SOURCE_DIR}/src/kekengine/res")
set(KEKGAME_RESOURCE_DIR "${PROJECT_SOURCE_DIR}/src/kekgame/res")
file(GLOB_RECURSE KEKENGINE_SOURCE_FILES "${PROJECT_SOURCE_DIR}/src/kekengine/cpp/*.cpp")
file(GLOB_RECURSE KEKENGINE_RESOURCE_FILES "${KEKENGINE_RESOURCE_DIR}/*")
file(GLOB_RECURSE KEKENGINE_RELATIVE_RESOURCE_FILES RELATIVE ${KEKENGINE_RESOURCE_DIR} "${KEKENGINE_RESOURCE_DIR}/*")
file(GLOB_RECURSE KEKGAME_SOURCE_FILES "${PROJECT_SOURCE_DIR}/src/kekgame/cpp/*.cpp")
file(GLOB_RECURSE KEKGAME_RESOURCE_FILES "${KEKGAME_RESOURCE_DIR}/*")
file(GLOB_RECURSE KEKGAME_RELATIVE_RESOURCE_FILES RELATIVE ${KEKGAME_RESOURCE_DIR} "${KEKGAME_RESOURCE_DIR}/*")
add_compile_definitions(FT_CONFIG_OPTION_ERROR_STRINGS) # Freetype error strings
if(${KEKENGINE_DEBUG})
add_compile_options(-Wall -g)
else()
add_compile_options(-Wall -O3)
endif()
set(CMAKE_CXX_STANDARD 20)
block()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
add_subdirectory(dependencies/microtar)
add_subdirectory(dependencies/bullet3 EXCLUDE_FROM_ALL)
add_subdirectory(dependencies/freetype)
endblock()
# kekengine resources
add_custom_target(kekengine_res ALL DEPENDS ${KEKENGINE_RESOURCE_FILES})
add_custom_command(TARGET kekengine_res PRE_BUILD
BYPRODUCTS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/resources.tar
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
COMMAND ${CMAKE_COMMAND} -E
chdir ${KEKENGINE_RESOURCE_DIR}
tar cf ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/resources.tar ${KEKENGINE_RELATIVE_RESOURCE_FILES})
# libkekengine
add_library(kekengine OBJECT ${KEKENGINE_SOURCE_FILES})
set_property(TARGET kekengine PROPERTY POSITION_INDEPENDENT_CODE 1)
add_dependencies(kekengine kekengine_res)
target_include_directories(kekengine PUBLIC "src/kekengine/include")
target_include_directories(kekengine PUBLIC "dependencies/bullet3/src")
target_include_directories(kekengine PUBLIC "dependencies/freetype/include")
target_include_directories(kekengine PUBLIC "dependencies/stb")
target_include_directories(kekengine PUBLIC "dependencies/glm")
target_link_libraries(kekengine PUBLIC microtar_static)
target_link_libraries(kekengine PUBLIC Bullet3Collision BulletDynamics BulletCollision LinearMath Bullet3Collision Bullet3Common Bullet3Dynamics Bullet3Geometry BulletInverseDynamics)
target_link_libraries(kekengine PUBLIC freetype)
if(UNIX)
target_link_libraries(kekengine PUBLIC glfw GLEW GL)
if(NOT ${KEKENGINE_DISABLE_ERRORDIALOG})
# GTK
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
target_link_libraries(kekengine PUBLIC ${GTK3_LIBRARIES})
target_include_directories(kekengine PRIVATE ${GTK3_INCLUDE_DIRS})
endif()
endif()
if(WIN32)
target_link_libraries(kekengine PUBLIC glfw3 glew32s opengl32)
target_compile_definitions(kekengine PUBLIC GLEW_STATIC)
endif()
if(${KEKENGINE_VR})
target_link_directories(kekengine PUBLIC "dependencies/openvr/bin/linux64")
target_link_libraries(kekengine PUBLIC openvr_api)
endif()
if(UNIX)
target_compile_definitions(kekengine PUBLIC KEKENGINE_TARGET_LINUX)
endif()
if(WIN32)
target_compile_definitions(kekengine PUBLIC KEKENGINE_TARGET_WINDOWS)
endif()
if(${KEKENGINE_VR})
target_compile_definitions(kekengine PUBLIC KEKENGINE_VR)
target_include_directories(kekengine PRIVATE "dependencies/openvr/headers")
endif()
if(${KEKENGINE_DISABLE_ERRORDIALOG})
target_compile_definitions(kekengine PUBLIC KEK_DISABLE_ERRORDIALOG)
endif()
add_library(kekengine_shared SHARED $<TARGET_OBJECTS:kekengine>)
target_link_libraries(kekengine_shared PUBLIC kekengine)
set_target_properties(kekengine_shared PROPERTIES OUTPUT_NAME kekengine)
add_library(kekengine_static STATIC $<TARGET_OBJECTS:kekengine>)
target_link_libraries(kekengine_static PUBLIC kekengine)
set_target_properties(kekengine_static PROPERTIES OUTPUT_NAME kekengine)
if(${KEKENGINE_BUILD_KEKGAME})
# kekgame resources
add_custom_target(kekgame_res ALL
DEPENDS ${KEKGAME_RESOURCE_FILES} kekengine_res)
add_custom_command(TARGET kekgame_res PRE_BUILD
BYPRODUCTS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/resources.tar
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
COMMAND ${CMAKE_COMMAND} -E
chdir ${KEKGAME_RESOURCE_DIR}
tar rf ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/resources.tar ${KEKGAME_RELATIVE_RESOURCE_FILES})
# kekgame
add_executable(kekgame ${KEKGAME_SOURCE_FILES})
add_dependencies(kekgame kekgame_res)
if(WIN32)
target_link_options(kekgame PUBLIC -static-libgcc -static-libstdc++ -static)
endif()
target_link_libraries(kekgame PUBLIC kekengine_static)
endif()