Skip to content

Commit

Permalink
Add BUILD_STATIC option to create static libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
drdanz committed Dec 10, 2024
1 parent 650665b commit 95d2f4c
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build-external-graphviz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ jobs:
- macos-latest
build_type:
- Debug
lib_type:
- Shared
- Static
config:
- qt_version: 6.6.2
qt_modules: qtscxml
Expand Down Expand Up @@ -68,6 +71,7 @@ jobs:
-DBUILD_TESTS=${{ matrix.build_type == 'Debug' }}
-DBUILD_EXAMPLES=ON
-DBUILD_DOCS=${{ matrix.build_type == 'Debug' && runner.os == 'Linux' }}
-DBUILD_STATIC=${{ matrix.lib_type == 'Static' }}
-DWITH_INTERNAL_GRAPHVIZ=OFF
- name: Build Project
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ jobs:
build_type:
- Debug
- Release
lib_type:
- Shared
- Static
config:
- qt_version: 5.15.2
qt_arch: win64_msvc2019_64
Expand Down Expand Up @@ -91,6 +94,7 @@ jobs:
-DBUILD_TESTS=${{ matrix.build_type == 'Debug' }}
-DBUILD_EXAMPLES=ON
-DBUILD_DOCS=${{ matrix.build_type == 'Debug' && runner.os == 'Linux' }}
-DBUILD_STATIC=${{ matrix.lib_type == 'Static' }}
- name: Build Project
run: cmake --build ./build
Expand Down
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Version 2.0.0: (unreleased):
* Use official Graphviz from upstream with -DWITH_INTERNAL_GRAPHVIZ=True
(Bad side-effect: allows dynamic builds only)
* Fixed build with more recent graphviz versions
* Buildsystem: new Option BUILD_STATIC to create static libraries

Version 1.2.8:
--------------
Expand Down
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
# Note: disabling tests also disables building the kdstatemachineeditor test application.
# Default=True
#
# -DBUILD_STATIC=[true|false]
# Build static libraries
# Default=false

cmake_minimum_required(VERSION 3.16)

Expand Down Expand Up @@ -76,6 +79,13 @@ else()
option(BUILD_TESTS "Build the test harness" ON)
endif()
option(BUILD_QT6 "Build against Qt 6" OFF)
option(BUILD_STATIC "Build statically" OFF)

if(BUILD_STATIC)
set(BUILD_LIBRARY_MODE "STATIC")
else()
set(BUILD_LIBRARY_MODE "SHARED")
endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/ECM/modules")
Expand Down
4 changes: 2 additions & 2 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ if(GRAPHVIZ_FOUND)
endif()
endif()

add_library(kdstatemachineeditor_core SHARED ${LIB_SRCS})
add_library(kdstatemachineeditor_core ${BUILD_LIBRARY_MODE} ${LIB_SRCS})
add_library(KDSME::Core ALIAS kdstatemachineeditor_core)
target_link_libraries(
kdstatemachineeditor_core
Expand Down Expand Up @@ -159,7 +159,7 @@ install(
EXPORT KDSME_TARGETS
${INSTALL_TARGETS_DEFAULT_ARGS}
)
if(MSVC)
if(MSVC AND NOT BUILD_STATIC)
install(
FILES "$<TARGET_PDB_FILE_DIR:kdstatemachineeditor_core>/$<TARGET_PDB_FILE_NAME:kdstatemachineeditor_core>"
DESTINATION ${BIN_INSTALL_DIR}
Expand Down
4 changes: 2 additions & 2 deletions src/debuginterface/debuginterfaceclient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if(NOT BUILD_QT6)
qt5_generate_repc(DEBUGINTERFACECLIENT_SRCS ../debuginterface.rep REPLICA)
endif()

add_library(kdstatemachineeditor_debuginterfaceclient SHARED ${DEBUGINTERFACECLIENT_SRCS})
add_library(kdstatemachineeditor_debuginterfaceclient ${BUILD_LIBRARY_MODE} ${DEBUGINTERFACECLIENT_SRCS})

if(BUILD_QT6)
qt6_add_repc_replicas(kdstatemachineeditor_debuginterfaceclient ../debuginterface.rep)
Expand Down Expand Up @@ -82,7 +82,7 @@ install(
EXPORT KDSME_TARGETS
${INSTALL_TARGETS_DEFAULT_ARGS}
)
if(MSVC)
if(MSVC AND NOT BUILD_STATIC)
# cmake-lint: disable=C0301
install(
FILES
Expand Down
5 changes: 3 additions & 2 deletions src/view/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
file(GLOB_RECURSE QML_JS_FILES *.qml *.js)

add_library(
kdstatemachineeditor_view SHARED
kdstatemachineeditor_view
${BUILD_LIBRARY_MODE}
command/command.cpp
command/commandfactory.cpp
command/createelementcommand.cpp
Expand Down Expand Up @@ -97,7 +98,7 @@ install(
EXPORT KDSME_TARGETS
${INSTALL_TARGETS_DEFAULT_ARGS}
)
if(MSVC)
if(MSVC AND NOT BUILD_STATIC)
install(
FILES "$<TARGET_PDB_FILE_DIR:kdstatemachineeditor_view>/$<TARGET_PDB_FILE_NAME:kdstatemachineeditor_view>"
DESTINATION ${BIN_INSTALL_DIR}
Expand Down

0 comments on commit 95d2f4c

Please sign in to comment.