Skip to content

Commit f94ca1f

Browse files
Add graphviz as submodule (#47)
* Add graphviz as submodule * Create fwd_headers for submodule graphiz * Fix exporting graphviz targets * Fix submodule build/link * Fix size_t warning * Build with Windows/macOS * [ci] Add macOS bison to PATH * Try to build on Windows with 64bit * Changes to static link graphviz * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update submodule with graphviz that has static build fixes * Build graphviz in static mode * Check if other OSes are still building and try to dump dlls from tests * Disable msvc setup on !windows * Try dumpbin * run dumpbin on failure * Try to fix linux and dumpbin * fix typo test * try to find test * another try * dumpbin * Revert kdstatemachineeditor_core to SHARED * Manually disable gvedit again * try devenv * try Dependency Walker * update graphviz * PIC revert was not merged yet * fix macos * Try to fix macos bison * Fix macos on apple silicon * fix variable name * Fix variable * make sure linux & macos pass all variants * Add graphviz deps bin to path * 2nd try * Another path fix try * inspecting github_path * Test if dir needs to exist * CMake copy depencencies to bin dir * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * cleanups * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 099a52d commit f94ca1f

File tree

15 files changed

+221
-132
lines changed

15 files changed

+221
-132
lines changed

.github/workflows/build.yml

+43-24
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
build:
1717
runs-on: ${{ matrix.os }}
1818
strategy:
19-
fail-fast: true
19+
fail-fast: false
2020
matrix:
2121
os:
2222
- ubuntu-latest
@@ -26,28 +26,26 @@ jobs:
2626
- Debug
2727
- Release
2828
config:
29-
- qt_version: "5.15"
30-
qt_arch: win64_mingw81
31-
- qt_version: "6.4.*"
29+
- qt_version: 5.15.2
30+
qt_arch: win64_msvc2019_64
31+
macos_architectures: "x86_64"
32+
- qt_version: 6.6.2
3233
qt_modules: qtscxml
33-
qt_arch: win64_mingw
34+
qt_arch: win64_msvc2019_64
35+
macos_architectures: "x86_64;arm64"
3436

3537
steps:
3638
- name: Install Dependencies on Linux
3739
if: ${{ runner.os == 'Linux' }}
3840
run: |
3941
sudo apt update -qq
40-
sudo apt install -y doxygen libgraphviz-dev
41-
42-
- name: Install Dependencies on Windows (graphviz was built with MinGW)
43-
if: ${{ runner.os == 'Windows' }}
44-
run: choco install winflexbison3 graphviz
42+
sudo apt install -y doxygen libgtk2.0-dev
4543
4644
- name: Install Dependencies on macOS
4745
if: ${{ runner.os == 'macOS' }}
48-
run: brew install graphviz
46+
run: brew install bison
4947

50-
- name: Install Qt with options and default aqtversion (Linux/macOS)
48+
- name: Install Qt ${{ matrix.config.qt_version }} with options and default aqtversion (Linux/macOS)
5149
if: ${{ runner.os != 'Windows' }}
5250
uses: jurplel/install-qt-action@v3
5351
with:
@@ -63,33 +61,54 @@ jobs:
6361
aqtversion: null # use whatever the default is
6462
modules: ${{ matrix.config.qt_modules }}
6563
version: ${{ matrix.config.qt_version }}
66-
arch: ${{ matrix.config.qt_arch }} # MinGW is required otherwise we get link errors with graphviz
64+
arch: ${{ matrix.config.qt_arch }}
6765
cache: true
6866

69-
- name: Add Graphviz libraries to Windows PATH
70-
if: ${{ runner.os == 'Windows' }}
71-
shell: bash
72-
run: echo "C:/Program Files/Graphviz/bin" >> $GITHUB_PATH
73-
7467
- name: Install ninja-build tool (must be after Qt due PATH changes)
7568
uses: turtlesec-no/get-ninja@main
7669

70+
- name: Add Bison to PATH (must be after Qt due PATH changes)
71+
if: ${{ runner.os == 'macOS' }}
72+
run: echo "/opt/homebrew/opt/bison/bin" >> $GITHUB_PATH
73+
74+
- uses: TheMrMilchmann/setup-msvc-dev@v3
75+
if: ${{ runner.os == 'Windows' }}
76+
with:
77+
arch: x64
78+
7779
- name: Checkout sources
7880
uses: actions/checkout@v4
81+
with:
82+
submodules: recursive
7983

80-
- name: Fetch Git submodule
81-
run: git submodule update --init --recursive
82-
83-
- name: Configure project
84+
- name: Configure project (Linux/macOS)
85+
if: ${{ runner.os != 'Windows' }}
8486
run: >
8587
cmake -S . -B ./build -G Ninja
86-
--warn-uninitialized -Werror=dev
8788
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
88-
-DCMAKE_PREFIX_PATH='C:\Program Files\Graphviz'
89+
-DCMAKE_OSX_ARCHITECTURES="${{ matrix.config.macos_architectures }}"
8990
-DBUILD_QT6=${{ startsWith(matrix.config.qt_version, '6.') }}
9091
-DBUILD_TESTS=${{ matrix.build_type == 'Debug' }}
9192
-DBUILD_EXAMPLES=ON
9293
-DBUILD_DOCS=${{ matrix.build_type == 'Debug' && runner.os == 'Linux' }}
94+
-DWITH_INTERNAL_GRAPHVIZ=ON
95+
-Dwith_gvedit=OFF
96+
97+
- name: Configure project (Windows)
98+
if: ${{ runner.os == 'Windows' }}
99+
run: >
100+
cmake -S . -B ./build -G Ninja
101+
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
102+
-DBUILD_QT6=${{ startsWith(matrix.config.qt_version, '6.') }}
103+
-DBUILD_TESTS=${{ matrix.build_type == 'Debug' }}
104+
-DBUILD_EXAMPLES=ON
105+
-DBUILD_DOCS=${{ matrix.build_type == 'Debug' && runner.os == 'Linux' }}
106+
-DWITH_INTERNAL_GRAPHVIZ=ON
107+
-Dwith_gvedit=OFF
108+
-DCMAKE_PREFIX_PATH="${{github.workspace}}/3rdparty/graphviz/windows/dependencies/libraries"
109+
-DCMAKE_PROGRAM_PATH="${{github.workspace}}/3rdparty/graphviz/windows/dependencies/graphviz-build-utilities"
110+
-DBISON_EXECUTABLE="${{github.workspace}}/3rdparty/graphviz/windows/dependencies/graphviz-build-utilities/winflexbison/win_bison.exe"
111+
-DFLEX_EXECUTABLE="${{github.workspace}}/3rdparty/graphviz/windows/dependencies/graphviz-build-utilities/winflexbison/win_flex.exe"
93112
94113
- name: Build Project
95114
run: cmake --build ./build

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "3rdparty/graphviz"]
2+
path = 3rdparty/graphviz
3+
url = https://gitlab.com/graphviz/graphviz.git

