diff --git a/.github/workflows/run_tests_osx.yml b/.github/workflows/run_tests_osx.yml index 042f2f1801..5617989d71 100644 --- a/.github/workflows/run_tests_osx.yml +++ b/.github/workflows/run_tests_osx.yml @@ -478,3 +478,51 @@ 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-osx + runs-on: macos-12 + strategy: + matrix: + hdf5: [ 1.12.2, 1.14.3 ] + steps: + - uses: actions/checkout@v3 + + ### + # 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-osx + 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 && 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 + + - name: Run tests + run: | + cd integration_tests/fetch_content/build + ctest --rerun-failed --output-on-failure . --verbose \ No newline at end of file diff --git a/.github/workflows/run_tests_ubuntu.yml b/.github/workflows/run_tests_ubuntu.yml index a6a17bf8a0..e54e58ad34 100644 --- a/.github/workflows/run_tests_ubuntu.yml +++ b/.github/workflows/run_tests_ubuntu.yml @@ -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 + + - name: Run tests + run: | + cd integration_tests/fetch_content/build + ctest --rerun-failed --output-on-failure . --verbose \ No newline at end of file diff --git a/.github/workflows/run_tests_win_cygwin.yml b/.github/workflows/run_tests_win_cygwin.yml index 6e124448ed..8d058ce358 100644 --- a/.github/workflows/run_tests_win_cygwin.yml +++ b/.github/workflows/run_tests_win_cygwin.yml @@ -78,4 +78,4 @@ jobs: - name: (Autotools) Build and run tests timeout-minutes: 30 run: | - make check -j8 SHELL=/bin/dash + make check -j8 SHELL=/bin/dash \ No newline at end of file diff --git a/.github/workflows/run_tests_win_mingw.yml b/.github/workflows/run_tests_win_mingw.yml index 978275cf6c..48c441c747 100644 --- a/.github/workflows/run_tests_win_mingw.yml +++ b/.github/workflows/run_tests_win_mingw.yml @@ -16,7 +16,6 @@ concurrency: cancel-in-progress: true jobs: - build-and-test-autotools: runs-on: windows-latest @@ -27,12 +26,12 @@ jobs: steps: - uses: actions/checkout@v3 + - uses: msys2/setup-msys2@v2 with: msystem: MINGW64 update: true install: git mingw-w64-x86_64-toolchain automake libtool autoconf make cmake mingw-w64-x86_64-hdf5 unzip mingw-w64-x86_64-libxml2 mingw-w64-x86_64-zlib - ### # Configure and build ### @@ -72,4 +71,4 @@ jobs: name: mingw-autotools-test-logs path: | */*.log - */*.trs + */*.trs \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index 970be33afd..505363fcaf 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -39,6 +39,15 @@ build_script: - cmd: cmake .. -G "%CMAKE_GENERATOR%" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%INSTALL_LOC% -DENABLE_BASH_SCRIPT_TESTING=OFF -DENABLE_FILTER_TESTING=OFF -DENABLE_BYTERANGE=ON - cmd: if errorlevel 1 exit 1 - cmd: cmake --build . --config Release -- /maxcpucount:4 + # Check fetch content integration + - cmd: cd ../integration_tests/fetch_content + - cmd: mkdir build + - cmd: cd build + - cmd: cmake .. + - cmd: cmake --build . --config Release -- /maxcpucount:4 + # go back to the first build directory + - cmd: cd ../../../build test_script: - cmd: cmake --build . --config Release --target install -- /maxcpucount:4 + diff --git a/docs/building-with-cmake.md b/docs/building-with-cmake.md index 3448976b4b..83acbebe2c 100644 --- a/docs/building-with-cmake.md +++ b/docs/building-with-cmake.md @@ -101,6 +101,32 @@ or > $ cmake --build [Build Directory] --target install +## Including netcdf with cmake's FetchContent + +Some projects may wish to have cmake handle including their project dependencies with [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html). netCDF's cmake file's also support this. An example cmake setup +that downloads a specific tag of netCDF and links it to some cmake target shows how this can be done. + +``` +include(FetchContent) + +# Fetch NetCDF +FetchContent_Declare( + netcdf + GIT_REPOSITORY https://github.com/Unidata/netcdf-c + GIT_TAG main +) + +# disable netCDF tests +set(ENABLE_TESTS OFF CACHE BOOL "" FORCE) + +FetchContent_MakeAvailable(netcdf) + +add_executable(netcdf_example main.c) + +# Link against NetCDF +target_link_libraries(netcdf_example PUBLIC netcdf) +``` + # See Also {#cmake_see_also} For further information regarding NetCDF and CMake, see \ref cmake_faq diff --git a/integration_tests/fetch_content/CMakeLists.txt b/integration_tests/fetch_content/CMakeLists.txt new file mode 100644 index 0000000000..1b856157ec --- /dev/null +++ b/integration_tests/fetch_content/CMakeLists.txt @@ -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) diff --git a/integration_tests/fetch_content/main.c b/integration_tests/fetch_content/main.c new file mode 100644 index 0000000000..e1525196bd --- /dev/null +++ b/integration_tests/fetch_content/main.c @@ -0,0 +1,7 @@ +#include +#include + +int main() { + printf("NetCDF library version: %s\n", nc_inq_libvers()); + return 0; +} \ No newline at end of file