Skip to content

Commit

Permalink
Add graphviz as submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
dantti committed Feb 9, 2024
1 parent a30ef1f commit 02cb480
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 114 deletions.
32 changes: 21 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,36 @@ jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest
#- windows-latest
#- macos-latest
build_type:
- Debug
- Release
#- Release
config:
- qt_version: "5.15"
qt_arch: win64_mingw81
- qt_version: "6.4.*"
qt_modules: qtscxml
qt_arch: win64_mingw
#- qt_version: "6.4.*"
#qt_modules: qtscxml
#qt_arch: win64_mingw
include:
- os: ubuntu-latest
build_type:
Debug
config:
qt_version: "6.6.*"
qt_modules: qtscxml
cmake_arg: "-DWITH_INTERNAL_GRAPHVIZ=ON"

steps:
- name: Install Dependencies on Linux
- name: Install Dependencies on Linux #removed libgraphviz-dev
if: ${{ runner.os == 'Linux' }}
run: |
sudo apt update -qq
sudo apt install -y doxygen libgraphviz-dev
sudo apt install -y doxygen libgtk2.0-dev
- name: Install Dependencies on Windows (graphviz was built with MinGW)
if: ${{ runner.os == 'Windows' }}
Expand All @@ -47,7 +55,7 @@ jobs:
if: ${{ runner.os == 'macOS' }}
run: brew install graphviz

- name: Install Qt with options and default aqtversion (Linux/macOS)
- name: Install Qt ${{ matrix.config.qt_version }} with options and default aqtversion (Linux/macOS)
if: ${{ runner.os != 'Windows' }}
uses: jurplel/install-qt-action@v3
with:
Expand Down Expand Up @@ -76,20 +84,22 @@ jobs:

- name: Checkout sources
uses: actions/checkout@v4
with:
submodules: recursive

- name: Fetch Git submodule
run: git submodule update --init --recursive

- name: Configure project
run: >
cmake -S . -B ./build -G Ninja
--warn-uninitialized -Werror=dev
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DCMAKE_PREFIX_PATH='C:\Program Files\Graphviz'
-DBUILD_QT6=${{ startsWith(matrix.config.qt_version, '6.') }}
-DBUILD_TESTS=${{ matrix.build_type == 'Debug' }}
-DBUILD_EXAMPLES=ON
-DBUILD_DOCS=${{ matrix.build_type == 'Debug' && runner.os == 'Linux' }}
${{ matrix.config.cmake_arg }}
- name: Build Project
run: cmake --build ./build
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "3rdparty/graphviz"]
path = 3rdparty/graphviz
url = https://gitlab.com/graphviz/graphviz.git
2 changes: 1 addition & 1 deletion .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Copyright: Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
License: LGPL-2.1-only OR LicenseRef-KDAB-KDStateMachineEditor

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

Expand Down
32 changes: 32 additions & 0 deletions 3rdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# This file is part of the KDAB State Machine Editor Library.
#
# SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
# Author: Daniel Nicoletti <[email protected]>
#
# SPDX-License-Identifier: LGPL-2.1-only OR LicenseRef-KDAB-KDStateMachineEditor
#
# Licensees holding valid commercial KDAB State Machine Editor Library
# licenses may use this file in accordance with the KDAB State Machine Editor
# Library License Agreement provided with the Software.
#
# Contact [email protected] if any conditions of this licensing are not clear to you.
#

if(WITH_INTERNAL_GRAPHVIZ)
# Function creates extra scope to keep these variables local
function(add_graphviz_subdirectory)
#TODO check if there are unneeded features to disable

if(WITH_STATIC_GRAPHVIZ)
set(BUILD_SHARED_LIBS OFF)
endif()
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/graphviz/CMakeLists.txt")
message(FATAL_ERROR "Please do git submodule update --init --recursive")
endif()

add_subdirectory(graphviz)
endfunction()

add_graphviz_subdirectory()
endif()
1 change: 1 addition & 0 deletions 3rdparty/graphviz
Submodule graphviz added at 6e66f9
104 changes: 5 additions & 99 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,6 @@ project(
VERSION 1.99.50
)

