-
Notifications
You must be signed in to change notification settings - Fork 262
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
adding an integration test to show fetch_content can work #2894
base: main
Are you sure you want to change the base?
Changes from all commits
3d68adf
0dc595c
81b0ca0
a9a8dfb
96ad9ae
dfc6031
9df0730
cac854f
a4aa0f9
5b8c273
e6da400
70e5f15
40866b7
8043ba7
8ae6795
479cf1e
9d6e798
0d68b33
6cbff81
150b2c0
487faa9
b5f82d3
62bea0c
9c7cb02
d77206a
7d1c71a
ccfcafd
bcb3170
c834636
f216dbf
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 |
---|---|---|
|
@@ -888,3 +888,56 @@ jobs: | |
cd build | ||
LD_LIBRARY_PATH=${LD_LIBRARY_PATH} ctest -j 12 --rerun-failed --output-on-failure -VV | ||
if: ${{ failure() }} | ||
|
||
fetch_content_cmake: | ||
needs: build-deps-serial | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
hdf5: [ 1.14.3 ] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Install System dependencies | ||
shell: bash -l {0} | ||
run: sudo apt update && sudo apt install -y libaec-dev zlib1g-dev automake autoconf libcurl4-openssl-dev libjpeg-dev wget curl bzip2 m4 flex bison cmake libzip-dev mpich libmpich-dev | ||
|
||
### | ||
# Set Environmental Variables | ||
### | ||
|
||
- run: echo "CMAKE_PREFIX_PATH=${HOME}/environments/${{ matrix.hdf5 }}/" >> $GITHUB_ENV | ||
- run: echo "LD_LIBRARY_PATH=${HOME}/environments/${{ matrix.hdf5 }}/lib" >> $GITHUB_ENV | ||
|
||
### | ||
# Fetch Cache | ||
### | ||
|
||
- name: Fetch HDF Cache | ||
id: cache-hdf5 | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/environments/${{ matrix.hdf5 }} | ||
key: hdf5-${{ runner.os }}-${{ matrix.hdf5 }} | ||
|
||
- name: Check Cache | ||
shell: bash -l {0} | ||
run: ls ${HOME}/environments/${{ matrix.hdf5 }} && ls ${HOME}/environments/${{ matrix.hdf5}}/lib | ||
|
||
### | ||
# Configure and build | ||
### | ||
- name: Run Cmake | ||
run: | | ||
cd integration_tests/fetch_content | ||
cmake -S . -B build | ||
|
||
- name: Build | ||
run: | | ||
cd integration_tests/fetch_content | ||
cmake --build build --parallel | ||
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. Preferably these tests are run as part of ctest using For an example: https://github.com/LecrisUT/CMake-Template/blob/a4f73dbd53d8cb98e6325296c2905b2ed40dcaa3/test/CMakeLists.txt#L114-L131 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. Oh neat! I'll give that a try tomorrow! 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. @LecrisUT I actually don't really understand what that test is doing and how it works. The stuff I added builds a small example project. From what I understand of what you sent, it seems like it would only build the netcdf project but not actually link to and use it. I feel like the integration test is a complete test. What am I missing here? 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. The first link there is the general framework for an arbitrary (regression) test that runs a cmake project as if it's used by a user from tge ground up. In the template it's ueed for packaging, example and regular regression test. For an example of a packaging test, see this CMakeLists.txt. There is a bit of fluff to allow testing in the build tree and outside, but if you look closely it's very minimal, FetchContent + link libraries + simple smoke test. See the parent folder for how the In the framework link I've sent before, notice the Compared to your approach, it's more or less identical, but this adds the ability to be called within the ctest itself, which will make it much easier to keep track of active cmake changes that break the test (it uses the current source as the "git commit" to FetchContent). Your current approach only tests Basically what I suggest here is to move the execution outside of the dedicated Github Workflow and inside the project's test itself. Sorry for being too wordy in my explanations most of the times, hope it doesn't put you off 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. No worries! I like detailed explanations and yours makes sense to me. Thanks for the input! |
||
|
||
- name: Run tests | ||
run: | | ||
cd integration_tests/fetch_content/build | ||
ctest --rerun-failed --output-on-failure . --verbose |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
cmake_minimum_required(VERSION 3.11) | ||
project(NetCDFExample) | ||
|
||
include(FetchContent) | ||
|
||
# Fetch NetCDF | ||
FetchContent_Declare( | ||
netcdf | ||
GIT_REPOSITORY https://github.com/Unidata/netcdf-c | ||
GIT_TAG main | ||
) | ||
|
||
set(ENABLE_TESTS OFF CACHE BOOL "" FORCE) | ||
|
||
FetchContent_MakeAvailable(netcdf) | ||
|
||
# Add executable | ||
add_executable(netcdf_example main.c) | ||
|
||
# Link against NetCDF | ||
target_link_libraries(netcdf_example PUBLIC netcdf) | ||
|
||
# Add test | ||
enable_testing() | ||
add_test(NAME netcdf_example_test COMMAND netcdf_example) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include <stdio.h> | ||
#include <netcdf.h> | ||
|
||
int main() { | ||
printf("NetCDF library version: %s\n", nc_inq_libvers()); | ||
return 0; | ||
} |
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.
Not a fan of these approaches, but I understand the need for them right now. If hdf5 is fetch-contentable, this could be simplified greatly.
Anyway,
LD_LIBRARY_PATH
should be unnecessary if running from build directory and the dependencies are installed with RPATH. Also, for mac it'sDYLD_LIBRARY_PATH