Skip to content

Commit

Permalink
Fix FindOrFetch module to pass variables
Browse files Browse the repository at this point in the history
  • Loading branch information
mhekkel committed Feb 24, 2025
1 parent 6a7b07a commit 0a4c1b0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,13 @@ endif()
# libraries
find_package(nlohmann_json REQUIRED)

# find_package(cifpp 7 REQUIRED)

find_or_fetch_package(mcfp VERSION 1.3.5 GIT_REPOSITORY https://github.com/mhekkel/libmcfp GIT_TAG b6c62a3)
find_or_fetch_package(cifpp VERSION 7 GIT_REPOSITORY https://github.com/PDB-REDO/libcifpp.git GIT_TAG v7.0.9)
find_or_fetch_package(pdb-redo VERSION 3.2.0 GIT_REPOSITORY https://github.com/PDB-REDO/libpdb-redo.git GIT_TAG f237ab0)
find_or_fetch_package(cifpp VERSION 7 GIT_REPOSITORY https://github.com/PDB-REDO/libcifpp.git GIT_TAG v7.0.9 VARIABLES "CIFPP_SHARE_DIR")
find_or_fetch_package(pdb-redo VERSION 3.2.0 GIT_REPOSITORY https://github.com/PDB-REDO/libpdb-redo.git GIT_TAG v3.2.1)

message(NOTICE "cifpp data dir: ${CIFPP_SHARE_DIR}")

add_executable(density-fitness
${PROJECT_SOURCE_DIR}/src/density-fitness.cpp
Expand Down
17 changes: 13 additions & 4 deletions cmake/FindOrFetch.cmake
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
# CMake module to find a package, or fetch it if not found

cmake_minimum_required(VERSION 3.25)

function(find_or_fetch_package _package)
set(flags VERBOSE)
set(options VERSION GIT_REPOSITORY GIT_TAG)
cmake_parse_arguments(FOF_OPTIONS "${flags}" "${options}" "" ${ARGN})
set(variables VARIABLES)
cmake_parse_arguments(FOF_OPTIONS "${flags}" "${options}" "${variables}" ${ARGN})

if(NOT _package)
message(FATAL_ERROR "TARGET option is missing")
endif()

if(TARGET "${_package}" OR ${_package}_FOUND)
return()
return(PROPAGATE ${FOF_OPTIONS_VARIABLES})
endif()

find_package("${_package}" ${FOF_OPTIONS_VERSION} QUIET)

if(${FOF_OPTIONS_VARIABLES})
message(NOTICE "fof cifpp data dir: ${CIFPP_SHARE_DIR}")
endif()

if(${_package}_FOUND)
return()
return(PROPAGATE ${FOF_OPTIONS_VARIABLES})
endif()

include(FetchContent)
Expand All @@ -35,5 +42,7 @@ function(find_or_fetch_package _package)
GIT_TAG ${FOF_OPTIONS_GIT_TAG})

FetchContent_MakeAvailable("${_package}")


return(PROPAGATE ${FOF_OPTIONS_VARIABLES})

endfunction()
15 changes: 1 addition & 14 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
# Makefile for tests

if(NOT(Catch2_FOUND OR TARGET Catch2))
find_package(Catch2 3 QUIET)

if(NOT Catch2_FOUND)
include(FetchContent)

FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.8.0)

FetchContent_MakeAvailable(Catch2)
endif()
endif()
find_or_fetch_package(Catch2 VERSION 3 GIT_REPOSITORY https://github.com/catchorg/Catch2.git GIT_TAG v3.8.0)

add_executable(unit-test-density-fitness
${PROJECT_SOURCE_DIR}/test/unit-test-density-fitness.cpp
Expand Down

0 comments on commit 0a4c1b0

Please sign in to comment.