From 95d2f4c24d097c445122a9722df57882af1bc5b3 Mon Sep 17 00:00:00 2001 From: "Daniele E. Domenichelli" Date: Tue, 10 Dec 2024 10:46:52 +0100 Subject: [PATCH] Add BUILD_STATIC option to create static libraries --- .github/workflows/build-external-graphviz.yml | 4 ++++ .github/workflows/build.yml | 4 ++++ CHANGES | 1 + CMakeLists.txt | 10 ++++++++++ src/core/CMakeLists.txt | 4 ++-- src/debuginterface/debuginterfaceclient/CMakeLists.txt | 4 ++-- src/view/CMakeLists.txt | 5 +++-- 7 files changed, 26 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-external-graphviz.yml b/.github/workflows/build-external-graphviz.yml index ff104300..ad09f66c 100644 --- a/.github/workflows/build-external-graphviz.yml +++ b/.github/workflows/build-external-graphviz.yml @@ -23,6 +23,9 @@ jobs: - macos-latest build_type: - Debug + lib_type: + - Shared + - Static config: - qt_version: 6.6.2 qt_modules: qtscxml @@ -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 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 769b32dc..4621626f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -25,6 +25,9 @@ jobs: build_type: - Debug - Release + lib_type: + - Shared + - Static config: - qt_version: 5.15.2 qt_arch: win64_msvc2019_64 @@ -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 diff --git a/CHANGES b/CHANGES index 124cdb4f..f903f1c2 100644 --- a/CHANGES +++ b/CHANGES @@ -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: -------------- diff --git a/CMakeLists.txt b/CMakeLists.txt index cfbc9415..f612cc1e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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") diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 6cfee031..84d3076a 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -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 @@ -159,7 +159,7 @@ install( EXPORT KDSME_TARGETS ${INSTALL_TARGETS_DEFAULT_ARGS} ) -if(MSVC) +if(MSVC AND NOT BUILD_STATIC) install( FILES "$/$" DESTINATION ${BIN_INSTALL_DIR} diff --git a/src/debuginterface/debuginterfaceclient/CMakeLists.txt b/src/debuginterface/debuginterfaceclient/CMakeLists.txt index cf773bd8..1ac9b027 100644 --- a/src/debuginterface/debuginterfaceclient/CMakeLists.txt +++ b/src/debuginterface/debuginterfaceclient/CMakeLists.txt @@ -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) @@ -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 diff --git a/src/view/CMakeLists.txt b/src/view/CMakeLists.txt index e7bc4c2f..d92a7c87 100644 --- a/src/view/CMakeLists.txt +++ b/src/view/CMakeLists.txt @@ -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 @@ -97,7 +98,7 @@ install( EXPORT KDSME_TARGETS ${INSTALL_TARGETS_DEFAULT_ARGS} ) -if(MSVC) +if(MSVC AND NOT BUILD_STATIC) install( FILES "$/$" DESTINATION ${BIN_INSTALL_DIR}