-
Notifications
You must be signed in to change notification settings - Fork 18
Fix CMake export and include interfaces #181
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
base: main
Are you sure you want to change the base?
Changes from all commits
d5a94db
74fecb7
640644a
62455c3
7a68f0e
f1e880a
e5db953
9cffc2b
960796b
8751dae
2d6daa1
f898abd
66a54c1
9d8ef4d
b813de2
0c8fb71
e0d9ca0
e028d87
94e39b0
4a98590
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,79 +1,141 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| tags: ['**'] | ||
| paths-ignore: | ||
| - '**/*.md' | ||
| pull_request: {branches: [main]} | ||
| workflow_dispatch: | ||
| inputs: | ||
| debug_enabled: | ||
| description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)' | ||
| required: false | ||
| default: false | ||
| defaults: {run: {shell: 'bash -el {0}'}} # https://github.com/marketplace/actions/setup-miniconda#important | ||
| env: | ||
| YARDL_VERSION: 0.6.3 | ||
| push: | ||
| paths-ignore: | ||
| - '**/*.md' | ||
| pull_request: {branches: [main]} | ||
| workflow_dispatch: | ||
| inputs: | ||
| debug_enabled: | ||
| description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)' | ||
| required: false | ||
| default: 'false' | ||
|
|
||
| jobs: | ||
| validate: | ||
| strategy: | ||
| matrix: | ||
| cppVersion: [17] | ||
| environment: pypi | ||
| permissions: {id-token: write} | ||
| name: Validate Python and C++${{ matrix.cppVersion }} and deploy to PyPI | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: {fetch-depth: 0, submodules: recursive} | ||
| - name: strip environment.yml | ||
| run: | | ||
| cat environment.yml | grep -v "#.*\<\local\>" > temp-ci-environment.yml | ||
| - uses: conda-incubator/setup-miniconda@v3 | ||
| with: | ||
| activate-environment: yardl | ||
| environment-file: temp-ci-environment.yml | ||
| - name: Install yardl | ||
| run: | | ||
| rm temp-ci-environment.yml | ||
| gh release download -R microsoft/yardl -p '*linux_x86_64.tar.gz' v$YARDL_VERSION | ||
| mkdir yardl | ||
| tar -xzf "yardl_${YARDL_VERSION}_linux_x86_64.tar.gz" -C yardl | ||
| rm "yardl_${YARDL_VERSION}_linux_x86_64.tar.gz" | ||
| echo "$PWD/yardl" >> "$GITHUB_PATH" | ||
| validate: | ||
| strategy: | ||
| matrix: | ||
| cppVersion: [17] | ||
| runs-on: ubuntu-24.04 | ||
| name: Validate Python and C++${{ matrix.cppVersion }} and deploy to PyPI | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| # Enable tmate debugging of manually-triggered workflows if the input option was provided | ||
| - name: Setup tmate session if triggered | ||
| #if: ${{ failure() }} | ||
| uses: mxschmitt/action-tmate@v3 | ||
| timeout-minutes: 30 | ||
| if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled == 'true' }} | ||
| - name: Build model | ||
| run: | | ||
| just generate | ||
| - name: Python | ||
| run: | | ||
| just run-python | ||
| - name: cpp | ||
| run: | | ||
| mkdir cpp/build | ||
| cd cpp/build | ||
| cmake -G Ninja -S .. -DHDF5_ROOT="$CONDA_PREFIX" | ||
| ninja | ||
| cd ../.. | ||
| just run-cpp | ||
| - name: Copy LICENSE for deployment | ||
| run: | | ||
| cp LICENSE.txt python/LICENSE | ||
| cp LICENSE.txt cpp/LICENSE | ||
| - uses: casperdcl/deploy-pypi@v2 | ||
| with: | ||
| build: python -o dist | ||
| upload: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') }} | ||
| requirements: 'build twine packaging>=24.2' # https://github.com/pypa/twine/issues/1216 | ||
| - uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: python-petsird | ||
| path: dist/** | ||
| PETSIRD_PREFIX: ${{ github.workspace }}/petsird-install | ||
|
|
||
| steps: | ||
| - name: Install System Dependencies (date-tz) | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y software-properties-common | ||
| sudo add-apt-repository -y universe | ||
| sudo apt-get update | ||
| sudo apt install -y libomp-dev libboost-dev libhdf5-serial-dev nlohmann-json3-dev | ||
| sudo apt-get install -y libdate-tz-dev || sudo apt-get install -y libhowardhinnant-date-dev | ||
|
|
||
| - name: Checkout PETSIRD | ||
| uses: actions/checkout@v4 | ||
|
|
||
|
|
||
| - name: Checkout Yardl (main) | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| repository: microsoft/yardl | ||
| ref: main | ||
| path: yardl | ||
|
|
||
| - name: Setup micromamba (yardl env) | ||
| uses: mamba-org/setup-micromamba@v2 | ||
| with: | ||
| environment-file: yardl/environment.yml | ||
| activate-environment: yardl | ||
|
|
||
| - name: Export CMake prefix path | ||
| run: | | ||
| echo "CMAKE_PREFIX_PATH=$CONDA_PREFIX;$CMAKE_PREFIX_PATH" >> $GITHUB_ENV | ||
|
|
||
| - name: Setup Go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: '1.22' | ||
|
|
||
| - name: Build and install Yardl | ||
| run: | | ||
| cd yardl/tooling/cmd/yardl | ||
| go build | ||
| mkdir -p "$HOME/.local/bin" | ||
| install -m 755 yardl $HOME/.local/bin/yardl | ||
| echo "$HOME/.local/bin" >> $GITHUB_PATH | ||
| "$HOME/.local/bin/yardl" --version | ||
|
|
||
| - name: Setup tmate session if triggered | ||
| #if: ${{ failure() }} | ||
| uses: mxschmitt/action-tmate@v3 | ||
| timeout-minutes: 30 | ||
| if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled == 'true' }} | ||
|
|
||
| - name: Install just | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y cmake ninja-build just | ||
|
|
||
| - name: Install PETSIRD Python dependencies | ||
| run: | | ||
| micromamba install -y -n yardl -f environment.yml | ||
| micromamba install -n yardl -c conda-forge xtensor xtensor-blas openblas | ||
|
|
||
| - name: Generate PETSIRD sources (yardl) | ||
| run: | | ||
| micromamba run -n yardl bash -lc " | ||
| export CC=/usr/bin/gcc | ||
| export CXX=/usr/bin/g++ | ||
|
|
||
| # Make conda packages visible to CMake | ||
| export CMAKE_PREFIX_PATH=\$CONDA_PREFIX:\$CMAKE_PREFIX_PATH | ||
| export CXXFLAGS=\"-I\$MAMBA_ROOT_PREFIX/envs/yardl/include \$CXXFLAGS\" | ||
|
|
||
| cd model | ||
| just generate | ||
| just run-python | ||
| just run-cpp | ||
| " | ||
|
|
||
| - name: Build PETSIRD C++ | ||
| run: | | ||
| micromamba run -n yardl bash -lc " | ||
| cd cpp | ||
| mkdir -p build | ||
| cd build | ||
|
|
||
| cmake .. \ | ||
| -DCMAKE_BUILD_TYPE=Release \ | ||
| -DCMAKE_PREFIX_PATH=\"\$CONDA_PREFIX\" \ | ||
| -DCMAKE_INSTALL_PREFIX=\"${{ env.PETSIRD_PREFIX }}\" | ||
|
|
||
| cmake --build . --target install -- -j$(nproc) | ||
| " | ||
|
|
||
| - name: Fix yardl mistake | ||
| run: | | ||
| FILE="cpp/generated/petsird/CMakeLists.txt" | ||
| echo "🔧 Fixing yardl-generated CMakeLists.txt (removing xtensor linkage)" | ||
| sed -i.bak \ | ||
| -e '/^[[:space:]]*xtensor[[:space:]]*$/d' \ | ||
| "$FILE" | ||
|
|
||
| - name: Set up Python for PyPI | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.11' | ||
| - name: Copy LICENSE for deployment | ||
| run: | | ||
| cp LICENSE.txt python/LICENSE | ||
| cp LICENSE.txt cpp/LICENSSE | ||
| - uses: casperdcl/deploy-pypi@v2 | ||
| with: | ||
| build: python -o dist | ||
| upload: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') }} | ||
| requirements: 'build twine packaging>=24.2' # https://github.com/pypa/twine/issues/1216 | ||
| - uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: python-petsird | ||
| path: dist/** |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| @PACKAGE_INIT@ | ||
| include(CMakeFindDependencyMacro) | ||
| find_dependency(date) | ||
| find_dependency(xtensor-blas) | ||
| if(@PETSIRD_GENERATED_USE_NDJSON@) | ||
| find_dependency(nlohmann_json) | ||
| endif() | ||
| if(@PETSIRD_GENERATED_USE_HDF5@) | ||
| find_dependency(HDF5 COMPONENTS CXX) | ||
| endif() | ||
| include("${CMAKE_CURRENT_LIST_DIR}/petsirdTargets.cmake") | ||
| check_required_components(PETSIRD) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,12 +2,33 @@ find_package(xtensor-blas REQUIRED) | |
|
|
||
| # create a petsird_helpers library target | ||
| # Currently it is just empty, but allows creating target properties which are transitive | ||
| add_library(petsird_helpers INTERFACE) | ||
| target_link_libraries(petsird_helpers INTERFACE petsird xtensor-blas) | ||
| target_include_directories(petsird_helpers INTERFACE "${PROJECT_SOURCE_DIR}/helpers/include") | ||
| add_library(petsird_helpers ${PETSIRD_HELPERS_SOURCES}) | ||
NikEfth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| target_include_directories(petsird_helpers | ||
| PUBLIC | ||
| $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
| $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> | ||
| ) | ||
|
|
||
| target_link_libraries(petsird_helpers | ||
| PUBLIC | ||
| petsird_generated | ||
| xtensor-blas | ||
| ) | ||
|
|
||
| add_executable(petsird_generator petsird_generator.cpp) | ||
| target_link_libraries(petsird_generator petsird_helpers) | ||
| target_link_libraries(petsird_generator PRIVATE petsird_generated petsird_helpers) | ||
|
|
||
| add_executable(petsird_analysis petsird_analysis.cpp) | ||
| target_link_libraries(petsird_analysis petsird_helpers) | ||
| target_link_libraries(petsird_analysis PRIVATE petsird_generated petsird_helpers) | ||
|
|
||
| foreach(t petsird petsird_generated petsird_helpers) | ||
| if(TARGET ${t}) | ||
| get_target_property(_libs ${t} INTERFACE_LINK_LIBRARIES) | ||
| if(_libs) | ||
| list(FILTER _libs EXCLUDE REGEX "xtensor") | ||
| set_target_properties(${t} | ||
| PROPERTIES INTERFACE_LINK_LIBRARIES "${_libs}") | ||
| endif() | ||
| endif() | ||
| endforeach() | ||
|
Comment on lines
+25
to
+34
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why did you need this? (probably because you removed
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To undo an overly-aggressive dependency propagation introduced by generated / helper targets.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As long as xtensor is header-only, we could use the same trick as https://github.com/UCL/STIR/blob/ec3a5670f9b63cb10f4bebce6edf22d6f028a6fb/src/buildblock/CMakeLists.txt#L125-L137, i.e. only add the include path. However, this is all quite ugly. I'd rather avoid it as much as possible. As long as we have |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like this is set minimum version, and is therefore useful, see https://stackoverflow.com/questions/70667513/cmake-cxx-standard-vs-target-compile-features and in particular https://stackoverflow.com/questions/70667513/cmake-cxx-standard-vs-target-compile-features#comment135186815_70667652
However, probably should be added to the
generatedlibrary already. (In fact, should be in the generated CMakeLists.txt)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
microsoft/yardl#261. but we can still add it ourselves