Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(CPM.cmake): work around FetchContent failure for cmake < 3.17 #506

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions cmake/CPM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ set(CURRENT_CPM_VERSION 1.0.0-development-version)

get_filename_component(CPM_CURRENT_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}" REALPATH)
if(CPM_DIRECTORY)
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
get_directory_property(hasParent PARENT_DIRECTORY)
if(NOT CPM_DIRECTORY STREQUAL CPM_CURRENT_DIRECTORY OR ${hasParent})
Comment on lines +50 to +51
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment above this explaining what issue this check fixes?

Also I feel some parenthesis could be useful around the NOT expression as I'm confused by CMake's operator precedence.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally the test cases seem to fail if hasParent is an empty string.

1: CMake Error at /home/runner/work/CPM.cmake/CPM.cmake/cmake/CPM.cmake:51 (if):
1:   if given arguments:
1: 
1:     "NOT" "CPM_DIRECTORY" "STREQUAL" "CPM_CURRENT_DIRECTORY" "OR"
1: 
1:   Unknown arguments specified
1: Call Stack (most recent call first):

It should be fixable by adding quotation marks.

Suggested change
if(NOT CPM_DIRECTORY STREQUAL CPM_CURRENT_DIRECTORY OR ${hasParent})
if(NOT CPM_DIRECTORY STREQUAL CPM_CURRENT_DIRECTORY OR "${hasParent}")

include(FetchContent)
endif()
endif()

if(NOT CPM_DIRECTORY STREQUAL CPM_CURRENT_DIRECTORY)
if(CPM_VERSION VERSION_LESS CURRENT_CPM_VERSION)
message(
Expand All @@ -56,9 +63,6 @@ It is recommended to upgrade CPM to the most recent version. \
See https://github.com/cpm-cmake/CPM.cmake for more information."
)
endif()
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
include(FetchContent)
endif()
return()
endif()

Expand Down
Loading