Multiple CMakeLists

前端 未结 1 383
北荒
北荒 2021-01-16 01:30

Suppose I have a directory structure as follows:

/main.cpp
/CMakeLists.txt
/foo/foo.cpp
/foo/CMakeLists.txt

where my /CMakeLists.txt<

1条回答
  •  迷失自我
    2021-01-16 02:16

    Does it search for a second CMakeLists.txt file in foo

    Yes, it does

    and add the contents to the first?

    No it doesn't. It performs a number of configuring actions such as finding libraries etc and a generates separate Makefile and/or other build-time artifacts.

    And specifically in this example, will the variable ${OpenNI_LIB} be recognised in the first, given that it is defined in the second?

    no, unless such a construction

    find_library(OpenNI REQUIRED) # this sets variables for OpenNI
                                  # in the context of foo/CMakeLists.txt
    set(OpenNI_LIB ${OpenNI_LIB} PARENT_SCOPE) # this copies ${OpenNI_LIB}
                                  # into the context of /CMakeLists.txt
    

    is used in foo/CMakeLists.txt

    By default variables defined in a subdirectory's CMakeLists.txt are also defined in the subdirectory's subdirectories, that is if foo/ in turn contained bar/ with its own CMakeLists.txt, then within bar/'s CMakeLists.txt ${OpenNI_LIB} would be set.

    P.S. message(STATUS "Some message with ${VAR}") in doubtful places of CMakeLists.txt is your friend. Just look into cmake output.

    0 讨论(0)
提交回复
热议问题