Skip to content

Commit

Permalink
Better dependency handling and ci
Browse files Browse the repository at this point in the history
  • Loading branch information
tamasmeszaros committed Oct 23, 2019
1 parent 6254a19 commit cc69680
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 28 deletions.
57 changes: 49 additions & 8 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,75 @@
# see https://hub.docker.com/_/gcc/
image: meszarosq/phoenix:latest

build:
stages:
- build
- test

build-clang:
stage: build
tags:
- linux
- clang
# instead of calling g++ directly you can also use some build toolkit like make
# install the necessary build tools when needed
before_script:
- apt update && apt -y install cmake ninja-build # libpolyclipping-dev libnlopt-cxx-dev libboost-dev
- apt update && apt -y install cmake ninja-build git subversion clang-7 # libpolyclipping-dev libnlopt-cxx-dev libboost-dev
script:
- mkdir -p build && cd build && cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release -DLIBNEST2D_BUILD_EXAMPLES=ON -DLIBNEST2D_BUILD_UNITTESTS=ON && cmake --build . --target all
- mkdir -p build-clang
- cd build-clang
- cmake .. -GNinja -DCMAKE_CXX_COMPILER=clang++-7 -DCMAKE_C_COMPILER=clang-7 -DCMAKE_BUILD_TYPE=Release -DLIBNEST2D_BUILD_EXAMPLES=ON -DLIBNEST2D_BUILD_UNITTESTS=ON -DRP_ENABLE_DOWNLOADING=ON
- cmake --build . --target all
artifacts:
paths:
- build/tests/tests_clipper_nlopt
- build-clang/tests/tests_clipper_nlopt
# depending on your build setup it's most likely a good idea to cache outputs to reduce the build time
cache:
paths:
- "build/dependencies/*"
- "build-clang/dependencies/*"

build-gcc:
stage: build
tags:
- linux
- gcc
# instead of calling g++ directly you can also use some build toolkit like make
# install the necessary build tools when needed
before_script:
- apt update && apt -y install cmake ninja-build git subversion g++ # libpolyclipping-dev libnlopt-cxx-dev libboost-dev
script:
- mkdir -p build-gcc
- cd build-gcc
- cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release -DLIBNEST2D_BUILD_EXAMPLES=ON -DLIBNEST2D_BUILD_UNITTESTS=ON -DRP_ENABLE_DOWNLOADING=ON
- cmake --build . --target all
artifacts:
paths:
- build-gcc/tests/tests_clipper_nlopt
# depending on your build setup it's most likely a good idea to cache outputs to reduce the build time
cache:
paths:
- "build-gcc/dependencies/*"

# run tests using the binary built before
test:
test-clang:
stage: test
tags:
- linux
#before_script:
# - apt update && apt -y install libpolyclipping22 libnlopt-cxx0 libnlopt0
script:
- cd build-clang/tests && ./tests_clipper_nlopt -r "junit" --out report-clang.xml
artifacts:
reports:
junit: build-clang/tests/report-clang.xml

test-gcc:
stage: test
tags:
- linux
#before_script:
# - apt update && apt -y install libpolyclipping22 libnlopt-cxx0 libnlopt0
script:
- cd build/tests && ./tests_clipper_nlopt -r "junit" --out report.xml
- cd build-gcc/tests && ./tests_clipper_nlopt -r "junit" --out report-gcc.xml
artifacts:
reports:
junit: build/tests/report.xml
junit: build-gcc/tests/report-gcc.xml
28 changes: 15 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,34 +108,34 @@ endif()
include(CMakePackageConfigHelpers)

write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/cmakeexports/Libnest2DConfigVersion.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmakeexports/${PROJECT_NAME}ConfigVersion.cmake"
VERSION 1.0
COMPATIBILITY AnyNewerVersion
)

install(TARGETS libnest2d libnest2d_headeronly ${LIBNAME}
EXPORT Libnest2DTargets
EXPORT ${PROJECT_NAME}Targets
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
INCLUDES DESTINATION include)

export(EXPORT Libnest2DTargets
FILE "${CMAKE_CURRENT_BINARY_DIR}/cmakeexports/Libnest2DTargets.cmake"
NAMESPACE Libnest2D::)
export(EXPORT ${PROJECT_NAME}Targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/cmakeexports/${PROJECT_NAME}Targets.cmake"
NAMESPACE ${PROJECT_NAME}::)

configure_file(cmake_modules/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/cmakeexports/Libnest2DConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmakeexports/${PROJECT_NAME}Config.cmake"
@ONLY
)

set(ConfigPackageLocation lib/cmake/Libnest2D)
set(ConfigPackageLocation lib/cmake/${PROJECT_NAME})

install(EXPORT Libnest2DTargets
install(EXPORT ${PROJECT_NAME}Targets
FILE
Libnest2DTargets.cmake
${PROJECT_NAME}Targets.cmake
NAMESPACE
Libnest2D::
${PROJECT_NAME}::
DESTINATION
${ConfigPackageLocation}
)
Expand All @@ -154,8 +154,8 @@ endforeach()

install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/cmakeexports/Libnest2DConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmakeexports/Libnest2DConfigVersion.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmakeexports/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmakeexports/${PROJECT_NAME}ConfigVersion.cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/FindClipper.cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/FindNLopt.cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/FindTBB.cmake"
Expand All @@ -165,5 +165,7 @@ install(
Devel
)

message(STATUS "RP_USED_PACKAGES: ${RP_USED_PACKAGES}")
rp_install_versions_file(${ConfigPackageLocation})

message(STATUS "Configuration depends on packages:${_pkgstr}")

11 changes: 11 additions & 0 deletions cmake_modules/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
include(CMakeFindDependencyMacro)

if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/RPPackageVersions.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/RPPackageVersions.cmake)
endif()

set(USED_PACKAGES @RP_USED_PACKAGES@)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})

set(TBB_STATIC @TBB_STATIC@)

foreach(package ${USED_PACKAGES})
if(NOT ${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
if(${${package}_VERSION})
set(_verstr "requested version: ${${package}_VERSION}")
endif()
message(STATUS "Using dependent package: ${package} ${_verstr}")
endif()
find_dependency(${package} ${${package}_VERSION})
endforeach()

Expand Down
23 changes: 18 additions & 5 deletions cmake_modules/RequirePackage.cmake
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# RP Package manager default install dir will be set globally
set(RP_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/dependencies CACHE STRING "Dependencies location")
set(RP_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Build configuration for the dependencies for single config generators")
option(RP_DISABLE_DOWNLOADING "Disable downloading of packages effectively falling back to find_package functionality" OFF)
option(RP_ENABLE_DOWNLOADING "Enable downloading of bundled packages if not found in system." OFF)
set(RP_REPOSITORY_DIR ${PROJECT_SOURCE_DIR}/external CACHE STRING "Package repository location")

set(RP_BUILD_PATH ${CMAKE_BINARY_DIR}/rp_packages_build CACHE STRING "Binary dir for downloaded package builds")

mark_as_advanced(RP_BUILD_PATH)

# This variable is used to gather dependencies for export (find_dependency will be called for each package)
# A list of the requested packages from all require_package calls.
set(RP_USED_PACKAGES "" CACHE INTERNAL "")
Expand Down Expand Up @@ -45,8 +49,6 @@ function(download_package)
set(RP_ARGS_VERSION ${ARGV1})
endif()

set(RP_BUILD_PATH ${CMAKE_BINARY_DIR}/rp_packages_build)

file(MAKE_DIRECTORY ${RP_BUILD_PATH})

# Hide output if requested
Expand Down Expand Up @@ -135,7 +137,7 @@ macro(require_package RP_ARGS_PACKAGE RP_ARGS_VERSION)
endif ()

if(NOT ${RP_ARGS_PACKAGE}_FOUND )
if (NOT RP_DISABLE_DOWNLOADING)
if (RP_ENABLE_DOWNLOADING)
download_package(${RP_ARGS_PACKAGE} ${RP_ARGS_VERSION}
${_QUIET}
${RP_ARGS_UNPARSED_ARGUMENTS} )
Expand All @@ -148,6 +150,17 @@ macro(require_package RP_ARGS_PACKAGE RP_ARGS_VERSION)
if (NOT RP_ARGS_NO_EXPORT)
list(APPEND RP_USED_PACKAGES ${RP_ARGS_PACKAGE})
set(RP_USED_PACKAGES "${RP_USED_PACKAGES}" CACHE INTERNAL "")
set(RP_${RP_ARGS_PACKAGE}_VERSION ${RP_ARGS_VERSION} CACHE INTERNAL "")
endif()

endmacro()
endmacro()

function(rp_install_versions_file dest)
set(_out "")
set(_fname ${RP_BUILD_PATH}/RPPackageVersions.cmake)
foreach(p ${RP_USED_PACKAGES})
set(_out "${_out}set(${p}_VERSION ${RP_${p}_VERSION})\n")
endforeach()
file(WRITE ${_fname} ${_out})
install(FILES ${_fname} DESTINATION ${dest})
endfunction()
2 changes: 0 additions & 2 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ if (NOT RP_PACKAGES)
subdirlist(RP_PACKAGES ${CMAKE_CURRENT_LIST_DIR})
endif()

get_directory_property(hasParent PARENT_DIRECTORY)

if (NOT RP_PACKAGE)
add_custom_target(rp ALL)
foreach(PACKAGE IN ITEMS ${RP_PACKAGES})
Expand Down

0 comments on commit cc69680

Please sign in to comment.