Skip to content

Commit

Permalink
fix is_top_level for cmake < 3.21
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed May 10, 2024
1 parent 9f7f8ea commit 600bbd7
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 24 deletions.
19 changes: 9 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ name: ci
env:
HOMEBREW_NO_INSTALL_CLEANUP: 1
CMAKE_BUILD_PARALLEL_LEVEL: 4
CTEST_PARALLEL_LEVEL: 4
CTEST_PARALLEL_LEVEL: 0
CMAKE_INSTALL_PREFIX: ~/libs
CMAKE_PREFIX_PATH: ~/libs

on:
push:
Expand Down Expand Up @@ -60,11 +62,11 @@ jobs:
cmake
-S example
-B example/build
-DCMAKE_PREFIX_PATH=${{ github.workspace }}/build/local
-DBUILD_SHARED_LIBS:BOOL=${{ matrix.shared }}
- name: build examples
run: cmake --build example/build

- name: Test examples
run: ctest --test-dir example/build -V

Expand Down Expand Up @@ -93,18 +95,15 @@ jobs:
- run: cmake --install build

- name: configure examples
run: >-
cmake
-S example
-B example/build
-DCMAKE_PREFIX_PATH=${{ github.workspace }}/build/local
run: cmake -S example -B example/build

- name: build examples
run: cmake --build example/build

- name: Test examples
run: ctest --test-dir example/build -V


linux-coverage:
if: github.event_name == 'release'
needs: base
Expand All @@ -113,7 +112,7 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'

Expand All @@ -126,7 +125,7 @@ jobs:
run: pip install gcovr

- run: cmake --preset coverage
- run: cmake --build --preset coverage --parallel
- run: cmake --build --preset coverage

- name: Code coverage
run: cmake --build --preset run-coverage
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/ci_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ on:

env:
CMAKE_BUILD_PARALLEL_LEVEL: 4
CTEST_PARALLEL_LEVEL: 4
CTEST_PARALLEL_LEVEL: 0
CMAKE_INSTALL_PREFIX: libs
CMAKE_PREFIX_PATH: libs


jobs:

Expand All @@ -40,7 +43,9 @@ jobs:
# run: cmake --workflow --preset debug

- name: config
run: cmake -G "MinGW Makefiles" -DHDF5_ROOT=${{ runner.temp }}/msys64/mingw64/ -DCMAKE_BUILD_TYPE=Release --preset default
run: cmake -G "MinGW Makefiles" --preset default
env:
HDF5_ROOT: ${{ runner.temp }}/msys64/mingw64/

- name: build
run: cmake --build --preset default
Expand All @@ -53,7 +58,7 @@ jobs:
# NetCDF-C packaging issue with HDF5--ignores CMAKE_MODULE_PATH and uses broken factory FindHDF5
# and can't seem to override
# - name: configure examples
# run: cmake -S example -B example/build -DCMAKE_PREFIX_PATH=${{ runner.temp }}
# run: cmake -S example -B example/build
# - name: build Examples
# run: cmake --build example/build
# - name: Test Examples
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/oneapi-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ env:
# https://github.com/oneapi-src/oneapi-ci/blob/master/.github/workflows/build_all.yml
CTEST_NO_TESTS_ACTION: error
CMAKE_BUILD_PARALLEL_LEVEL: 4
CTEST_PARALLEL_LEVEL: 0
CMAKE_INSTALL_PREFIX: ~/libs
CMAKE_PREFIX_PATH: ~/libs

on:
push:
Expand Down Expand Up @@ -64,7 +67,6 @@ jobs:
cmake
-S example
-B example/build
-DCMAKE_PREFIX_PATH:PATH=${{ github.workspace }}/build/local
# BUILD_SHARED_LIBS=false since as with any C++ / Fortran program with Intel compiler,
# need to have GCC environment carefully set
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ if(NOT NetCDF_FOUND)
endif()

# --- code coverage
if(${PROJECT_NAME}_COVERAGE)
if(${PROJECT_NAME}_COVERAGE AND ${PROJECT_NAME}_IS_TOP_LEVEL)
include(cmake/Modules/CodeCoverage.cmake)
append_coverage_compiler_flags()
set(COVERAGE_EXCLUDES ${PROJECT_SOURCE_DIR}/test)
endif()

# --- clang-tidy
if(tidy AND PROJECT_IS_TOP_LEVEL)
if(tidy AND ${PROJECT_NAME}_IS_TOP_LEVEL)
find_program(CLANG_TIDY_EXE NAMES "clang-tidy" REQUIRED)
set(CMAKE_C_CLANG_TIDY ${CLANG_TIDY_EXE})
endif()
Expand Down
1 change: 0 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
{
"name": "default",
"binaryDir": "${sourceDir}/build",
"installDir": "${sourceDir}/build/local",
"cacheVariables": {
"CMAKE_COMPILE_WARNING_AS_ERROR": true
}
Expand Down
2 changes: 1 addition & 1 deletion cmake/libraries.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"url" : "https://github.com/zlib-ng/zlib-ng/archive/refs/tags/2.1.6.tar.gz"
},
"hdf5": {
"url": "https://github.com/HDFGroup/hdf5/archive/refs/tags/hdf5-1_14_3.tar.gz"
"url": "https://github.com/HDFGroup/hdf5/releases/download/hdf5_1.14.4.2/hdf5-1.14.4-2.tar.gz"
}
}
16 changes: 10 additions & 6 deletions options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ option(${PROJECT_NAME}_COVERAGE "Code coverage tests")
option(tidy "Run clang-tidy on the code")
option(find "find NetCDF libraries" ON)


option(${PROJECT_NAME}_BUILD_TESTING "Build tests" ${PROJECT_IS_TOP_LEVEL})
option(CMAKE_TLS_VERIFY "Verify TLS certificates when downloading libraries" ON)
if(CMAKE_VERSION VERSION_LESS 3.21)
get_property(not_top DIRECTORY PROPERTY PARENT_DIRECTORY)
if(not_top)
set(${PROJECT_NAME}_IS_TOP_LEVEL false)
else()
set(${PROJECT_NAME}_IS_TOP_LEVEL true)
endif()
endif()


if(nc4fortran_IS_TOP_LEVEL AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set_property(CACHE CMAKE_INSTALL_PREFIX PROPERTY VALUE "${PROJECT_BINARY_DIR}/local")
endif()
option(${PROJECT_NAME}_BUILD_TESTING "Build tests" ${${PROJECT_NAME}_IS_TOP_LEVEL})
option(CMAKE_TLS_VERIFY "Verify TLS certificates when downloading libraries" ON)

set_property(DIRECTORY PROPERTY EP_UPDATE_DISCONNECTED true)

Expand Down

0 comments on commit 600bbd7

Please sign in to comment.