KekEngine/CMakeLists.txt

147 lines
5.3 KiB
CMake
Raw Normal View History

cmake_minimum_required(VERSION 3.13)
2022-10-07 15:48:50 +02:00
project(KekEngine VERSION 1.0)
option(KEKENGINE_DEBUG "Build with debug information" OFF)
2022-10-12 19:32:56 +02:00
option(KEKENGINE_VR "Include VR support" OFF)
option(KEKENGINE_BUILD_KEKGAME "Build kekgame" OFF)
2023-10-18 18:39:04 +02:00
option(KEKENGINE_DISABLE_ERRORDIALOG "Disable error dialogs" OFF)
2022-10-07 15:48:50 +02:00
2022-10-12 19:32:56 +02:00
if(UNIX)
set(KEKENGINE_TARGET_PLATFORM Linux)
endif()
if(WIN32)
set(KEKENGINE_TARGET_PLATFORM Windows)
#set(BUILD_SHARED_LIBS OFF)
2022-10-12 19:32:56 +02:00
endif()
message("Debug: ${KEKENGINE_DEBUG}")
message("Build kekgame: ${KEKENGINE_BUILD_KEKGAME}")
message("Build with VR support: ${KEKENGINE_VR}")
2022-10-12 19:32:56 +02:00
message("Target platform: ${KEKENGINE_TARGET_PLATFORM}")
2022-10-07 15:48:50 +02:00
2023-09-09 14:13:38 +02:00
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)
2022-10-07 15:48:50 +02:00
2023-09-09 14:13:38 +02:00
set(KEKENGINE_RESOURCE_DIR "${PROJECT_SOURCE_DIR}/src/kekengine/res")
set(KEKGAME_RESOURCE_DIR "${PROJECT_SOURCE_DIR}/src/kekgame/res")
2023-09-09 14:13:38 +02:00
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}/*")
2023-09-09 14:13:38 +02:00
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}/*")
2022-10-07 15:48:50 +02:00
add_compile_definitions(FT_CONFIG_OPTION_ERROR_STRINGS) # Freetype error strings
if(${KEKENGINE_DEBUG})
2023-10-18 18:39:04 +02:00
add_compile_options(-Wall -g)
else()
2023-10-18 18:39:04 +02:00
add_compile_options(-Wall -O3)
endif()
2022-10-07 15:48:50 +02:00
2023-10-18 18:39:04 +02:00
set(CMAKE_CXX_STANDARD 20)
2023-09-09 16:35:31 +02:00
block()
2023-09-09 16:18:36 +02:00
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
2023-09-09 16:35:31 +02:00
add_subdirectory(dependencies/microtar)
2023-09-09 16:18:36 +02:00
add_subdirectory(dependencies/bullet3 EXCLUDE_FROM_ALL)
2023-09-09 16:35:31 +02:00
add_subdirectory(dependencies/freetype)
endblock()
2023-09-09 16:18:36 +02:00
# 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
2022-10-08 14:27:25 +02:00
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)
2022-10-08 14:27:25 +02:00
add_dependencies(kekengine kekengine_res)
2022-10-07 15:48:50 +02:00
2023-09-09 16:35:31 +02:00
target_include_directories(kekengine PUBLIC "src/kekengine/include")
target_include_directories(kekengine PUBLIC "dependencies/bullet3/src")
target_include_directories(kekengine PUBLIC "dependencies/freetype/include")
2023-09-11 14:03:49 +02:00
target_include_directories(kekengine PUBLIC "dependencies/stb")
2023-10-18 18:39:04 +02:00
target_include_directories(kekengine PUBLIC "dependencies/glm")
2023-09-09 16:18:36 +02:00
2022-10-16 14:30:12 +02:00
target_link_libraries(kekengine PUBLIC microtar_static)
2023-09-09 16:43:28 +02:00
target_link_libraries(kekengine PUBLIC Bullet3Collision BulletDynamics BulletCollision LinearMath Bullet3Collision Bullet3Common Bullet3Dynamics Bullet3Geometry BulletInverseDynamics)
target_link_libraries(kekengine PUBLIC freetype)
2022-11-07 21:36:45 +01:00
2022-10-12 19:32:56 +02:00
if(UNIX)
target_link_libraries(kekengine PUBLIC glfw GLEW GL)
2023-10-18 18:39:04 +02:00
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()
2022-10-12 19:32:56 +02:00
endif()
if(WIN32)
target_link_libraries(kekengine PUBLIC glfw3 glew32s opengl32)
target_compile_definitions(kekengine PUBLIC GLEW_STATIC)
2022-10-12 19:32:56 +02:00
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()
2022-10-07 15:48:50 +02:00
2023-10-18 18:39:04 +02:00
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)
2023-09-09 16:18:36 +02:00
add_library(kekengine_static STATIC $<TARGET_OBJECTS:kekengine>)
target_link_libraries(kekengine_static PUBLIC kekengine)
set_target_properties(kekengine_static PROPERTIES OUTPUT_NAME kekengine)
2022-10-08 14:27:25 +02:00
if(${KEKENGINE_BUILD_KEKGAME})
# kekgame resources
add_custom_target(kekgame_res ALL
DEPENDS ${KEKGAME_RESOURCE_FILES} kekengine_res)
2022-10-08 14:27:25 +02:00
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})
2022-10-07 15:48:50 +02:00
2022-10-08 14:27:25 +02:00
# kekgame
add_executable(kekgame ${KEKGAME_SOURCE_FILES})
add_dependencies(kekgame kekgame_res)
2022-10-07 15:48:50 +02:00
if(WIN32)
target_link_options(kekgame PUBLIC -static-libgcc -static-libstdc++ -static)
endif()
target_link_libraries(kekgame PUBLIC kekengine_static)
2022-10-08 14:27:25 +02:00
endif()