Skip to content

Commit

Permalink
Support selection of deps to be shared/static
Browse files Browse the repository at this point in the history
  • Loading branch information
tamasmeszaros committed Nov 2, 2023
1 parent 0e115d3 commit 56b0fdf
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ option(${PROJECT_NAME}_BUILD_SANITIZERS "Turn on sanitizers" OFF)
# Dependency build management
option(${PROJECT_NAME}_BUILD_DEPS "Build dependencies before the project" OFF)
option(${PROJECT_NAME}_DEPS_OUTPUT_QUIET "Don't print build output for dependencies" ON)
option(${PROJECT_NAME}_DEPS_SHARED "Build dependencies as shared libraries" OFF)
set(${PROJECT_NAME}_DEPS_PRESET "default" CACHE STRING "Preset of the dependencies when ${PROJECT_NAME}_BUILD_DEPS is ON")
set(${PROJECT_NAME}_DEPS_BUILD_DIR "" CACHE PATH "Binary dir of the dependencies build when ${PROJECT_NAME}_BUILD_DEPS is ON")

Expand Down Expand Up @@ -61,6 +62,10 @@ configure_file(
${PROJECT_BINARY_DIR}/version.rc
@ONLY)

if (CMAKE_COMPILER_IS_GNUCXX)
add_compile_options(-fvisibility=hidden)
endif ()

add_subdirectory(${_srcloc}/core)

if (${PROJECT_NAME}_BUILD_COMPONENT_Binarize)
Expand Down
1 change: 0 additions & 1 deletion cmake/ProjectVersion.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
file(STRINGS ${CMAKE_CURRENT_LIST_DIR}/../pyproject.toml _tmp REGEX "version")
string(REGEX REPLACE "version = \"([0-9]+\\.[0-9]+\\.[0-9]+)\"" "\\1" LibBGCode_VERSION ${_tmp} )
message(STATUS "LibBGCode_VERSION=${LibBGCode_VERSION}")
1 change: 1 addition & 0 deletions cmake/modules/AddCMakeProject.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function(add_cmake_project projectname)
-DCMAKE_C_FLAGS_${_build_type_upper}:STRING=${CMAKE_C_FLAGS_${_build_type_upper}}
-DCMAKE_TOOLCHAIN_FILE:STRING=${CMAKE_TOOLCHAIN_FILE}
-DBUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS}
-DCMAKE_POSITION_INDEPENDENT_CODE=${CMAKE_POSITION_INDEPENDENT_CODE}
"${_configs_line}"
${DEP_CMAKE_OPTS}
${P_ARGS_CMAKE_ARGS}
Expand Down
8 changes: 8 additions & 0 deletions deps/autobuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ if (CMAKE_TOOLCHAIN_FILE)
list(APPEND _build_args "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}")
endif ()

if (${PROJECT_NAME}_DEPS_SHARED) # if deps needs to be built as shared libs
list(APPEND _build_args "-DBUILD_SHARED_LIBS:BOOL=ON")
endif ()

if (BUILD_SHARED_LIBS) # forward if PIC is needed (static deps but project is shared library)
list(APPEND _build_args "-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON")
endif ()

set(_build_dir "${CMAKE_CURRENT_LIST_DIR}/build-${${PROJECT_NAME}_DEPS_PRESET}")
if (${PROJECT_NAME}_DEPS_BUILD_DIR)
set(_build_dir "${${PROJECT_NAME}_DEPS_BUILD_DIR}")
Expand Down
14 changes: 12 additions & 2 deletions deps/heatshrink/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
cmake_minimum_required(VERSION 3.10)

project(heatshrink C)
project(heatshrink C VERSION 0.4.1)

set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)

add_library(${PROJECT_NAME} heatshrink_decoder.c heatshrink_encoder.c)
add_library(${PROJECT_NAME}_dynalloc heatshrink_decoder.c heatshrink_encoder.c)
Expand All @@ -22,13 +25,20 @@ if (UNIX)
set_target_properties(${PROJECT_NAME}_cmd PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
endif ()

foreach (tgt IN ${PROJECT_NAME} ${PROJECT_NAME}_dynalloc)
set_target_properties(${tgt}
PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION})
endforeach()

# Installation and export:

include(CMakePackageConfigHelpers)

write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
VERSION 0.4.1
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)

Expand Down

0 comments on commit 56b0fdf

Please sign in to comment.