From 5b267a80e38733695a8398c3db342a17b01dce66 Mon Sep 17 00:00:00 2001 From: Silvio Date: Tue, 17 Dec 2024 15:31:58 +0100 Subject: [PATCH 1/2] Add nodeps CMake preset and BUILD_WITHOUT_DEPENDENCIES CMake option --- .github/workflows/ci-nodeps.yml | 31 ++++++++++++++++++++++++ CMakeLists.txt | 42 +++++++++++++++++++++++++-------- CMakePresets.json | 38 +++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/ci-nodeps.yml create mode 100644 CMakePresets.json diff --git a/.github/workflows/ci-nodeps.yml b/.github/workflows/ci-nodeps.yml new file mode 100644 index 0000000000..afbf54c019 --- /dev/null +++ b/.github/workflows/ci-nodeps.yml @@ -0,0 +1,31 @@ +name: CI Workflow with nodeps CMake preset + +on: + push: + pull_request: + workflow_dispatch: + schedule: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Install deps + run: | + sudo apt-get install -y cmake build-essential + + - name: Configure + run: | + cmake --preset nodeps + + - name: Build + run: | + cmake --build --preset nodeps + + - name: Install + run: | + cd build + cmake --install ./build diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ce93e95d8..5739b0bbf3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,20 +4,40 @@ cmake_minimum_required(VERSION 3.12) project(robots-configuration VERSION 2.7.0) -find_package(YCM REQUIRED) -find_package(YARP REQUIRED) -find_package(ICUBcontrib REQUIRED) - -list(APPEND CMAKE_MODULE_PATH ${ICUBCONTRIB_MODULE_PATH}) -include(ICUBcontribOptions) -include(ICUBcontribHelpers) - +option(BUILD_WITHOUT_DEPENDENCIES "If enabled, permit to install robots-configuration without any dependency on YCM, YARP or ICUBcontrib" OFF) option(INSTALL_ALL_ROBOTS "Enable installation of all robots" OFF) set(ROBOT_NAME "$ENV{YARP_ROBOT_NAME}" CACHE PATH "Name of your robot") set(ROBOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${ROBOT_NAME}") option(BUILD_TESTING "If ON compile tests" OFF) -icubcontrib_set_default_prefix() + +if(NOT BUILD_WITHOUT_DEPENDENCIES) + find_package(YCM REQUIRED) + find_package(YARP REQUIRED) + find_package(ICUBcontrib REQUIRED) + + list(APPEND CMAKE_MODULE_PATH ${ICUBCONTRIB_MODULE_PATH}) + include(ICUBcontribOptions) + include(ICUBcontribHelpers) + icubcontrib_set_default_prefix() +else() + if(BUILD_TESTING) + message(FATAL_ERROR "BUILD_TESTING=ON requires BUILD_WITHOUT_DEPENDENCIES=OFF") + endif() + + # If we do not have dependencies, we just need to define yarp_install as a simple redirect + # to CMake's builtin install + function(yarp_install) + install(${ARGN}) + endfunction() + + # The only use of ICUBContrib beside setting the default install prefix is to + # set ICUBCONTRIB_ROBOTS_INSTALL_DIR + include(GNUInstallDirs) + # CMAKE_INSTALL_DATAROOTDIR is just a fancy (and platform independent) way to refer to share, + # see https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html + set(ICUBCONTRIB_ROBOTS_INSTALL_DIR "${CMAKE_INSTALL_DATAROOTDIR}/ICUBcontrib/robots") +endif() if(UNIX) find_program(BASH_PROGRAM bash) @@ -111,4 +131,6 @@ else() endif() endif() -icubcontrib_add_uninstall_target() +if(NOT BUILD_WITHOUT_DEPENDENCIES) + icubcontrib_add_uninstall_target() +endif() \ No newline at end of file diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000000..00238e7b47 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,38 @@ +{ + "version": 3, + "cmakeMinimumRequired": { + "major": 3, + "minor": 22, + "patch": 1 + }, + "configurePresets": [ + { + "name": "default", + "displayName": "Default Configuration", + "binaryDir": "${sourceDir}/build", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + }, + { + "name": "nodeps", + "inherits": "default", + "displayName": "Configuration that does not depend on YARP, ICUBContrib or YCM", + "installDir": "${sourceDir}/build/install", + "cacheVariables": { + "INSTALL_ALL_ROBOTS": "ON", + "BUILD_WITHOUT_DEPENDENCIES": "ON" + } + } + ], + "buildPresets": [ + { + "name": "default", + "configurePreset": "default" + }, + { + "name": "nodeps", + "configurePreset": "nodeps" + } + ] +} From 8e961adb86ee6c6378d4223470287b5cc0a77e46 Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Tue, 17 Dec 2024 16:34:06 +0100 Subject: [PATCH 2/2] Add missing newline Co-authored-by: Stefano Dafarra --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5739b0bbf3..4db6e9acff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -133,4 +133,4 @@ endif() if(NOT BUILD_WITHOUT_DEPENDENCIES) icubcontrib_add_uninstall_target() -endif() \ No newline at end of file +endif()