Skip to content

CPM apparently doesn't propagate variables set with PARENT_SCOPE #662

Open
@SidneyCogdill

Description

@SidneyCogdill

Testing locally with CPM uncovered this problem: apparently CPM prevents the variables set by subdirectory projects from propagating to parent project. On the other hand CPM automatically sets a proxy_SOURCE_DIR variable instead which can be used to locate the include directory.

Note this issue doesn't affect FetchContent_Declare.

The issue is addressed in microsoft/proxy@62f6c4d .

include(cmake/CPM.cmake)
CPMAddPackage(
  NAME proxy
  GIT_TAG 62f6c4d1370c76a2f6a00cb16babc0092beee019
  GIT_REPOSITORY https://github.com/SidneyCogdill/proxy.git
)

Since with CPM there's no downstream packager, the microsoft/proxy repository itself is the library vendor, I think it will be a good idea to add a CI test (at a later time), to make sure that consuming with CPM actually works.

Originally posted by @SidneyCogdill in microsoft/proxy#293 (comment)


This is how the variable is set: https://github.com/microsoft/proxy/blob/62f6c4d1370c76a2f6a00cb16babc0092beee019/CMakeLists.txt#L46

# Do not set the module target if proxy is consumed as a subdirectory.
if(PROJECT_IS_TOP_LEVEL)
  set(proxy_INCLUDE_DIR include)
  if(PROXY_BUILD_MODULES)
    include(cmake/proxyModuleTargets.cmake)
  endif()
else()
  # Propagate the variable to the parent project
  set(proxy_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include PARENT_SCOPE)
endif()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions