C++ cmake——让子目录使用它自己的Makefile
我有一个主要使用CMake的项目 但是,第三方/传统库中有一个子目录。它有一个Makefile,可以将自己编译成第三方。一个库文件 我自己的CMakeLists.txt能否调用该Makefile,生成它的第三方.a库,并让我的代码链接到它?我不想将其遗留的Makefile修改为CMakeLists.txtC++ cmake——让子目录使用它自己的Makefile,c++,linux,makefile,cmake,C++,Linux,Makefile,Cmake,我有一个主要使用CMake的项目 但是,第三方/传统库中有一个子目录。它有一个Makefile,可以将自己编译成第三方。一个库文件 我自己的CMakeLists.txt能否调用该Makefile,生成它的第三方.a库,并让我的代码链接到它?我不想将其遗留的Makefile修改为CMakeLists.txt ├── my_source_folder_1 ├── my_source_folder_2 ├── CMakeLists.txt ├── 3rd_party │ ├── 3rd_party
├── my_source_folder_1
├── my_source_folder_2
├── CMakeLists.txt
├── 3rd_party
│ ├── 3rd_party_source
│ ├── 3rd_party_make
│ | ├── Makefile
谢谢 相关:
从上面的链接可以看出,您可以使用一个特殊命令来概述CMake应该如何创建目标:
add_custom_target(
extern_lib
COMMAND make
WORKING_DIRECTORY full_path to where Makefile is located
)
add_executable(myexecutable myexcutable.c)
target_link_libraries(myexecutable full_path_to_generated_library)
add_dependencies(myexecutable extern_lib)
这应该足够让你离开地面了