add_definitions(
-DQT_NO_CAST_TO_ASCII
-DQT_NO_CAST_FROM_ASCII
-DQT_STRICT_ITERATORS
-DQT_NO_URL_CAST_FROM_STRING
-DQT_NO_CAST_FROM_BYTEARRAY
-DQT_USE_QSTRINGBUILDER
-DQT_USE_FAST_OPERATOR_PLUS
)

set(KDSME_SOVERSION "2") #means the 2.x ABI is frozen. ABI changes will must go to version 3

include(FeatureSummary)
Expand Down Expand Up @@ -217,7 +207,9 @@ set(INSTALL_TARGETS_DEFAULT_ARGS

# search for Graphviz
set(GRAPHVIZ_MIN_VERSION "2.30.1")
find_package(Graphviz)
if(NOT DEFINED WITH_INTERNAL_GRAPHVIZ)
find_package(Graphviz)
endif()
set_package_properties(
Graphviz PROPERTIES
TYPE RECOMMENDED
Expand All @@ -231,101 +223,15 @@ if(GRAPHVIZ_FOUND)
elseif(NOT CMAKE_SYSTEM_NAME STREQUAL QNX)
message(STATUS "Auto-enabling internal Graphviz build, since no installed version is available")
set(WITH_INTERNAL_GRAPHVIZ_DEFAULT ON)
set(GRAPHVIZ_FOUND ON)
endif()

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

set(WITH_STATIC_GRAPHVIZ OFF) # Whether the Graphviz build we're using is static or not -- WIP

if(WITH_INTERNAL_GRAPHVIZ)
# CMake is really awful here...
set(source_dir ${CMAKE_CURRENT_BINARY_DIR}/graphviz-src)
set(install_dir ${CMAKE_CURRENT_BINARY_DIR}/graphviz-install)

# work-around: https://cmake.org/Bug/view.php?id=15052
set(include_dir "${install_dir}/include")
file(MAKE_DIRECTORY ${include_dir})
set(GRAPHVIZ_INCLUDE_DIR ${include_dir})

if(UNIX OR WITH_STATIC_GRAPHVIZ)
set(libfolder "lib")
else()
set(libfolder "bin")
endif()

if(WITH_STATIC_GRAPHVIZ)
set(staticdotlayoutplugin_library
"${install_dir}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}gvplugin_dot_layout${CMAKE_STATIC_LIBRARY_SUFFIX}"
)
set(link_libraries_absolute)
foreach(link_library "xdot;gvc;cgraph;pathplan")
list(APPEND link_libraries_absolute
${install_dir}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}${link_library}${CMAKE_STATIC_LIBRARY_SUFFIX}
)
endforeach()
else()
set(GRAPHVIZ_CGRAPH_LIBRARY
"${install_dir}/${libfolder}/${CMAKE_SHARED_LIBRARY_PREFIX}cgraph${CMAKE_SHARED_LIBRARY_SUFFIX}"
)
set(GRAPHVIZ_GVC_LIBRARY
"${install_dir}/${libfolder}/${CMAKE_SHARED_LIBRARY_PREFIX}gvc${CMAKE_SHARED_LIBRARY_SUFFIX}"
)
set(link_libraries_absolute "${GRAPHVIZ_CGRAPH_LIBRARY};${GRAPHVIZ_GVC_LIBRARY}")
endif()

set(win_build_utilities ${source_dir}/windows/dependencies/graphviz-build-utilities)
string(TIMESTAMP graphvizDate)
set(GRAPHVIZ_MAJOR_VERSION 2)
set(GRAPHVIZ_MINOR_VERSION 48)
set(GRAPHVIZ_PATCH_VERSION 0)
set(graphvizVersion "${GRAPHVIZ_MAJOR_VERSION}.${GRAPHVIZ_MINOR_VERSION}.${GRAPHVIZ_PATCH_VERSION}")
# cmake-lint: disable=C0301
externalproject_add(
GraphvizExternalProject
GIT_REPOSITORY "https://gitlab.com/graphviz/graphviz.git"
GIT_TAG ${graphvizVersion}
GIT_PROGRESS 1
USES_TERMINAL_DOWNLOAD
TRUE # needed for Ninja so we can see the Git progress (cf. https://gitlab.kitware.com/cmake/cmake/-/issues/18238)
CMAKE_ARGS
-DVERSION=${graphvizVersion}
-DDATE=${graphvizDate}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_C_COMPILER_AR=${CMAKE_C_COMPILER_AR}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_CXX_COMPILER_AR=${CMAKE_CXX_COMPILER_AR}
-DCMAKE_INSTALL_PREFIX=${install_dir}
$<$<BOOL:${WIN32}>:-DCMAKE_IGNORE_PATH="C:/Strawberry/c/bin">
$<$<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>
BUILD_COMMAND "" # skip, make install is enough
SOURCE_DIR ${source_dir}
INSTALL_DIR ${install_dir}
INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install
# Note: BUILD_BYPRODUCTS only available since CMake 3.2
# Needed to make ExternalProject_Add in combination with the Ninja generator work
# Also see: https://cmake.org/pipermail/cmake/2015-April/060234.html
BUILD_BYPRODUCTS ${staticdotlayoutplugin_library} ${link_libraries_absolute}
)

if(WITH_STATIC_GRAPHVIZ)
add_library(GraphvizStaticDotLayoutPlugin IMPORTED STATIC)
set_target_properties(
GraphvizStaticDotLayoutPlugin
PROPERTIES IMPORTED_LOCATION "${staticdotlayoutplugin_library}"
INTERFACE_COMPILE_DEFINITIONS
"CGRAPH_EXPORTS;GVC_EXPORTS;WITH_CGRAPH" # Fix export macro madness in Graphviz
INTERFACE_INCLUDE_DIRECTORIES ${include_dir}
INTERFACE_LINK_LIBRARIES "${link_libraries_absolute}"
)
else()
# in case of a Graphviz dynamic library build, we need to install
install(DIRECTORY ${install_dir}/ DESTINATION ".")
endif()

set(GRAPHVIZ_FOUND TRUE)
endif()
add_subdirectory(3rdparty)

#
# Compiler & linker settings
Expand Down
10 changes: 10 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
# Contact [email protected] if any conditions of this licensing are not clear to you.
#

add_definitions(
-DQT_NO_CAST_TO_ASCII
-DQT_NO_CAST_FROM_ASCII
-DQT_STRICT_ITERATORS
-DQT_NO_URL_CAST_FROM_STRING
-DQT_NO_CAST_FROM_BYTEARRAY
-DQT_USE_QSTRINGBUILDER
-DQT_USE_FAST_OPERATOR_PLUS
)

include_directories(${CMAKE_CURRENT_BINARY_DIR})

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config-examples.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-examples.h)
Expand Down
10 changes: 10 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
# Contact [email protected] if any conditions of this licensing are not clear to you.
#

add_definitions(
-DQT_NO_CAST_TO_ASCII
-DQT_NO_CAST_FROM_ASCII
-DQT_STRICT_ITERATORS
-DQT_NO_URL_CAST_FROM_STRING
-DQT_NO_CAST_FROM_BYTEARRAY
-DQT_USE_QSTRINGBUILDER
-DQT_USE_FAST_OPERATOR_PLUS
)

set(HAVE_GRAPHVIZ ${GRAPHVIZ_FOUND})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config-kdsme.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-kdsme.h)

Expand Down
3 changes: 0 additions & 3 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@ if(GRAPHVIZ_FOUND)
target_link_libraries(kdstatemachineeditor_core PRIVATE GraphvizStaticDotLayoutPlugin)
endif()
target_link_libraries(kdstatemachineeditor_core PRIVATE ${GRAPHVIZ_GVC_LIBRARY} ${GRAPHVIZ_CGRAPH_LIBRARY})
if(WITH_INTERNAL_GRAPHVIZ)
add_dependencies(kdstatemachineeditor_core GraphvizExternalProject)
endif()
target_include_directories(kdstatemachineeditor_core PRIVATE ${GRAPHVIZ_INCLUDE_DIR})
endif()

Expand Down

0 comments on commit 02cb480

Please sign in to comment.