Skip to content

Commit

Permalink
Workaround for a bug affecting CMake < 0.30.3 and CPM >= 0.40.1 (#21)
Browse files Browse the repository at this point in the history
* Workaround for a bug affecting CMake < 3.30.3 and CPM > 0.40.1

cpm-cmake/CPM.cmake#603

* Unset ${PACKAGE}_SOURCE_DIR before calling add_subirectory

When a ${PACKAGE}_SOURCE_DIR is set before project() is called
projects where the name and project-dir-name differ,
like "gtest" for "googletest" in everest-core seem to have the wrong
${PACKAGE}_SOURCE_DIR set after the project() call

* Bump version to 0.5.1

---------

Signed-off-by: Kai-Uwe Hermann <[email protected]>
  • Loading branch information
hikinggrass authored Dec 2, 2024
1 parent 5b456ae commit c1ec735
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions 3rd_party/CPM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ function(CPMAddPackage)
# add_subdirectory. Up until these changes, we had to call FetchContent_Populate and
# add_subdirectory separately, which is no longer necessary and has been deprecated as of 3.30.
set(fetchContentDeclareExtraArgs "")
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.28.0")
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.30.3")
if(${CPM_ARGS_EXCLUDE_FROM_ALL})
list(APPEND fetchContentDeclareExtraArgs EXCLUDE_FROM_ALL)
endif()
Expand All @@ -880,7 +880,7 @@ function(CPMAddPackage)
if(DEFINED CPM_ARGS_SOURCE_SUBDIR)
list(APPEND fetchContentDeclareExtraArgs SOURCE_SUBDIR ${CPM_ARGS_SOURCE_SUBDIR})
endif()
# For CMake version <3.28 OPTIONS are parsed in cpm_add_subdirectory
# For CMake version <3.30.3 OPTIONS are parsed in cpm_add_subdirectory
if(CPM_ARGS_OPTIONS AND NOT DOWNLOAD_ONLY)
foreach(OPTION ${CPM_ARGS_OPTIONS})
cpm_parse_option("${OPTION}")
Expand All @@ -896,7 +896,7 @@ function(CPMAddPackage)
if(CPM_SOURCE_CACHE AND download_directory)
file(LOCK ${download_directory}/../cmake.lock RELEASE)
endif()
if(${populated} AND ${CMAKE_VERSION} VERSION_LESS "3.28.0")
if(${populated} AND ${CMAKE_VERSION} VERSION_LESS "3.30.3")
cpm_add_subdirectory(
"${CPM_ARGS_NAME}"
"${DOWNLOAD_ONLY}"
Expand Down Expand Up @@ -1076,6 +1076,7 @@ function(
endif()
set(CPM_OLD_INDENT "${CPM_INDENT}")
set(CPM_INDENT "${CPM_INDENT} ${PACKAGE}:")
unset(${PACKAGE}_SOURCE_DIR)
add_subdirectory(${SOURCE_DIR} ${BINARY_DIR} ${addSubdirectoryExtraArgs})
set(CPM_INDENT "${CPM_OLD_INDENT}")
endif()
Expand All @@ -1098,7 +1099,7 @@ function(cpm_fetch_package PACKAGE DOWNLOAD_ONLY populated)
string(TOLOWER "${PACKAGE}" lower_case_name)

if(NOT ${lower_case_name}_POPULATED)
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.28.0")
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.30.3")
if(DOWNLOAD_ONLY)
# MakeAvailable will call add_subdirectory internally which is not what we want when
# DOWNLOAD_ONLY is set. Populate will only download the dependency without adding it to the
Expand Down
2 changes: 1 addition & 1 deletion everest-cmake-config-version.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(PACKAGE_VERSION 0.5.0)
set(PACKAGE_VERSION 0.5.1)

if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION)
set(PACKAGE_VERSION_EXACT TRUE)
Expand Down

0 comments on commit c1ec735

Please sign in to comment.