From c649f3768711cbb4823096176530907514ba47a4 Mon Sep 17 00:00:00 2001 From: Nick Wogan Date: Fri, 27 Oct 2023 08:51:23 -0700 Subject: [PATCH] option to not download libyaml --- CMakeLists.txt | 31 ++++++++++++++++++++++--------- src/CMakeLists.txt | 10 +++++----- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f16936..3041eec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,15 +7,28 @@ FortranCInterface_VERIFY() set(CMAKE_Fortran_MODULE_DIRECTORY "${CMAKE_BINARY_DIR}/modules") -# dependencies -include(cmake/CPM.cmake) -CPMAddPackage( - NAME libyaml - VERSION 0.2.5 - GITHUB_REPOSITORY "yaml/libyaml" - GIT_TAG "release/0.2.5" - EXCLUDE_FROM_ALL ON -) +option(DOWNLOAD_LIBYAML "If ON, then libyaml will be downloaded and +built." ON) + +# Find libyaml +if (DOWNLOAD_LIBYAML) + # use CPM to download and build libyaml + include(cmake/CPM.cmake) + CPMAddPackage( + NAME libyaml + VERSION 0.2.5 + GITHUB_REPOSITORY "yaml/libyaml" + GIT_TAG "release/0.2.5" + EXCLUDE_FROM_ALL ON + ) +else() + # Try to find libyaml using pkg-config + find_package(PkgConfig REQUIRED) + pkg_check_modules(YAML REQUIRED IMPORTED_TARGET yaml-0.1) + if (NOT (${YAML_VERSION} STREQUAL "0.2.5")) + message(FATAL_ERROR "PkgConfig found yaml version ${YAML_VERSION} but version 0.2.5 is required") + endif() +endif() add_subdirectory(src) add_subdirectory(tests) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7444e8a..58b7668 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,7 +1,10 @@ -set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") add_library(libyaml_interface libyaml_interface.c) -target_link_libraries(libyaml_interface yaml) +if (DOWNLOAD_LIBYAML) + target_link_libraries(libyaml_interface yaml) +else() + target_link_libraries(libyaml_interface PkgConfig::YAML) +endif() add_library(fortran-yaml-c fortran_yaml_c_types.f90 @@ -17,6 +20,3 @@ if ("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU") endif() endif() -install(TARGETS yaml libyaml_interface fortran-yaml-c DESTINATION lib) -install(DIRECTORY ${CMAKE_BINARY_DIR}/modules DESTINATION .) -