Search code examples
cmakeexternal-project

How to define variable derived from a target built with ExternalProject_add in cmake?


You can get a property of a CMake target that was built using ExternalProject_add using something like this:

ExternalProject_Get_property(zipper SOURCE_DIR)
message("Source dir of myExtProj = ${SOURCE_DIR}")

How would I save this to another variable, i.e. not SOURCE_DIR?


Solution

  • If you can use ${SOURCE_DIR} to print its value, you can use it set another variable, using the set() command:

    ExternalProject_Get_property(zipper SOURCE_DIR)
    message("Source dir of myExtProj = ${SOURCE_DIR}")
    
    # Set the variable zipper_SOURCE_DIR.
    set(zipper_SOURCE_DIR ${SOURCE_DIR})