Skip to content

Commit

Permalink
Merge branch 'netcdf-refactor' into 'master'
Browse files Browse the repository at this point in the history
[cmake] Refactor netCDF library finding

See merge request ogs/ogs!4814
  • Loading branch information
bilke committed Dec 12, 2023
2 parents 50a9b44 + a26d52d commit f4a837e
Show file tree
Hide file tree
Showing 27 changed files with 43 additions and 1,371 deletions.
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ tags
# Visual Studio Code project files
.vscode

# Conan package manager
conanbuildinfo.cmake
conaninfo.txt
CMakeLists.txt.user*

*.pyc
.venv

Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ repos:
- id: cmake-format
additional_dependencies: ["cmakelang[YAML]"]
args: [--config=.cmake-format.yaml]
exclude: "scripts/cmake/jedbrown/.*|conan.cmake|CPM.cmake|FindFilesystem.cmake|FindMKL.cmake|JSONParser.cmake|ConanSetup.cmake|Tests.cmake"
exclude: "scripts/cmake/jedbrown/.*|CPM.cmake|FindFilesystem.cmake|FindMKL.cmake|JSONParser.cmake|Tests.cmake"
- id: cmake-lint
additional_dependencies: ["cmakelang[YAML]"]
exclude: "scripts/cmake/jedbrown/.*|conan.cmake|CPM.cmake|FindFilesystem.cmake|FindMKL.cmake|JSONParser.cmake|ConanSetup.cmake|BuildExternalProject.cmake"
exclude: "scripts/cmake/jedbrown/.*|CPM.cmake|FindFilesystem.cmake|FindMKL.cmake|JSONParser.cmake|BuildExternalProject.cmake"
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.33.0
hooks:
Expand Down
12 changes: 1 addition & 11 deletions Applications/DataExplorer/VtkVis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,7 @@ target_link_libraries(
)

if(OGS_USE_NETCDF)
target_link_libraries(
VtkVisFilter PUBLIC ${NETCDF_LIBRARIES_CXX} ${NETCDF_LIBRARIES_C}
${HDF5_HL_LIBRARIES} ${HDF5_LIBRARIES}
)
# Workaround for system installed VTK (tested on arch)
if(NOT OGS_USE_CONAN)
target_include_directories(
VtkVisFilter SYSTEM PUBLIC ${NETCDF_INCLUDES_C}
${NETCDF_INCLUDES_CXX}
)
endif()
target_link_libraries(VtkVisFilter PUBLIC netcdf-cxx4)
add_autogen_include(VtkVisFilter)
endif()

Expand Down
5 changes: 1 addition & 4 deletions Applications/Utils/FileConverter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,5 @@ if(TARGET ConvertSHPToGLI)
endif()

