Skip to content

Commit

Permalink
temporary CMake refactor commit, squash this later
Browse files Browse the repository at this point in the history
  • Loading branch information
RiscadoA committed Sep 27, 2024
1 parent 3a4258d commit 528aa87
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 6 deletions.
48 changes: 48 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,51 @@ option(BUILD_DOCUMENTATION "Build docs" OFF)
if(BUILD_DOCUMENTATION)
add_subdirectory(docs)
endif()

# Installation instructions

include(GNUInstallDirs)
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/cubos)

install(TARGETS ${CUBOS_CORE_TARGETS} ${CUBOS_ENGINE_TARGETS}
EXPORT cubos-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

# Copy the headers to the install directory
install(DIRECTORY core/include DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/cubos-core)
install(DIRECTORY engine/include DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/cubos-engine)

# Export the targets to a script
install(EXPORT cubos-targets
FILE cubosTargets.cmake
NAMESPACE cubos::
DESTINATION ${INSTALL_CONFIGDIR}
)

# Write a ConfigVersion.cmake file so that find_package can be used with version specification
include(CMakePackageConfigHelpers)
write_basic_package_version_file(cubosConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMinorVersion
)

configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/cmake/cubosConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cubosConfig.cmake
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
)

# Install the config and configversion modules
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/cubosConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/cubosConfigVersion.cmake
DESTINATION ${INSTALL_CONFIGDIR}
)

# Export from the build tree

export(TARGETS ${CUBOS_CORE_TARGETS} ${CUBOS_ENGINE_TARGETS}
FILE ${CMAKE_CURRENT_BINARY_DIR}/cubosTargets.cmake
NAMESPACE cubos::)
export(PACKAGE cubos)
13 changes: 13 additions & 0 deletions cmake/cubosConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
get_filename_component(CUBOS_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
include(CMakeFindDependencyMacro)

list(APPEND CMAKE_MODULE_PATH ${CUBOS_CMAKE_DIR})

find_dependency(nlohmann_json)
find_dependency(stduuid)

if(NOT TARGET cubos::core OR NOT TARGET cubos::engine)
include("${CUBOS_CMAKE_DIR}/cubosTargets.cmake")
endif()

set(CUBOS_LIBRARIES cubos::core cubos::engine)
17 changes: 16 additions & 1 deletion core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,16 @@ if(BUILD_CORE_SHARED)
else()
add_library(cubos-core STATIC ${CUBOS_CORE_SOURCE})
endif()
target_include_directories(cubos-core PUBLIC "include")

# Alias so that we can use cubos::core inside the build tree
add_library(cubos::core ALIAS cubos-core)
set_target_properties(cubos-core PROPERTIES EXPORT_NAME core)
set(CUBOS_CORE_TARGETS cubos-core PARENT_SCOPE)

target_include_directories(cubos-core PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/cubos-core>
)
target_compile_definitions(cubos-core PUBLIC
-DCUBOS_CORE_ECS_MAX_COMPONENTS=${CUBOS_CORE_ECS_MAX_COMPONENTS}
)
Expand All @@ -175,6 +184,7 @@ if(WITH_OPENGL)
endif()
target_link_libraries(cubos-core PRIVATE glad)
target_compile_definitions(cubos-core PRIVATE WITH_OPENGL GLAD_GLAPI_EXPORT GLAD_GLAPI_EXPORT_BUILD)
set(CUBOS_CORE_TARGETS ${CUBOS_CORE_TARGETS} glad PARENT_SCOPE)
endif()

if(WITH_GLFW)
Expand All @@ -183,6 +193,7 @@ if(WITH_GLFW)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
add_subdirectory(lib/glfw)
set(CUBOS_CORE_TARGETS ${CUBOS_CORE_TARGETS} glfw PARENT_SCOPE)
else()
find_package(glfw3 REQUIRED)
endif()
Expand All @@ -199,18 +210,22 @@ if(WITH_OPENAL)
target_include_directories(cubos-core PRIVATE lib/openal-soft/include)
target_link_libraries(cubos-core PRIVATE OpenAL)
target_compile_definitions(cubos-core PRIVATE WITH_OPENAL)
set(CUBOS_CORE_TARGETS ${CUBOS_CORE_TARGETS} OpenAL PARENT_SCOPE)
endif()

if(GLM_USE_SUBMODULE)
add_subdirectory(lib/glm SYSTEM)
set(CUBOS_CORE_TARGETS ${CUBOS_CORE_TARGETS} glm PARENT_SCOPE)
else()
find_package(glm REQUIRED)
endif()

set(JSON_BuildTests OFF CACHE INTERNAL "")
add_subdirectory(lib/json)
set(CUBOS_CORE_TARGETS ${CUBOS_CORE_TARGETS} nlohmann_json PARENT_SCOPE)

add_subdirectory(lib/stduuid)
set(CUBOS_CORE_TARGETS ${CUBOS_CORE_TARGETS} stduuid PARENT_SCOPE)
target_link_libraries(cubos-core PUBLIC stduuid)

set(THREADS_PREFER_PTHREAD_FLAG ON)
Expand Down
25 changes: 20 additions & 5 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,15 @@ else()
add_library(cubos-engine STATIC ${CUBOS_ENGINE_SOURCE})
endif()

target_include_directories(cubos-engine PUBLIC "include")
# Alias so that we can use cubos::engine inside the build tree
add_library(cubos::engine ALIAS cubos-engine)
set_target_properties(cubos-engine PROPERTIES EXPORT_NAME engine)
set(CUBOS_ENGINE_TARGETS cubos-engine PARENT_SCOPE)

target_include_directories(cubos-engine PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/cubos-engine>
)
target_link_libraries(cubos-engine PUBLIC cubos-core)
target_compile_definitions(cubos-engine PRIVATE CUBOS_BUILTIN_ASSETS_FOLDER="${CMAKE_CURRENT_SOURCE_DIR}/assets")
cubos_common_target_options(cubos-engine)
Expand All @@ -199,16 +207,23 @@ set(IMGUI_SOURCES
"lib/implot/implot_demo.cpp"
)
add_library(imgui STATIC ${IMGUI_SOURCES})
set(CUBOS_ENGINE_TARGETS ${CUBOS_ENGINE_TARGETS} imgui PARENT_SCOPE)
set_property(TARGET imgui PROPERTY POSITION_INDEPENDENT_CODE ON)
target_include_directories(imgui PUBLIC
"lib/imgui"
"lib/imgui/misc/cpp"
"lib/implot"
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lib/imgui>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lib/imgui/misc/cpp>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lib/implot>
$<INSTALL_INTERFACE:include/imgui>
)
target_link_libraries(cubos-engine PUBLIC imgui)

add_library(stb_image INTERFACE)
target_include_directories(stb_image SYSTEM INTERFACE "lib/stb_image")
set(CUBOS_ENGINE_TARGETS ${CUBOS_ENGINE_TARGETS} stb_image PARENT_SCOPE)
target_include_directories(stb_image SYSTEM INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lib/stb_image>
$<INSTALL_INTERFACE:include/stb_image>
)

target_link_libraries(cubos-engine PUBLIC stb_image)

# Add engine tests
Expand Down

0 comments on commit 528aa87

Please sign in to comment.