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

Feature/remove fetch content #179

Open
wants to merge 2 commits into
base: New-Antares-Emulator-2
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion .github/workflows/centos7-system-deps-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
run: |
git clone $GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git -b $GITHUB_REF_NAME .

- uses: ./.github/workflows/install_minizip
- name: Init submodule
run: |
git submodule update --init --recursive src/antares-deps
Expand All @@ -50,7 +51,7 @@ jobs:
source /opt/rh/devtoolset-9/enable
#git 2.x must be enabled for Coin compilation with CMake ExternalProject_Add
source /opt/rh/rh-git227/enable
cmake -B _build -S src -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON
cmake -B _build -S src -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DCMAKE_PREFIX_PATH="../install"

- name: Build
run: |
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/centos7.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
yum install -y devtoolset-10-gcc*

- uses: ./.github/workflows/install-cmake-328
- uses: ./.github/workflows/install_minizip

- name: Init submodule
run: |
Expand Down Expand Up @@ -90,7 +91,7 @@ jobs:
-DBUILD_not_system=OFF \
-DBUILD_TOOLS=ON \
-DBUILD_UI=OFF \
-DCMAKE_PREFIX_PATH=${{ env.ORTOOLSDIR }}/install \
-DCMAKE_PREFIX_PATH="../install;${{ env.ORTOOLS_DIR }}/install" \

- name: Build
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/install-cmake-328/action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Install cmake 3.28 using devtoolset 10"
name: "Install cmake 3.28 using devtoolset 10 if possible"
description: "Download and install system wide cmake 3.28"

runs:
Expand All @@ -7,7 +7,7 @@ runs:
- name: Build cmake
shell: bash
run: |
source /opt/rh/devtoolset-10/enable
source /opt/rh/devtoolset-10/enable || true # Ignore error if devtoolset-10 is not available
yum -y install openssl-devel
wget https://github.com/Kitware/CMake/releases/download/v3.28.2/cmake-3.28.2.tar.gz
tar -xvf cmake-3.28.2.tar.gz
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/install_minizip/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: "Install minizip"
description: "Download and install system wide minizip library"

runs:
using: "composite"
steps:
- name: Build minizip
shell: bash
run: |
source /opt/rh/devtoolset-10/enable || true # Ignore error if devtoolset-10 is not available
wget https://github.com/zlib-ng/minizip-ng/archive/refs/tags/4.0.5.zip
unzip 4.0.5.zip
cd minizip-ng-4.0.5
cmake -S . -B build \
-DCMAKE_BUILD_TYPE=Release \
-D MZ_BUILD_TESTS=OFF \
-D MZ_LZMA=OFF \
-D MZ_ZSTD=OFF \
-D MZ_BZIP2=OFF \
-D MZ_PKCRYPT=OFF \
-D MZ_WZAES=OFF \
-D MZ_OPENSSL=OFF \
-D MZ_ICONV=OFF \
-DZLIB_TAG=develop #Temporary fix for zlib issue https://github.com/zlib-ng/minizip-ng/issues/764
cmake --build build --config Release
cmake --install build --prefix ../install
4 changes: 3 additions & 1 deletion .github/workflows/oracle8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ jobs:
unzip ortools.zip
rm ortools.zip

- uses: ./.github/workflows/install_minizip

- name: Init submodule
run: |
git config --global safe.directory '*'
Expand All @@ -85,7 +87,7 @@ jobs:
-DBUILD_TESTING=ON \
-DBUILD_TOOLS=ON \
-DBUILD_UI=OFF \
-DCMAKE_PREFIX_PATH=${{ env.ORTOOLS_DIR }}/install
-DCMAKE_PREFIX_PATH="../install;${{ env.ORTOOLS_DIR }}/install"

- name: Build
run: |
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ jobs:
python -m pip install --upgrade pip
pip3 install -r src/tests/examples/requirements.txt

- uses: ./.github/workflows/install_minizip

- name: Init submodule
run: |
git submodule update --init src/antares-deps
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/ubuntu-system-deps-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ jobs:
python -m pip install --upgrade pip
pip3 install -r src/tests/examples/requirements.txt

- uses: ./.github/workflows/install_minizip

- name: Init submodule
run: |
git submodule update --init --recursive src

