KekEngine/CMakeLists.txt

133 lines
4.6 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)
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
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(KEKENGINE_RESOURCE_DIR "${CMAKE_SOURCE_DIR}/src/kekengine/res")
set(KEKGAME_RESOURCE_DIR "${CMAKE_SOURCE_DIR}/src/kekgame/res")
2022-11-05 13:47:17 +01:00
file(GLOB_RECURSE KEKENGINE_SOURCE_FILES "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}/*")
2022-11-05 13:47:17 +01:00
file(GLOB_RECURSE KEKGAME_SOURCE_FILES "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})
add_compile_options(-Wall -g)
else()
add_compile_options(-Wall -O3)
endif()
2022-10-07 15:48:50 +02:00
add_subdirectory(dependencies/microtar)
# 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
2022-10-16 14:30:12 +02:00
target_link_libraries(kekengine PUBLIC microtar_static)
# Freetype
find_package(PkgConfig REQUIRED)
pkg_check_modules(FREETYPE REQUIRED freetype2)
target_link_libraries(kekengine PUBLIC ${FREETYPE_LIBRARIES})
2022-10-20 21:09:04 +02:00
target_include_directories(kekengine PUBLIC ${FREETYPE_INCLUDE_DIRS})
2022-10-12 19:32:56 +02:00
if(UNIX)
target_link_libraries(kekengine PUBLIC glfw GLEW GL)
# 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()
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()
2022-10-07 15:48:50 +02:00
target_include_directories(kekengine PRIVATE "src/kekengine/include")
2022-10-12 19:32:56 +02:00
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
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)
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
target_include_directories(kekgame PRIVATE "src/kekengine/include")
endif()