Set variable in current scope and PARENT_SCOPE?

If I do this:

set(SourceDir ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE)
message("SourceDir: " ${SourceDir})

The message says that SourceDir is empty. Presumably, it is installed only in the parent area. Is there a way to set a variable in the current scope and the parent scope? So what I do not need to do:

set(SourceDir ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE)
set(SourceDir ${CMAKE_CURRENT_SOURCE_DIR})
message("SourceDir: " ${SourceDir})
+4
source share
2 answers

When you set it to PARENT_SCOPE, it does not do this for the current scope. But the two-step process works. The first line sets it locally, the second line exports it to the parent area.

set (LIB_VER 6)
set (LIB_VER ${LIB_VER} PARENT_SCOPE)
+3
source

I think you can’t. The documentation states:

Each new directory or function creates a new scope.

, SET , . , (PARENT_SCOPE), .

CMake, , , . , .

+1

Source: https://habr.com/ru/post/1618163/


All Articles