Skip to content

Commit e558913

Browse files
committed
improve use as child project
1 parent 093e4a2 commit e558913

File tree

3 files changed

+11
-23
lines changed

3 files changed

+11
-23
lines changed

CMakeLists.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.19...3.29)
1+
cmake_minimum_required(VERSION 3.19...3.30)
22

33
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
44
message(FATAL_ERROR "In-source builds are not allowed. Do like:
@@ -27,19 +27,19 @@ file(GENERATE OUTPUT .gitignore CONTENT "*")
2727
if(find)
2828
find_package(NetCDF COMPONENTS C Fortran)
2929
endif()
30-
if(NOT NetCDF_FOUND)
30+
if(NOT NetCDF_FOUND AND NOT TARGET NetCDF::NetCDF_Fortran)
3131
include(cmake/netcdf.cmake)
3232
endif()
3333

3434
# --- code coverage
35-
if(${PROJECT_NAME}_COVERAGE AND ${PROJECT_NAME}_IS_TOP_LEVEL)
35+
if(nc4fortran_COVERAGE AND nc4fortran_IS_TOP_LEVEL)
3636
include(cmake/Modules/CodeCoverage.cmake)
3737
append_coverage_compiler_flags()
3838
set(COVERAGE_EXCLUDES ${PROJECT_SOURCE_DIR}/test)
3939
endif()
4040

4141
# --- clang-tidy
42-
if(tidy AND ${PROJECT_NAME}_IS_TOP_LEVEL)
42+
if(tidy AND nc4fortran_IS_TOP_LEVEL)
4343
find_program(CLANG_TIDY_EXE NAMES "clang-tidy" REQUIRED)
4444
set(CMAKE_C_CLANG_TIDY ${CLANG_TIDY_EXE})
4545
endif()
@@ -66,7 +66,7 @@ target_link_libraries(nc4fortran::nc4fortran INTERFACE nc4fortran)
6666

6767
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/nc4fortran.mod TYPE INCLUDE)
6868

69-
install(TARGETS nc4fortran EXPORT ${PROJECT_NAME}-targets)
69+
install(TARGETS nc4fortran EXPORT nc4fortran-targets)
7070

7171
# additional Find*.cmake necessary
7272
install(FILES
@@ -76,7 +76,7 @@ DESTINATION cmake
7676
)
7777

7878

79-
if(${PROJECT_NAME}_BUILD_TESTING)
79+
if(nc4fortran_BUILD_TESTING)
8080
add_subdirectory(test)
8181
endif()
8282

cmake/FindNetCDF.cmake

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ Search details:
4040
4141
#]=======================================================================]
4242

43-
include(CheckCSourceCompiles)
44-
include(CheckFortranSourceCompiles)
43+
include(CheckSourceCompiles)
4544

4645
function(netcdf_c)
4746

@@ -77,7 +76,7 @@ if(UNIX)
7776
list(APPEND CMAKE_REQUIRED_LIBRARIES m)
7877
endif()
7978

80-
check_c_source_compiles(
79+
check_source_compiles(C
8180
[=[
8281
#include <netcdf.h>
8382
#include <stdio.h>
@@ -132,13 +131,12 @@ set(CMAKE_REQUIRED_FLAGS)
132131
set(CMAKE_REQUIRED_INCLUDES ${NetCDF_Fortran_INCLUDE_DIR})
133132
list(INSERT CMAKE_REQUIRED_LIBRARIES 0 ${NetCDF_Fortran_LIBRARY})
134133

135-
check_fortran_source_compiles(
134+
check_source_compiles(Fortran
136135
"program a
137136
use netcdf
138137
implicit none
139138
end program"
140139
NetCDF_Fortran_links
141-
SRC_EXT f90
142140
)
143141

144142
if(NOT NetCDF_Fortran_links)

options.cmake

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11
message(STATUS "${PROJECT_NAME} ${PROJECT_VERSION} CMake ${CMAKE_VERSION} Toolchain ${CMAKE_TOOLCHAIN_FILE}")
22

3-
option(${PROJECT_NAME}_COVERAGE "Code coverage tests")
3+
option(nc4fortran_COVERAGE "Code coverage tests")
44
option(tidy "Run clang-tidy on the code")
55
option(find "find NetCDF libraries" ON)
66

7-
if(CMAKE_VERSION VERSION_LESS 3.21)
8-
get_property(not_top DIRECTORY PROPERTY PARENT_DIRECTORY)
9-
if(not_top)
10-
set(${PROJECT_NAME}_IS_TOP_LEVEL false)
11-
else()
12-
set(${PROJECT_NAME}_IS_TOP_LEVEL true)
13-
endif()
14-
endif()
15-
16-
17-
option(${PROJECT_NAME}_BUILD_TESTING "Build tests" ${${PROJECT_NAME}_IS_TOP_LEVEL})
7+
option(nc4fortran_BUILD_TESTING "Build tests" ${nc4fortran_IS_TOP_LEVEL})
188
option(CMAKE_TLS_VERIFY "Verify TLS certificates when downloading libraries" ON)
199

2010
set_property(DIRECTORY PROPERTY EP_UPDATE_DISCONNECTED true)

0 commit comments

Comments
 (0)