Skip to content

Commit

Permalink
Support EVAL CODE on CMake <3.18
Browse files Browse the repository at this point in the history
  • Loading branch information
CraigHutchinson committed Mar 8, 2023
1 parent b330641 commit 98782df
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions cmake/CPM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,16 @@ function(cpm_override_fetchcontent contentName)
set_property(GLOBAL PROPERTY ${propertyName} TRUE)
endfunction()

macro(cpm_cmake_eval)
set(__ARGN "${ARGN}")
if(COMMAND cmake_language)
cmake_language(EVAL CODE "${__ARGN}")
else()
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/eval.cmake "${__ARGN}")
include(${CMAKE_CURRENT_BINARY_DIR}/eval.cmake)
endif()
endmacro()

# Download and add a package from source
macro(CPMAddPackage)
set(__ARGN "${ARGN}")
Expand All @@ -518,7 +528,7 @@ macro(CPMAddPackage)
foreach(__ARG IN LISTS __ARGN)
string(APPEND __ARGN_Quoted " [==[${__ARG}]==]")
endforeach()
cmake_language(EVAL CODE "cpm_add_package_multi_arg( ${__ARGN_Quoted} )")
cpm_cmake_eval("cpm_add_package_multi_arg( ${__ARGN_Quoted} )")
endif()
endmacro()

Expand Down Expand Up @@ -940,7 +950,7 @@ function(cpm_declare_fetch PACKAGE VERSION INFO)
foreach(__item IN LISTS ARGN)
string(APPEND __argsQuoted " [==[${__item}]==]")
endforeach()
cmake_language(EVAL CODE "FetchContent_Declare(${PACKAGE} ${__argsQuoted} )")
cpm_cmake_eval("FetchContent_Declare(${PACKAGE} ${__argsQuoted} )")
endfunction()

# returns properties for a package previously defined by cpm_declare_fetch
Expand Down

0 comments on commit 98782df

Please sign in to comment.