if(TARGET NetCdfConverter)
target_link_libraries(
NetCdfConverter ${NETCDF_LIBRARIES_CXX} ${NETCDF_LIBRARIES_C}
${HDF5_HL_LIBRARIES} ${HDF5_LIBRARIES}
)
target_link_libraries(NetCdfConverter netcdf-cxx4)
endif()
9 changes: 0 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ set(CMAKE_LIBRARY_SEARCH_PATH ""
set(OGS_CPU_ARCHITECTURE "native" CACHE STRING "Processor architecture, \
defaults to native (*nix) / blend (MSVC)."
)
option(OGS_USE_CONAN "Should Conan package manager be used?" ON)
set(OGS_CONAN_BUILD "missing" CACHE STRING "Possible values: all, missing, \
never or list of libs to build"
)
option(OGS_DISABLE_COMPILER_CACHE "Disables compiler cache." OFF)
option(OGS_USE_UNITY_BUILDS "Enables Unity builds for faster compilation." ON)
option(OGS_USE_PIP "Enables automatic Python virtual environment handling." OFF)
Expand Down Expand Up @@ -76,16 +72,11 @@ include(PythonSetup)
include(ProcessesSetup)
include(ProjectSetup)
include(Functions)
include(ConanSetup)
include(CompilerSetup)
include(JobPools)
include(Find)
include(DependenciesExternalProject)
include(Dependencies)
# Hack for Conan (msvc) gui build. Also linking to ${CONAN_LIBS} globally
if(OGS_USE_CONAN AND OGS_USE_NETCDF)
link_libraries($<$<BOOL:${WIN32}>:zlib.lib> ${CONAN_LIBS})
endif()
include(DocumentationSetup)
include(test/Test)
include(Coverage)
Expand Down
2 changes: 1 addition & 1 deletion GeoLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ target_link_libraries(
if(OGS_USE_NETCDF)
target_link_libraries(
GeoLib
PRIVATE ${NETCDF_LIBRARIES_CXX} ${NETCDF_LIBRARIES_C}
PRIVATE netcdf-cxx4
)
target_compile_definitions(GeoLib PRIVATE OGS_USE_NETCDF)
endif()
Expand Down
1 change: 0 additions & 1 deletion scripts/ci/extends/template-build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
- mkdir -p $build_dir_full build
- if [[ "$OSTYPE" == "darwin"* ]] ; then readlink_cmd=greadlink; else readlink_cmd=readlink; fi
- ln -s `$readlink_cmd -f $build_dir_full` build/${CMAKE_PRESET}
- ([ "${CONAN_USER_HOME}" == "${CI_PROJECT_DIR}/.conan" ]) && conan remove --system-reqs '*'
- ([[ $BUILD_CTEST_LARGE_ON_MASTER && "${CI_COMMIT_BRANCH}" == "master" ]]) && export BUILD_CTEST_LARGE=true
- cmake --preset=$CMAKE_PRESET --log-level=VERBOSE -Wno-dev $CMAKE_ARGS
# Activate .venv
Expand Down
2 changes: 0 additions & 2 deletions scripts/ci/jobs/build-gui-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,3 @@ build gui linux:
allow_failure: true
variables:
CMAKE_PRESET: release-gui
CMAKE_ARGS: >-
-DOGS_USE_CONAN=OFF
2 changes: 0 additions & 2 deletions scripts/ci/jobs/build-gui-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ build gui mac:
allow_failure: true
variables:
CMAKE_PRESET: release-gui
CMAKE_ARGS: >-
-DOGS_USE_CONAN=auto
parallel:
matrix:
- ARCHITECTURE: ["amd64"] # "arm64" not supported yet
2 changes: 1 addition & 1 deletion scripts/cmake/CMakeSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ if(NOT PROJECT_IS_TOP_LEVEL)
endif()

if((NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
OR (NOT CMAKE_BUILD_TYPE AND MSVC AND OGS_USE_CONAN)
OR (NOT CMAKE_BUILD_TYPE AND MSVC)
)
message(STATUS "Setting build type to 'Debug' as none was specified.")
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE)
Expand Down
124 changes: 0 additions & 124 deletions scripts/cmake/ConanSetup.cmake

This file was deleted.

34 changes: 30 additions & 4 deletions scripts/cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ if(_build_chemistry_lib)
)
list(APPEND DISABLE_WARNINGS_TARGETS IPhreeqc)
if(BUILD_SHARED_LIBS)
install(TARGETS IPhreeqc LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(TARGETS IPhreeqc
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endif()
endif()
endif()
Expand Down Expand Up @@ -415,8 +417,7 @@ if(OGS_BUILD_UTILS)
NAME metis
GIT_REPOSITORY https://github.com/KarypisLab/METIS
VERSION 5.2.1
EXCLUDE_FROM_ALL YES
UPDATE_DISCONNECTED ON
EXCLUDE_FROM_ALL YES UPDATE_DISCONNECTED ON
PATCH_COMMAND git apply
${PROJECT_SOURCE_DIR}/scripts/cmake/metis.patch
OPTIONS ${_metis_options}
Expand All @@ -443,6 +444,31 @@ if(OGS_BUILD_UTILS)
endif()
endif()

if(OGS_USE_NETCDF)
find_package(netCDF CONFIG REQUIRED)
find_library(NETCDF_LIBRARIES_CXX NAMES netcdf_c++4 netcdf-cxx4)
if(NOT NETCDF_LIBRARIES_CXX)
CPMAddPackage(
NAME netcdf-cxx4
GIT_REPOSITORY https://github.com/Unidata/netcdf-cxx4
VERSION 4.3.1
EXCLUDE_FROM_ALL YES SOURCE_SUBDIR cxx4
OPTIONS "NCXX_ENABLE_TESTS OFF"
)
set_target_properties(
netCDF::netcdf PROPERTIES INTERFACE_LINK_LIBRARIES ""
) # fix win installed config
target_link_libraries(netcdf-cxx4 PUBLIC netCDF::netcdf)
else()
find_path(NETCDF_INCLUDES_CXX NAMES netcdf)
add_library(netcdf-cxx4 INTERFACE IMPORTED)
target_include_directories(netcdf-cxx4 INTERFACE ${NETCDF_INCLUDES_CXX})
target_link_libraries(
netcdf-cxx4 INTERFACE ${NETCDF_LIBRARIES_CXX} netCDF::netcdf
)
endif()
endif()

# Disable warnings
if(WIN32 AND VTK_ADDED)
list(APPEND DISABLE_WARNINGS_TARGETS vtksys)
Expand Down Expand Up @@ -473,7 +499,7 @@ if(CLANG_FORMAT_PROGRAM OR CMAKE_FORMAT_PROGRAM)
GITHUB_REPOSITORY TheLartians/Format.cmake
OPTIONS
${_skip_cmake}
"CMAKE_FORMAT_EXCLUDE scripts/cmake/CPM.cmake|.*/Tests.cmake|scripts/cmake/jedbrown/.*|scripts/cmake/conan/conan.cmake|scripts/cmake/vector-of-bool/.*"
"CMAKE_FORMAT_EXCLUDE scripts/cmake/CPM.cmake|.*/Tests.cmake|scripts/cmake/jedbrown/.*|scripts/cmake/vector-of-bool/.*"
)
endif()

Expand Down
6 changes: 0 additions & 6 deletions scripts/cmake/Find.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ if(OGS_BUILD_GUI)
list(APPEND CMAKE_BUILD_RPATH ${Qt5_DIR}/../..)
endif()

if(OGS_USE_NETCDF)
set(NETCDF_ROOT ${CONAN_NETCDF-C_ROOT})
set(NETCDF_CXX_ROOT ${CONAN_NETCDF-CXX_ROOT})
find_package(NetCDF REQUIRED)
endif()

# geotiff ##
find_package(GEOTIFF)

Expand Down
37 changes: 0 additions & 37 deletions scripts/cmake/FindNetCDF.cmake

This file was deleted.

14 changes: 0 additions & 14 deletions scripts/cmake/ProjectSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,6 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY
${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}
)
if(OGS_USE_CONAN AND MSVC)
foreach(outputconfig ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${outputconfig} outputconfig)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${outputconfig}
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${outputconfig}
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${outputconfig}
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
)
endforeach()
endif()

# cmake-lint: disable=C0103
set(Data_SOURCE_DIR ${PROJECT_SOURCE_DIR}/Tests/Data CACHE INTERNAL "")
Expand Down
Loading

0 comments on commit f4a837e

Please sign in to comment.