Skip to content

Commit

Permalink
build(core): allow building as a shared library
Browse files Browse the repository at this point in the history
  • Loading branch information
RiscadoA committed Mar 1, 2024
1 parent 94e07d0 commit 3bffc29
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- New feature guide focused on queries (#995, **@RiscadoA**).
- ECS Statistics tesseratos plugin (#1024, **@RiscadoA**).
- Global position, rotation and scale getters (#1002, **@DiogoMendonc-a**).
- Possibility of building the core library as a shared library (#1052, **@RiscadoA**).

### Fixed

Expand Down
17 changes: 15 additions & 2 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ set(CUBOS_CORE_DISPATCHER_MAX_CONDITIONS "64" CACHE STRING "The maximum number o

option(BUILD_CORE_SAMPLES "Build cubos core samples" OFF)
option(BUILD_CORE_TESTS "Build cubos core tests?" OFF)
option(BUILD_CORE_SHARED "Build cubos core as shared library?" ON)

message("# Building core samples: " ${BUILD_CORE_SAMPLES})
message("# Building core tests: " ${BUILD_CORE_TESTS})
message("# Building core as shared library: " ${BUILD_CORE_SHARED})

# Set core source files
set(CUBOS_CORE_SOURCE
Expand Down Expand Up @@ -135,7 +137,15 @@ set(CUBOS_CORE_SOURCE
)

# Create core library
add_library(cubos-core ${CUBOS_CORE_SOURCE})
if(BUILD_CORE_SHARED)
add_library(cubos-core SHARED ${CUBOS_CORE_SOURCE})
target_compile_definitions(cubos-core
PRIVATE -DCUBOS_CORE_EXPORT
PUBLIC -DCUBOS_CORE_IMPORT
)
else()
add_library(cubos-core STATIC ${CUBOS_CORE_SOURCE})
endif()
target_include_directories(cubos-core PUBLIC "include")
target_compile_definitions(cubos-core PUBLIC
-DCUBOS_CORE_ECS_MAX_COMPONENTS=${CUBOS_CORE_ECS_MAX_COMPONENTS}
Expand All @@ -148,8 +158,11 @@ if(WITH_OPENGL)
set(GLAD_SOUURCES_DIR "lib/glad")
add_subdirectory("${GLAD_SOUURCES_DIR}/cmake" glad_cmake SYSTEM)
glad_add_library(glad REPRODUCIBLE API gl:core=3.3)
if(BUILD_CORE_SHARED)
set_property(TARGET glad PROPERTY POSITION_INDEPENDENT_CODE ON)
endif()
target_link_libraries(cubos-core PRIVATE glad)
target_compile_definitions(cubos-core PRIVATE WITH_OPENGL)
target_compile_definitions(cubos-core PRIVATE WITH_OPENGL GLAD_GLAPI_EXPORT GLAD_GLAPI_EXPORT_BUILD)
endif()

if(WITH_GLFW)
Expand Down

0 comments on commit 3bffc29

Please sign in to comment.