Skip to content

Commit

Permalink
option to not download libyaml
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholaswogan committed Oct 27, 2023
1 parent 98a045c commit c649f37
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
31 changes: 22 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
10 changes: 5 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 .)

0 comments on commit c649f37

Please sign in to comment.