CMAKE inherits definition from parent

I am writing some definition in the parent CMakeLists.txt I want this definition to be inherited in the project subdirectory. So if I have a project like

root |- CMakeLists.txt |- A | |- CMakeLists.txt |- B |- CMakeLists.txt 

the definition that I wrote in the root of CMakeLists.txt should go to the child.

How to do it?

+6
source share
2 answers

Change the order in which the changes are included. I used in the past

 CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0) SET(ENV{OSDEP} "linux") SET(ENV{BIT} 64) SET(ENV{XUL} 5000) ADD_SUBDIRECTORY(lib/src/json) add_definitions("-_DDEBUG") 

which I changed the last two lines to

 add_definitions("-_DDEBUG") ADD_SUBDIRECTORY(lib/src/json) 
+7
source

It depends on how you use A and B CMakeLists.txt in CMakeLists.txt.

The CMAKE path should add_subdirectory (and I highly recommend it, after a long time) in the root CMakeLists.txt for A and B. Then A and B have all the variables from root and root, all available targets from A and B.

+1
source

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


All Articles