- name: Configure
run: |
cmake -B _build -S src -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER=/usr/bin/gcc-10 -DCMAKE_CXX_COMPILER=/usr/bin/g++-10 -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON
cmake -B _build -S src -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER=/usr/bin/gcc-10 -DCMAKE_CXX_COMPILER=/usr/bin/g++-10 -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DCMAKE_PREFIX_PATH="../install"

- name: Build
run: |
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ jobs:
python -m pip install --upgrade pip
pip3 install -r src/tests/examples/requirements.txt

- uses: ./.github/workflows/install_minizip

- name: Init submodule
run: |
git submodule update --init src/antares-deps
Expand All @@ -105,7 +107,7 @@ jobs:
-DBUILD_TESTING=ON \
-DBUILD_not_system=OFF \
-DBUILD_TOOLS=ON \
-DCMAKE_PREFIX_PATH=${{ env.ORTOOLS_DIR }}/install \
-DCMAKE_PREFIX_PATH="../install;${{ env.ORTOOLS_DIR }}/install" \
-DPython3_EXECUTABLE="${{ env.Python3_ROOT_DIR }}/bin/python"

- name: Build
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/windows-vcpkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ jobs:
- name: Install pip dependencies if necessary
run: pip install -r src/tests/examples/requirements.txt

- uses: ./.github/workflows/install_minizip

- name: Init submodule
run: |
git submodule update --init src/antares-deps
Expand All @@ -145,7 +147,7 @@ jobs:
run: |
cmake -B _build -S src \
-DDEPS_INSTALL_DIR=rte-antares-deps-Release \
-DCMAKE_PREFIX_PATH="${{ env.ORTOOLS_DIR }}/install" \
-DCMAKE_PREFIX_PATH="../install;${{ env.ORTOOLS_DIR }}/install" \
-DVCPKG_ROOT="${{env.VCPKG_ROOT}}" \
-DVCPKG_TARGET_TRIPLET=${{ env.triplet }} \
-DCMAKE_BUILD_TYPE=Release \
Expand Down
25 changes: 25 additions & 0 deletions docs/Architecture_Decision_Records/Remove_fetch_content.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Remove usage of fetch_content for runtime dependencies

## Status: Accepted [2024/04/08]

## Context

Efficiently publishing a library involves creating a CMake package for distribution. The recommended approach is to export the project targets.

When integrating dependencies through fetch_content, they are elevated to the status of first-party components within the project's ecosystem. This
means that targets of this dependency must also be exported. Consequently, it becomes necessary to export the targets associated with these dependencies. While this presents a challenge, it's manageable, though not without some complexity.

However, opting to utilize an installed package of a dependency rather than relying on fetch_content complicates matters further.
In such cases, the library is still considered a third-party entity, yet the targets associated must not be exported.
This discrepancy can lead to inconsistencies in behavior and export sets, necessitating the maintenance of two distinct approaches.

## Decision

Remove usage of fetch_content for runtime dependencies (e.g. ortools and minizip)

It can still be used for build or test dependencies (e.g. accepted methode for google test)

## Consequences

* or-tools and minizip must be provided and can't be downloaded automatically
* Developpers must install pre-compiled binairies of said dependencies or buil them from source.
2 changes: 0 additions & 2 deletions docs/build/2-Dependencies-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ These third-party libraries can be installed:
Apart from OR-Tools, all dependencies can be built at configure time using the option `-DBUILD_ALL=ON` (`OFF` by default).
For a list of available options, see [the Antares dependencies compilation repository](https://github.com/AntaresSimulatorTeam/antares-deps).

You can set `-DBUILD_ORTOOLS=ON` to download & build OR-Tools. It is also possible to use a precompiled archive, see below.

For compiling the package yourself from git, additional build dependencies are needed (see [here](1-Development-requirements.md)).

### Pre-compiled OR-Tools: release+static only
Expand Down
1 change: 0 additions & 1 deletion docs/build/3-Build.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ Here is a list of mandatory or optional CMake configuration options:
| `DEPS_INSTALL_DIR` | no | Define dependencies libraries install directory | absolute path to an existing directory | `<antares_checkout_dir>/../rte-antares-deps-<build_type>` |
| `USE_PRECOMPILED_EXT` | no | This option must be set if you use wxWidget as precompiled external library | `ON` / `OFF` | `OFF` |
| `BUILD_TESTING` | no | Enable build for unit tests | `ON` / `OFF` | `OFF` |
| `BUILD_ORTOOLS` | no | Enable build for OR-Tools and its dependencies (requires an Internet connection) | `ON` / `OFF` | `OFF` |

> 💡 **Disable the UI build to make builds faster**
> The UI takes up a good chunk of compilation time. It is enabled by default, but you can disable it by turning off `BUILD_UI`
Expand Down
62 changes: 1 addition & 61 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,6 @@ message(STATUS "Build antares ui simulator: ${BUILD_UI}")
option(BUILD_TOOLS "Build antares tools" OFF)
message(STATUS "Build antares tools: ${BUILD_TOOLS}")

option(BUILD_ORTOOLS "Build OR-Tools" OFF)
message(STATUS "Build OR-Tools: ${BUILD_ORTOOLS}")

option(BUILD_MINIZIP "Build minizip" OFF)
message(STATUS "Build minizip: ${BUILD_MINIZIP}")

option(BUILD_MERSENNE_TWISTER_PYBIND11 "Build pybind11 bindings for Mersenne-Twister" OFF)
if (${BUILD_MERSENNE_TWISTER_PYBIND11})
find_package(pybind11 REQUIRED)
Expand Down Expand Up @@ -258,61 +252,7 @@ endif()
set(GFLAGS_USE_TARGET_NAMESPACE TRUE)
find_package(gflags)

find_package(ortools)
if(NOT ortools_FOUND OR BUILD_ORTOOLS)
message(STATUS "OR-Tools tag ${ORTOOLS_TAG}")
FetchContent_Declare(ortools
GIT_REPOSITORY "https://github.com/rte-france/or-tools"
GIT_TAG ${ORTOOLS_TAG}
GIT_SHALLOW TRUE
)

# Pass options to OR-Tools's CMake
set(BUILD_DEPS "ON" CACHE INTERNAL "")
set(BUILD_SAMPLES "OFF" CACHE INTERNAL "")
set(BUILD_FLATZINC "OFF" CACHE INTERNAL "")
set(BUILD_EXAMPLES "OFF" CACHE INTERNAL "")
set(USE_SCIP "ON" CACHE INTERNAL "")
set(USE_GLPK "ON" CACHE INTERNAL "")
# We build OR-Tools as a static lib. Cyclic dependencies are detected
# without this flag.
set(BUILD_SHARED_LIBS "OFF" CACHE INTERNAL "")
# In mode optimization error analysis, we call Sirius through or-tools
# So we need to activate Sirius in or-tools configuration (OFF by default)
set(USE_SIRIUS "ON" CACHE INTERNAL "")

FetchContent_MakeAvailable(ortools)
endif()

find_package(minizip QUIET)

if(NOT minizip_FOUND OR BUILD_MINIZIP)
if (NOT minizip_FOUND)
message("minizip not found, downloading")
endif ()
if (BUILD_MINIZIP)
message("BUILD_MINIZIP set, downloading")
endif ()
# Repository + tag
set(MZ_REPOSITORY "https://github.com/zlib-ng/minizip-ng.git")
set(MZ_TAG "4.0.1")
# CMake flags
set(MZ_LZMA "OFF" CACHE INTERNAL "")
set(MZ_ZSTD "OFF" CACHE INTERNAL "")
set(MZ_BZIP2 "OFF" CACHE INTERNAL "")
set(MZ_PKCRYPT "OFF" CACHE INTERNAL "")
set(MZ_WZAES "OFF" CACHE INTERNAL "")
set(MZ_OPENSSL "OFF" CACHE INTERNAL "")
set(MZ_ICONV "OFF" CACHE INTERNAL "")

FetchContent_Declare(minizip
GIT_REPOSITORY ${MZ_REPOSITORY}
GIT_TAG ${MZ_TAG}
OVERRIDE_FIND_PACKAGE
)

FetchContent_MakeAvailable(minizip)
endif()
find_package(ortools REQUIRED)
find_package(minizip REQUIRED)

#wxWidget not needed for all library find is done in ui CMakeLists.txt
Expand Down
1 change: 0 additions & 1 deletion src/packaging/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ set(TARGET_LIBS #No alias
#
signal-handling
antares-solver-variable-info
minizip
)

install(TARGETS ${TARGET_LIBS}
Expand Down
4 changes: 3 additions & 1 deletion src/packaging/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
@PACKAGE_INIT@

include(CMakeFindDependencyMacro)
find_dependency(ortools)

#In this order. Why? I don't really know, but it works.
find_dependency(minizip)
find_dependency(ortools)

include("${CMAKE_CURRENT_LIST_DIR}/AntaresTargets.cmake")

Expand Down