.reuse/dep5

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Copyright: Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
1414
License: LGPL-2.1-only OR LicenseRef-KDAB-KDStateMachineEditor
1515

1616
#misc config files
17-
Files: .pre-commit-config.yaml .codespellrc .krazy .clang-tidy .gitignore appveyor.yml distro/* .clang-format .cmake-format.py .mdlrc .mdlrc.rb
17+
Files: .pre-commit-config.yaml .codespellrc .krazy .clang-tidy .gitignore .gitmodules appveyor.yml distro/* .clang-format .cmake-format.py .mdlrc .mdlrc.rb
1818
Copyright: Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
1919
License: BSD-3-Clause
2020

3rdparty/CMakeLists.txt

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#
2+
# This file is part of the KDAB State Machine Editor Library.
3+
#
4+
# SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
5+
# Author: Daniel Nicoletti <[email protected]>
6+
#
7+
# SPDX-License-Identifier: LGPL-2.1-only OR LicenseRef-KDAB-KDStateMachineEditor
8+
#
9+
# Licensees holding valid commercial KDAB State Machine Editor Library
10+
# licenses may use this file in accordance with the KDAB State Machine Editor
11+
# Library License Agreement provided with the Software.
12+
#
13+
# Contact [email protected] if any conditions of this licensing are not clear to you.
14+
#
15+
16+
if(WITH_INTERNAL_GRAPHVIZ)
17+
# Function creates extra scope to keep these variables local
18+
function(add_graphviz_subdirectory)
19+
#TODO check if there are unneeded features to disable
20+
21+
if(WITH_STATIC_GRAPHVIZ)
22+
set(CMAKE_POSITION_INDEPENDENT_CODE ON
23+
)#TODO remove after https://gitlab.com/graphviz/graphviz/-/merge_requests/3823 is merged
24+
set(BUILD_SHARED_LIBS OFF)
25+
endif()
26+
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/graphviz/CMakeLists.txt")
27+
message(FATAL_ERROR "Please do git submodule update --init --recursive")
28+
endif()
29+
30+
add_subdirectory(graphviz)
31+
32+
if(WIN32)
33+
# On Windows we need some dependencies available for tests
34+
file(GLOB GRAPHVIZ_DEPENDENCIES
35+
${CMAKE_CURRENT_SOURCE_DIR}/graphviz/windows/dependencies/libraries/x64/bin/*
36+
)
37+
file(COPY ${GRAPHVIZ_DEPENDENCIES} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
38+
endif()
39+
endfunction()
40+
41+
add_graphviz_subdirectory()
42+
endif()

3rdparty/graphviz

Submodule graphviz added at ef3ba96

CMakeLists.txt

+20-97
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
# In the case where a separate Graphviz installation is not practical or desired.
2323
# Default=true if Graphviz is not located; false otherwise
2424
#
25+
# -WITH_STATIC_GRAPHVIZ=[true|false]
26+
# Allow the internal Graphviz build to be statically.
27+
# Currently shared graphviz builds on Windows have link issues.
28+
# Default=true
29+
#
2530
# -DBUILD_QT6=[true|false]
2631
# Build against Qt6 rather than Qt5
2732
# Default=false (Qt5 will be used even if Qt6 is available)
@@ -50,16 +55,6 @@ project(
5055
VERSION 1.99.50
5156
)
5257

53-
add_definitions(
54-
-DQT_NO_CAST_TO_ASCII
55-
-DQT_NO_CAST_FROM_ASCII
56-
-DQT_STRICT_ITERATORS
57-
-DQT_NO_URL_CAST_FROM_STRING
58-
-DQT_NO_CAST_FROM_BYTEARRAY
59-
-DQT_USE_QSTRINGBUILDER
60-
-DQT_USE_FAST_OPERATOR_PLUS
61-
)
62-
6358
set(KDSME_SOVERSION "2") #means the 2.x ABI is frozen. ABI changes will must go to version 3
6459

6560
include(FeatureSummary)
@@ -217,7 +212,9 @@ set(INSTALL_TARGETS_DEFAULT_ARGS
217212

218213
# search for Graphviz
219214
set(GRAPHVIZ_MIN_VERSION "2.30.1")
220-
find_package(Graphviz)
215+
if(NOT DEFINED WITH_INTERNAL_GRAPHVIZ)
216+
find_package(Graphviz)
217+
endif()
221218
set_package_properties(
222219
Graphviz PROPERTIES
223220
TYPE RECOMMENDED
@@ -231,102 +228,28 @@ if(GRAPHVIZ_FOUND)
231228
elseif(NOT CMAKE_SYSTEM_NAME STREQUAL QNX)
232229
message(STATUS "Auto-enabling internal Graphviz build, since no installed version is available")
233230
set(WITH_INTERNAL_GRAPHVIZ_DEFAULT ON)
231+
set(GRAPHVIZ_FOUND ON)
234232
endif()
235233

236234
option(WITH_INTERNAL_GRAPHVIZ "Enable build of external project Graphviz" ${WITH_INTERNAL_GRAPHVIZ_DEFAULT})
237235
add_feature_info("Internal build of Graphviz" WITH_INTERNAL_GRAPHVIZ "enable with WITH_INTERNAL_GRAPHVIZ=ON")
238236

239-
set(WITH_STATIC_GRAPHVIZ OFF) # Whether the Graphviz build we're using is static or not -- WIP
240-
241237
if(WITH_INTERNAL_GRAPHVIZ)
242-
# CMake is really awful here...
243-
set(source_dir ${CMAKE_CURRENT_BINARY_DIR}/graphviz-src)
244-
set(install_dir ${CMAKE_CURRENT_BINARY_DIR}/graphviz-install)
245-
246-
# work-around: https://cmake.org/Bug/view.php?id=15052
247-
set(include_dir "${install_dir}/include")
248-
file(MAKE_DIRECTORY ${include_dir})
249-
set(GRAPHVIZ_INCLUDE_DIR ${include_dir})
250-
251-
if(UNIX OR WITH_STATIC_GRAPHVIZ)
252-
set(libfolder "lib")
253-
else()
254-
set(libfolder "bin")
255-
endif()
256-
257-
if(WITH_STATIC_GRAPHVIZ)
258-
set(staticdotlayoutplugin_library
259-
"${install_dir}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}gvplugin_dot_layout${CMAKE_STATIC_LIBRARY_SUFFIX}"
260-
)
261-
set(link_libraries_absolute)
262-
foreach(link_library "xdot;gvc;cgraph;pathplan")
263-
list(APPEND link_libraries_absolute
264-
${install_dir}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}${link_library}${CMAKE_STATIC_LIBRARY_SUFFIX}
265-
)
266-
endforeach()
267-
else()
268-
set(GRAPHVIZ_CGRAPH_LIBRARY
269-
"${install_dir}/${libfolder}/${CMAKE_SHARED_LIBRARY_PREFIX}cgraph${CMAKE_SHARED_LIBRARY_SUFFIX}"
270-
)
271-
set(GRAPHVIZ_GVC_LIBRARY
272-
"${install_dir}/${libfolder}/${CMAKE_SHARED_LIBRARY_PREFIX}gvc${CMAKE_SHARED_LIBRARY_SUFFIX}"
273-
)
274-
set(link_libraries_absolute "${GRAPHVIZ_CGRAPH_LIBRARY};${GRAPHVIZ_GVC_LIBRARY}")
275-
endif()
276-
277-
set(win_build_utilities ${source_dir}/windows/dependencies/graphviz-build-utilities)
278-
string(TIMESTAMP graphvizDate)
279-
set(GRAPHVIZ_MAJOR_VERSION 2)
280-
set(GRAPHVIZ_MINOR_VERSION 48)
281-
set(GRAPHVIZ_PATCH_VERSION 0)
282-
set(graphvizVersion "${GRAPHVIZ_MAJOR_VERSION}.${GRAPHVIZ_MINOR_VERSION}.${GRAPHVIZ_PATCH_VERSION}")
283-
# cmake-lint: disable=C0301
284-
externalproject_add(
285-
GraphvizExternalProject
286-
GIT_REPOSITORY "https://gitlab.com/graphviz/graphviz.git"
287-
GIT_TAG ${graphvizVersion}
288-
GIT_PROGRESS 1
289-
USES_TERMINAL_DOWNLOAD
290-
TRUE # needed for Ninja so we can see the Git progress (cf. https://gitlab.kitware.com/cmake/cmake/-/issues/18238)
291-
CMAKE_ARGS
292-
-DVERSION=${graphvizVersion}
293-
-DDATE=${graphvizDate}
294-
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
295-
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
296-
-DCMAKE_C_COMPILER_AR=${CMAKE_C_COMPILER_AR}
297-
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
298-
-DCMAKE_CXX_COMPILER_AR=${CMAKE_CXX_COMPILER_AR}
299-
-DCMAKE_INSTALL_PREFIX=${install_dir}
300-
$<$<BOOL:${WIN32}>:-DCMAKE_IGNORE_PATH="C:/Strawberry/c/bin">
301-
$<$<BOOL:${WIN32}>:-DCMAKE_SYSTEM_PREFIX_PATH=${win_build_utilities}$<SEMICOLON>${win_build_utilities}/winflexbison$<SEMICOLON>${win_build_utilities}/Perl64$<SEMICOLON>${win_build_utilities}/GnuWin/bin>
302-
BUILD_COMMAND "" # skip, make install is enough
303-
SOURCE_DIR ${source_dir}
304-
INSTALL_DIR ${install_dir}
305-
INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install
306-
# Note: BUILD_BYPRODUCTS only available since CMake 3.2
307-
# Needed to make ExternalProject_Add in combination with the Ninja generator work
308-
# Also see: https://cmake.org/pipermail/cmake/2015-April/060234.html
309-
BUILD_BYPRODUCTS ${staticdotlayoutplugin_library} ${link_libraries_absolute}
238+
option(WITH_STATIC_GRAPHVIZ "Enable static build of Graphviz when internally building" ON)
239+
add_feature_info(
240+
"Statically build Graphviz for internal builds" WITH_INTERNAL_GRAPHVIZ "disable with WITH_STATIC_GRAPHVIZ=OFF"
310241
)
311242

312-
if(WITH_STATIC_GRAPHVIZ)
313-
add_library(GraphvizStaticDotLayoutPlugin IMPORTED STATIC)
314-
set_target_properties(
315-
GraphvizStaticDotLayoutPlugin
316-
PROPERTIES IMPORTED_LOCATION "${staticdotlayoutplugin_library}"
317-
INTERFACE_COMPILE_DEFINITIONS
318-
"CGRAPH_EXPORTS;GVC_EXPORTS;WITH_CGRAPH" # Fix export macro madness in Graphviz
319-
INTERFACE_INCLUDE_DIRECTORIES ${include_dir}
320-
INTERFACE_LINK_LIBRARIES "${link_libraries_absolute}"
321-
)
322-
else()
323-
# in case of a Graphviz dynamic library build, we need to install
324-
install(DIRECTORY ${install_dir}/ DESTINATION ".")
325-
endif()
326-
327-
set(GRAPHVIZ_FOUND TRUE)
243+
include_directories(${PROJECT_SOURCE_DIR}/src/fwd_headers)
244+
include_directories(${PROJECT_SOURCE_DIR}/3rdparty/graphviz/lib/common)
245+
include_directories(${PROJECT_SOURCE_DIR}/3rdparty/graphviz/lib/gvc)
246+
include_directories(${PROJECT_SOURCE_DIR}/3rdparty/graphviz/lib/pathplan)
247+
include_directories(${PROJECT_SOURCE_DIR}/3rdparty/graphviz/lib/cgraph)
248+
include_directories(${PROJECT_SOURCE_DIR}/3rdparty/graphviz/lib/cdt)
328249
endif()
329250

251+
add_subdirectory(3rdparty)
252+
330253
#
331254
# Compiler & linker settings
332255
#

examples/CMakeLists.txt

+10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
# Contact [email protected] if any conditions of this licensing are not clear to you.
1313
#
1414

15+
add_definitions(
16+
-DQT_NO_CAST_TO_ASCII
17+
-DQT_NO_CAST_FROM_ASCII
18+
-DQT_STRICT_ITERATORS
19+
-DQT_NO_URL_CAST_FROM_STRING
20+
-DQT_NO_CAST_FROM_BYTEARRAY
21+
-DQT_USE_QSTRINGBUILDER
22+
-DQT_USE_FAST_OPERATOR_PLUS
23+
)
24+
1525
include_directories(${CMAKE_CURRENT_BINARY_DIR})
1626

1727
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config-examples.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-examples.h)

src/CMakeLists.txt

+10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
# Contact [email protected] if any conditions of this licensing are not clear to you.
1313
#
1414

15+
add_definitions(
16+
-DQT_NO_CAST_TO_ASCII
17+
-DQT_NO_CAST_FROM_ASCII
18+
-DQT_STRICT_ITERATORS
19+
-DQT_NO_URL_CAST_FROM_STRING
20+
-DQT_NO_CAST_FROM_BYTEARRAY
21+
-DQT_USE_QSTRINGBUILDER
22+
-DQT_USE_FAST_OPERATOR_PLUS
23+
)
24+
1525
set(HAVE_GRAPHVIZ ${GRAPHVIZ_FOUND})
1626
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config-kdsme.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-kdsme.h)
1727

src/core/CMakeLists.txt

+15-8
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,7 @@ endif()
112112
generate_export_header(kdstatemachineeditor_core EXPORT_FILE_NAME kdsme_core_export.h BASE_NAME KDSME_CORE)
113113

114114
if(GRAPHVIZ_FOUND)
115-
if(WITH_STATIC_GRAPHVIZ)
116-
target_link_libraries(kdstatemachineeditor_core PRIVATE GraphvizStaticDotLayoutPlugin)
117-
endif()
118-
target_link_libraries(kdstatemachineeditor_core PRIVATE ${GRAPHVIZ_GVC_LIBRARY} ${GRAPHVIZ_CGRAPH_LIBRARY})
119-
if(WITH_INTERNAL_GRAPHVIZ)
120-
add_dependencies(kdstatemachineeditor_core GraphvizExternalProject)
121-
endif()
122-
target_include_directories(kdstatemachineeditor_core PRIVATE ${GRAPHVIZ_INCLUDE_DIR})
115+
target_link_libraries(kdstatemachineeditor_core PRIVATE cgraph gvc gvplugin_dot_layout)
123116
endif()
124117

125118
set(build_iface_dirs
@@ -133,6 +126,20 @@ target_include_directories(
133126

134127
set_target_properties(kdstatemachineeditor_core PROPERTIES OUTPUT_NAME "kdstatemachineeditor_core${KDSME_LIBRARY_QTID}")
135128

129+
if(WITH_INTERNAL_GRAPHVIZ)
130+
install(
131+
TARGETS gvc cgraph cdt gvplugin_dot_layout dotgen
132+
EXPORT KDSME_TARGETS
133+
${INSTALL_TARGETS_DEFAULT_ARGS}
134+
)
135+
if(WITH_STATIC_GRAPHVIZ)
136+
install(
137+
TARGETS common pack ortho pathplan label xdot
138+
EXPORT KDSME_TARGETS
139+
${INSTALL_TARGETS_DEFAULT_ARGS}
140+
)
141+
endif()
142+
endif()
136143
install(
137144
TARGETS kdstatemachineeditor_core
138145
EXPORT KDSME_TARGETS

0 commit comments

Comments
 (0)