Skip to content

Commit

Permalink
improve use as child project
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Jul 22, 2024
1 parent 093e4a2 commit e558913
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 23 deletions.
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.19...3.29)
cmake_minimum_required(VERSION 3.19...3.30)

if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
message(FATAL_ERROR "In-source builds are not allowed. Do like:
Expand Down Expand Up @@ -27,19 +27,19 @@ file(GENERATE OUTPUT .gitignore CONTENT "*")
if(find)
find_package(NetCDF COMPONENTS C Fortran)
endif()
if(NOT NetCDF_FOUND)
if(NOT NetCDF_FOUND AND NOT TARGET NetCDF::NetCDF_Fortran)
include(cmake/netcdf.cmake)
endif()

# --- code coverage
if(${PROJECT_NAME}_COVERAGE AND ${PROJECT_NAME}_IS_TOP_LEVEL)
if(nc4fortran_COVERAGE AND nc4fortran_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_NAME}_IS_TOP_LEVEL)
if(tidy AND nc4fortran_IS_TOP_LEVEL)
find_program(CLANG_TIDY_EXE NAMES "clang-tidy" REQUIRED)
set(CMAKE_C_CLANG_TIDY ${CLANG_TIDY_EXE})
endif()
Expand All @@ -66,7 +66,7 @@ target_link_libraries(nc4fortran::nc4fortran INTERFACE nc4fortran)

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

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

# additional Find*.cmake necessary
install(FILES
Expand All @@ -76,7 +76,7 @@ DESTINATION cmake
)


if(${PROJECT_NAME}_BUILD_TESTING)
if(nc4fortran_BUILD_TESTING)
add_subdirectory(test)
endif()

Expand Down
8 changes: 3 additions & 5 deletions cmake/FindNetCDF.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ Search details:

#]=======================================================================]

include(CheckCSourceCompiles)
include(CheckFortranSourceCompiles)
include(CheckSourceCompiles)

function(netcdf_c)

Expand Down Expand Up @@ -77,7 +76,7 @@ if(UNIX)
list(APPEND CMAKE_REQUIRED_LIBRARIES m)
endif()

check_c_source_compiles(
check_source_compiles(C
[=[
#include <netcdf.h>
#include <stdio.h>
Expand Down Expand Up @@ -132,13 +131,12 @@ set(CMAKE_REQUIRED_FLAGS)
set(CMAKE_REQUIRED_INCLUDES ${NetCDF_Fortran_INCLUDE_DIR})
list(INSERT CMAKE_REQUIRED_LIBRARIES 0 ${NetCDF_Fortran_LIBRARY})

check_fortran_source_compiles(
check_source_compiles(Fortran
"program a
use netcdf
implicit none
end program"
NetCDF_Fortran_links
SRC_EXT f90
)

if(NOT NetCDF_Fortran_links)
Expand Down
14 changes: 2 additions & 12 deletions options.cmake
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
message(STATUS "${PROJECT_NAME} ${PROJECT_VERSION} CMake ${CMAKE_VERSION} Toolchain ${CMAKE_TOOLCHAIN_FILE}")

option(${PROJECT_NAME}_COVERAGE "Code coverage tests")
option(nc4fortran_COVERAGE "Code coverage tests")
option(tidy "Run clang-tidy on the code")
option(find "find NetCDF 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()


option(${PROJECT_NAME}_BUILD_TESTING "Build tests" ${${PROJECT_NAME}_IS_TOP_LEVEL})
option(nc4fortran_BUILD_TESTING "Build tests" ${nc4fortran_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 e558913

Please sign in to comment.