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

Conversation

Anton3
Copy link

@Anton3 Anton3 commented Sep 13, 2023

Fixes: #505

@Anton3 Anton3 changed the title fix(CPM.cmake): workaround FetchContent failure for cmake < 3.17 fix(CPM.cmake): work around FetchContent failure for cmake < 3.17 Sep 14, 2023
Copy link
Member

@TheLartians TheLartians left a comment

Choose a reason for hiding this comment

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

Hey thanks for the issue and accompanying fix! Would it make sense to also add a test case for this, so we don't accidentally break it in the future?

Comment on lines +50 to +51
get_directory_property(hasParent PARENT_DIRECTORY)
if(NOT CPM_DIRECTORY STREQUAL CPM_CURRENT_DIRECTORY OR ${hasParent})
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.

@@ -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})
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}")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FetchContent failure when using CPM on a single project with multiple subdirectories with cmake < 3.17
2 participants