Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake: How to access a variable from a subdirectory without explicitly setting it in parent scope

Tags:

cmake

box2d

I have added a subdirectory in CMake by using add_subdirectory. How can I access a variable from the scope of that subdirectory without explicitly setting the variable by using set in combination with PARENT_SCOPE ?

set(BOX2D_BUILD_STATIC       1)
set(BOX2D_BUILD_EXAMPLES     0)
set(BOX2D_INSTALL_BY_DEFAULT 0)

add_subdirectory(Box2D_v2.2.1)

message(STATUS "Using Box2D version ${BOX2D_VERSION}")

# how to get ${BOX2D_VERSION} variable without modifying CMakeLists.txt in Box2D_v2.2.1?

Is this possible?

like image 541
user1492625 Avatar asked Mar 20 '13 06:03

user1492625


1 Answers

If the variable is a plain variable (as opposed to a cache variable), there is no way to access it from the parent scope.

Cache variables (those set with set(... CACHE ...)) can be accessed regardless of scope, as can global properties (set_property(GLOBAL ...)).

like image 137
Angew is no longer proud of SO Avatar answered Sep 20 '22 07:09

Angew is no longer proud of SO