On Saturday 14 July 2012, 黄光成 wrote: > my directory hierarchical is : dir1/dir2/dir3. > In dir3's CMakeLists.txt, I define a custom variable named 'xxx' using the > command set(xxx yyy). I want to use the variable 'xxx' in dir1's > CMakeLists.txt, how to do that? Can export the user-defined variable?
For getting a variable one level up, using PARENT_SCOPE should work: set(foo "abc" PARENT_SCOPE) Calling this in dir3 directly in the CMakeLists.txt (i.e. not in a function) would set foo in dir2. Alternatively, you can set a variable globally, via two ways: set(foo "abc" CACHE STRING "something..." FORCE) or using a GLOBAL property: in dir1/dir2/dir3/: set_property(GLOBAL .... ) and then access it from anywhere else get_property(GLOBAL ....) I think setting a directory property should also work: in dir1/dir2/dir3/: set_property(DIRECTORY PROPERTY foo "abc") then accessing it should also work from everywhere I think: get_property(myFoo DIRECTORY ${CMAKE_SOURCE_DIR}/dir1/dir2/dir3 PROPERTY foo) Alex
-- Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake