Skip to content

Commit

Permalink
factored out dependency parsing to a macro
Browse files Browse the repository at this point in the history
  • Loading branch information
drexlerd committed Jan 12, 2024
1 parent 765da75 commit c077e92
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
24 changes: 3 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ list(APPEND CMAKE_MODULE_PATH
)
include("configure_boost")
include("configure_ccache")

include("configure_dependencies")

##############################################################
# CCache
Expand All @@ -68,26 +68,8 @@ configure_ccache()
# Dependency Handling
##############################################################

# We installed the dependencies into the subdirectories under the install prefix.
# Hence must append them to the single cmake_prefix_path.
message("Configure dependencies of Loki:")
message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
list(LENGTH CMAKE_PREFIX_PATH PREFIX_PATH_COUNT)
if(PREFIX_PATH_COUNT GREATER 1)
message(FATAL_ERROR "Only one prefix path is allowed. Found multiple paths in CMAKE_PREFIX_PATH. Please add dependencies to the CMake Superbuild.")
endif()

list(APPEND MODIFIED_CMAKE_PREFIX_PATH
"${CMAKE_PREFIX_PATH}/benchmark"
"${CMAKE_PREFIX_PATH}/boost"
"${CMAKE_PREFIX_PATH}/googletest")
message(${MODIFIED_CMAKE_PREFIX_PATH})
set(CMAKE_PREFIX_PATH ${MODIFIED_CMAKE_PREFIX_PATH})
message(STATUS "MODIFIED_CMAKE_PREFIX_PATH:")
foreach(CMAKE_PREFIX_PATH_ARG ${CMAKE_PREFIX_PATH})
message(STATUS "-- ${CMAKE_PREFIX_PATH_ARG}")
endforeach()
# set(CMAKE_FIND_DEBUG_MODE ON)
set(DEPENDENCY_NAMES_LIST benchmark boost googletest)
configure_dependencies("${DEPENDENCY_NAMES_LIST}")

# Boost
# Find Boost headers only according to https://cmake.org/cmake/help/latest/module/FindBoost.html
Expand Down
31 changes: 31 additions & 0 deletions cmake/configure_dependencies.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
macro(configure_dependencies list_of_dependencies)
separate_arguments(list_of_dependencies)
message("${list_of_dependencies}")
# We installed the dependencies into the subdirectories under the install prefix.
# Hence must append them to the single cmake_prefix_path.
message("Configure dependencies of Loki:")
message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
list(LENGTH CMAKE_PREFIX_PATH PREFIX_PATH_COUNT)
if(PREFIX_PATH_COUNT GREATER 1)
message(FATAL_ERROR "Only one prefix path is allowed. Found multiple paths in CMAKE_PREFIX_PATH. Please add dependencies to the CMake Superbuild.")
endif()

# Assuming there's only one path in CMAKE_PREFIX_PATH, get that path
list(GET CMAKE_PREFIX_PATH 0 SINGLE_CMAKE_PREFIX_PATH)

# Clear MODIFIED_CMAKE_PREFIX_PATH before appending
set(MODIFIED_CMAKE_PREFIX_PATH "")

# Iterate over list of names and append each to SINGLE_CMAKE_PREFIX_PATH
foreach(DEPENDENCY_NAME ${list_of_dependencies})
list(APPEND MODIFIED_CMAKE_PREFIX_PATH "${SINGLE_CMAKE_PREFIX_PATH}/${DEPENDENCY_NAME}")
endforeach()

# message(${MODIFIED_CMAKE_PREFIX_PATH})
set(CMAKE_PREFIX_PATH ${MODIFIED_CMAKE_PREFIX_PATH})
message(STATUS "MODIFIED_CMAKE_PREFIX_PATH:")
foreach(CMAKE_PREFIX_PATH_ARG ${CMAKE_PREFIX_PATH})
message(STATUS "-- ${CMAKE_PREFIX_PATH_ARG}")
endforeach()
# set(CMAKE_FIND_DEBUG_MODE ON)
endmacro()

0 comments on commit c077e92

Please sign in to comment.