繁体   English   中英

如何强制Cmake执行具有多组件依赖关系的顶级CMakeLists.txt?

[英]How to force Cmake execute a top-level CMakeLists.txt of a multi component dependency?

我正在尝试使我的android项目具有C支持。 假设我具有以下结构(一切都是源目录,没有二进制文件):

CMakeLists.txt
src/main/cpp/|
             |---Executable1/
             |---Executable2/
             |---deps/

在此CMakeLists.txt中,我有:

cmake_minimum_required(VERSION 3.4.1)
project(ProjectName)
set(CMAKE_VERBOSE_MAKEFILE on)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/src/main/assets/${ANDROID_ABI}")
add_subdirectory(src/main/cpp/deps)
add_subdirectory(src/main/cpp/Executable1)
add_subdirectory(src/main/cpp/Executable2)

在“ deps”文件夹中,我具有以下结构:

deps/|
     |---CMakeLists.txt
     |---Library1/
     |---LIbrary2/

在此CMakeLists.txt中,我有:

add_subdirectory(Library1)
add_subdirectory(Library2)

在Library2中,我有2个模块:

Library2/|---CMakeLists.txt
         |---Module1/
         |---Module2/

在这个CMakeLists.txt中,我有

project(Library2)
include_directories ( BEFORE SYSTEM ${CMAKE_CURRENT_BINARY_DIR}/Module1
                                ${CMAKE_CURRENT_BINARY_DIR}/Module2
                                Module1
                                . )
add_subdirectory( Module1 )
add_subdirectory( Module2 )

Module1和Module2是我添加的库

add_library(Module1 STATIC sourceM1_1.c sourceM1_2.c ...)

add_library(Module2 STATIC sourceM2_1.c sourceM2_2.c ...)

分别在其CMakeLists.txt中。

Executable2在其CMakeLists.txt中具有:

add_executable(Executable2  sourceE2_1.c sourceE2_2.c ...)
target_link_libraries(Executable2 Module1 Module2)

如果以这种方式进行操作,则在编译Module1时会出错。

错误表明找不到某些标头。 这些标题位于“ Library2”目录中。

如果我在最上面的CMakeLists.txt中注释掉Executable2,一切都可以编译。

因此,问题是如何强制CMake执行“ Library2 / CMakeLists.txt”中的指令,或者我该怎么做才能添加所需的包含目录? 我想我可以将它们直接添加到“ Module1”和“ Module2”的CMakeLists.txt中,但是我认为这不是一个好习惯。

好吧,一段时间后,我自己找到了一种解决方法。 我无法让Cmake不忽略Library2 CMakeLists.txt,所以我只是在Module1和Module2 CMakeLists.txt中添加了缺少的指向Library2的include_directory。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM