Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve dependency handling #89

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
!COPYING
!README.md
!*.cmake
!*.cmake.in
*.local.cmake
64 changes: 64 additions & 0 deletions CMakeGraphVizOptions.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# This file is part of OpenOrienteering.

# Copyright 2021 Kai Pastor
#
# Redistribution and use is allowed according to the terms of the BSD license:
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# https://cmake.org/cmake/help/v3.17/module/CMakeGraphVizOptions.html

set(GRAPHVIZ_GRAPH_NAME Superbuild)

set(GRAPHVIZ_EXECUTABLES FALSE)
set(GRAPHVIZ_STATIC_LIBS FALSE)
set(GRAPHVIZ_SHARED_LIBS FALSE)
set(GRAPHVIZ_MODULE_LIBS FALSE)
set(GRAPHVIZ_INTERFACE_LIBS FALSE)
set(GRAPHVIZ_OBJECT_LIBS FALSE)
set(GRAPHVIZ_UNKNOWN_LIBS FALSE)
set(GRAPHVIZ_EXTERNAL_LIBS FALSE)
set(GRAPHVIZ_CUSTOM_TARGETS TRUE)

set(GRAPHVIZ_IGNORE_TARGETS
@GRAPHVIZ_IGNORE_TOOLCHAINS@
.*-ci
.*-dev
.*-multi-.*
.*-package
.*-patches-.*
.*-source
.*-toolchain
boost.*-bootstrap-.*
CI
common-licenses-.*
doc
iwyu-.*
qt5.*-openorienteering-git
superbuild-graphviz.*
toolchain-info.*
)

set(GRAPHVIZ_GENERATE_PER_TARGET TRUE)
set(GRAPHVIZ_GENERATE_DEPENDERS TRUE)
118 changes: 85 additions & 33 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is part of OpenOrienteering.

# Copyright 2016-2020 Kai Pastor
# Copyright 2016-2021 Kai Pastor
#
# Redistribution and use is allowed according to the terms of the BSD license:
#
Expand All @@ -27,7 +27,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

cmake_minimum_required(VERSION 3.3)
cmake_minimum_required(VERSION 3.10)

project(Superbuild C)

Expand Down Expand Up @@ -76,12 +76,6 @@ list(REMOVE_DUPLICATES SUPERBUILD_HANDLE_ENV)
set(SUPERBUILD_STEP_TARGETS "" CACHE STRING
"CMake ExternalProject step targets to be created")

if(DEFINED DISABLE_DEPENDENCIES)
message(WARNING "DISABLE_DEPENDENCIES is deprecated, use SUPERBUILD_DISABLE_DEPENDENCIES instead")
set(SUPERBUILD_DISABLE_DEPENDENCIES "${DISABLE_DEPENDENCIES}" CACHE BOOL
"Disable dependencies between binary packages")
unset(DISABLE_DEPENDENCIES CACHE)
endif()
set(SUPERBUILD_DISABLE_DEPENDENCIES FALSE CACHE BOOL
"Disable dependencies between binary packages")
mark_as_advanced(SUPERBUILD_DISABLE_DEPENDENCIES)
Expand All @@ -99,6 +93,35 @@ set(no_warn_unused


# Global utilities
function(_sb_configure_graphviz)
find_program(DOT_EXECUTABLE
NAMES "dot"
DOC "Path of the dot executable from Graphviz"
)
if(NOT DOT_EXECUTABLE)
return()
endif()

set(GRAPHVIZ_IGNORE_TOOLCHAINS )
get_property(toolchains GLOBAL PROPERTY SB_TOOLCHAINS)
foreach(toolchain ${toolchains})
get_property(system_name TARGET ${toolchain} PROPERTY SB_PACKAGE_SYSTEM_NAME)
list(APPEND GRAPHVIZ_IGNORE_TOOLCHAINS ".*-${system_name}")
endforeach()
configure_file(CMakeGraphVizOptions.cmake.in CMakeGraphVizOptions.cmake @ONLY)
add_custom_target(superbuild-graphviz
COMMAND "${CMAKE_COMMAND}" -E make_directory "graphviz"
COMMAND "${CMAKE_COMMAND}" -E chdir "graphviz"
"${CMAKE_COMMAND}" .. --graphviz=Superbuild.dot
)
add_custom_target(superbuild-graphviz-pdf
COMMAND "${DOT_EXECUTABLE}" -Tpdf -Grankdir=LR -oSuperbuild.pdf "graphviz/Superbuild.dot"
DEPENDS superbuild-graphviz
)
endfunction()



function(sb_install_dir var system_name)
if(DEFINED ${system_name}_INSTALL_DIR)
set(${var} "${${system_name}_INSTALL_DIR}" PARENT_SCOPE)
Expand Down Expand Up @@ -915,8 +938,10 @@ endfunction()
# Setup package dependencies
function(_sb_resolve_dependencies)
set(suffix "${ARGV0}")
get_property(source_packages GLOBAL PROPERTY SB_SOURCE_PACKAGES)
get_property(packages GLOBAL PROPERTY SB_PACKAGES)
foreach(package ${packages})
get_property(aliases GLOBAL PROPERTY SB_ALIASES)
foreach(package ${source_packages} ${packages})
if(NOT TARGET ${package}${suffix})
continue()
endif()
Expand All @@ -942,6 +967,9 @@ function(_sb_resolve_dependencies)
string(REGEX REPLACE "^source:" "" real_dependency ${dependency})
set(real_suffix "-source")
set(real_package ${package}-source)
if(NOT TARGET ${real_package})
string(REGEX REPLACE "-source-source$" "-source" real_package ${real_package})
endif()
else()
if(SUPERBUILD_DISABLE_DEPENDENCIES)
continue()
Expand All @@ -951,11 +979,22 @@ function(_sb_resolve_dependencies)
set(real_package ${package}${suffix})
endif()
get_property(default_version GLOBAL PROPERTY SB_DEFAULT_${real_dependency})
set(dependee NOTFOUND)
if(TARGET ${real_dependency}${real_suffix})
add_dependencies(${real_package} ${real_dependency}${real_suffix})
set(dependee ${real_dependency}${real_suffix})
elseif(TARGET ${real_dependency}-${default_version}${real_suffix})
add_dependencies(${real_package} ${real_dependency}-${default_version}${real_suffix})
elseif(NOT suffix)
set(dependee ${real_dependency}-${default_version}${real_suffix})
else()
foreach(alias ${aliases})
if ("${alias}" MATCHES "${real_dependency} ")
string(REPLACE "${real_dependency} " "" dependee "${alias}${real_suffix}")
break()
endif()
endforeach()
endif()
if(dependee)
add_dependencies(${real_package} ${dependee})
else()
message(SEND_ERROR "No rule to satisfy dependency '${dependency}' for package '${package}'")
endif()
endforeach()
Expand All @@ -981,6 +1020,7 @@ function(_sb_handle_toolchains)
list(APPEND virtual_packages ${package})
endif()
endforeach()
set_property(GLOBAL PROPERTY SB_TOOLCHAINS "${toolchains}")
foreach(toolchain ${toolchains})
foreach(package ${regular_packages})
_sb_make_toolchained_build(${package} ${toolchain})
Expand Down Expand Up @@ -1269,6 +1309,7 @@ function(superbuild_package)
SOURCE
BUILD
PACKAGE
PROVIDES
USING
EXECUTABLES
)
Expand Down Expand Up @@ -1306,6 +1347,9 @@ function(superbuild_package)
endif()
_sb_make_source(${package})

set(binary_dependencies "${SB_PACKAGE_DEPENDS}")
list(FILTER binary_dependencies EXCLUDE REGEX "^source:.*")

if(DEFINED SB_PACKAGE_BUILD
OR "${package}" STREQUAL "toolchain-info")
if(TARGET ${package}-source)
Expand Down Expand Up @@ -1381,28 +1425,41 @@ function(superbuild_package)
add_dependencies(${executable}-${SB_PACKAGE_VERSION} ${package})
set(keyword "")
endforeach()
elseif(DEFINED SB_PACKAGE_DEPENDS)
elseif(binary_dependencies)
add_custom_target(${package})
else()
elseif(NOT DEFINED SB_PACKAGE_DEPENDS)
return()
endif()

if(TARGET ${package})
# Publish package via global properties
set(target ${package})
set_property(GLOBAL APPEND PROPERTY SB_PACKAGES ${package})

string(REPLACE "-" "." version ${SB_PACKAGE_VERSION})
get_property(default_version GLOBAL PROPERTY SB_DEFAULT_${SB_PACKAGE_NAME})
string(REPLACE "-" "." default_version "${default_version}")
if(NOT SB_PACKAGE_NO_DEFAULT
AND (NOT default_version
OR version VERSION_GREATER default_version))
set_property(GLOBAL PROPERTY SB_DEFAULT_${SB_PACKAGE_NAME} ${SB_PACKAGE_VERSION})
endif()

# Publish provided aliases
foreach(alias ${SB_PACKAGE_PROVIDES})
set_property(GLOBAL APPEND PROPERTY SB_ALIASES "${alias} ${package}")
endforeach()
else()
# Publish source package via global properties
set(target ${package}-source)
set_property(GLOBAL APPEND PROPERTY SB_SOURCE_PACKAGES ${target})
endif()

# Publish package properties
set_property(TARGET ${package} PROPERTY SB_PACKAGE_FILE ${CMAKE_CURRENT_LIST_FILE})
set_property(TARGET ${target} PROPERTY SB_PACKAGE_FILE ${CMAKE_CURRENT_LIST_FILE})
foreach(arg ${sb_options} ${sb_one_value_args} ${sb_multi_value_args})
set_property(TARGET ${package} PROPERTY SB_PACKAGE_${arg} ${SB_PACKAGE_${arg}})
set_property(TARGET ${target} PROPERTY SB_PACKAGE_${arg} ${SB_PACKAGE_${arg}})
endforeach()

# Publish package via global properties
set_property(GLOBAL APPEND PROPERTY SB_PACKAGES ${package})
string(REPLACE "-" "." version ${SB_PACKAGE_VERSION})
get_property(default_version GLOBAL PROPERTY SB_DEFAULT_${SB_PACKAGE_NAME})
string(REPLACE "-" "." default_version "${default_version}")
if(NOT SB_PACKAGE_NO_DEFAULT
AND (NOT default_version
OR version VERSION_GREATER default_version))
set_property(GLOBAL PROPERTY SB_DEFAULT_${SB_PACKAGE_NAME} ${SB_PACKAGE_VERSION})
endif()
endfunction()


Expand All @@ -1417,12 +1474,6 @@ endforeach()
add_custom_target(doc SOURCES ${documentation})
add_custom_target(CI SOURCES ${ci})

# ExternalPackage < 3.8.0 has bug with UPDATE_DISCONNECTED
if(NOT CMAKE_VERSION VERSION_LESS 3.8.0)
option(SUPERBUILD_UPDATE_DISCONNECTED "Skip package update steps" ON)
set_directory_properties(PROPERTIES EP_UPDATE_DISCONNECTED "${SUPERBUILD_UPDATE_DISCONNECTED}")
endif()

_sb_create_main_c()
_sb_create_default_toolchain()
_sb_create_host_toolchain()
Expand All @@ -1433,3 +1484,4 @@ _sb_read_packages()
_sb_create_toolchain_info() # after package reading, affected by toolchains
_sb_resolve_dependencies()
_sb_handle_toolchains()
_sb_configure_graphviz()
16 changes: 12 additions & 4 deletions android-toolchain-ndk-r19c.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,20 @@ else()
set(ANDROID_COMPILE_SDK android-28)
endif()

if(ANDROID_SDK_ROOT AND ANDROID_NDK_ROOT)
set(sdk_host "") # external SDK and NDK
elseif(APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
if(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
message(FATAL_ERROR "System processor must be x86_64")
elseif(APPLE)
set(sdk_host "darwin")
elseif(UNIX AND NOT APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
elseif(UNIX)
set(sdk_host "linux")
elseif(WIN32)
set(sdk_host "windows") # Untested
else()
message(FATAL_ERROR "Unsupported sdk_host")
endif()

if(sdk_host AND NOT sdk_host STREQUAL "windows")
# Not relying on ANDROID_SDK_ROOT / ANDROID_NDK_ROOT
elseif(NOT ANDROID_SDK_ROOT)
message(FATAL_ERROR "ANDROID_SDK_ROOT must be set to an external SDK")
elseif(NOT ANDROID_NDK_ROOT)
Expand Down
3 changes: 2 additions & 1 deletion ci/azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is part of OpenOrienteering.

# Copyright 2019-2020 Kai Pastor
# Copyright 2019-2021 Kai Pastor
#
# Redistribution and use is allowed according to the terms of the BSD license:
#
Expand Down Expand Up @@ -65,6 +65,7 @@ jobs:
variables:
IMAGE_NAME: 'ubuntu-18.04'
SUPERBUILD_INSTALL_DIR: $(HOME)/superbuild
WITH_GRAPHVIZ: true
pool:
vmImage: '$(IMAGE_NAME)'
steps:
Expand Down
13 changes: 12 additions & 1 deletion ci/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is part of OpenOrienteering.

# Copyright 2019-2020 Kai Pastor
# Copyright 2019-2021 Kai Pastor
#
# Redistribution and use is allowed according to the terms of the BSD license:
#
Expand Down Expand Up @@ -84,3 +84,14 @@ steps:
-- ${{ parameters.buildArgs }}
timeoutInMinutes: 210
displayName: 'Build'

- task: CMake@1
inputs:
workingDirectory: 'build'
cmakeArgs: >
$(CMAKE_WRAPPING)
--build .
--target superbuild-graphviz-pdf
timeoutInMinutes: 5
condition: and(succeeded(), in(variables['WITH_GRAPHVIZ'], '1', 'on', 'true', 'yes'))
displayName: 'Generate dependencies documentation'
18 changes: 17 additions & 1 deletion ci/publish.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is part of OpenOrienteering.

# Copyright 2019 Kai Pastor
# Copyright 2019-2021 Kai Pastor
#
# Redistribution and use is allowed according to the terms of the BSD license:
#
Expand Down Expand Up @@ -76,3 +76,19 @@ steps:
condition: and(succeeded(), in(variables['CREATE_ARTIFACTS'], '1', 'on', 'true', 'yes'))
displayName: 'Publish binary artifacts'

- bash: |
set -e
set -x
test -f build/Superbuild.pdf || exit 1
rm -Rf "${BUILD_ARTIFACTSTAGINGDIRECTORY}/dependencies"
mkdir "${BUILD_ARTIFACTSTAGINGDIRECTORY}/dependencies"
cp build/Superbuild.pdf "${BUILD_ARTIFACTSTAGINGDIRECTORY}/dependencies/"
condition: and(succeeded(), in(variables['WITH_GRAPHVIZ'], '1', 'on', 'true', 'yes'))
displayName: 'Prepare dependencies documentation publishing'

- task: PublishPipelineArtifact@0
inputs:
artifactName: 'superbuild-dependencies'
targetPath: $(Build.ArtifactStagingDirectory)/dependencies
condition: and(succeeded(), in(variables['WITH_GRAPHVIZ'], '1', 'on', 'true', 'yes'))
displayName: 'Publish dependencies documentation'
7 changes: 1 addition & 6 deletions giflib-5.1.9.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ superbuild_package(
superbuild_package(
NAME giflib
VERSION ${patch_version}_${openorienteering_version}
PROVIDES libgif
DEPENDS
source:giflib-patches-${patch_version}
source:giflib-openorienteering-${openorienteering_version}
Expand Down Expand Up @@ -106,9 +107,3 @@ superbuild_package(
>
]]
)

superbuild_package(
NAME libgif
VERSION ${patch_version}
DEPENDS giflib-${patch_version}_${openorienteering_version}
)
Loading