How to include an additional CMakeLists.txt

前端 未结 2 1587
梦毁少年i
梦毁少年i 2021-01-03 17:42

Say we have a command call foo in CMakeLists.txt which is in folder /A.

foo is defined in antother CMakeLists.txt which is in

相关标签:
2条回答
  • 2021-01-03 18:22

    That can be done with include, here's some simple example:

    Content of A/CMakeLists.txt

    function(foo)
        message(STATUS "heya")
    endfunction()
    

    Content of B/CMakeLists.txt

    cmake_minimum_required(VERSION 2.8)
    include(${CMAKE_CURRENT_SOURCE_DIR}/../A/CMakeLists.txt)
    foo()
    

    Now, including another CMakeLists.txt will also run everything in that file, so you may want to avoid doing that if there are targets in B/CMakeLists.txt

    If you can modify your code, it would be better to define your functions in a "top level" CMakeLists.txt before calling add_subdirectory.

    0 讨论(0)
  • 2021-01-03 18:28

    If this files just contains functions definitions you should not call it CMakeLists.txt, but some_adequate_name.cmake

    Than you can include it where you need those functions definitions using include.

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