CMake subdirectories dependency

▼魔方 西西 提交于 2019-11-30 11:28:21

Adding a subdirectory does not do much more than specify to CMake that it should enter the directory and look for another CMakeLists.txt there. You still need to create a library with the source files with add_library and link it to your executable with target_link_libraries. Something like the following:

In the subdir CMakeLists.txt

set( component_SOURCES ... ) # Add the source-files for the component here
# Optionally you can use file glob (uncomment the next line)
# file( GLOB component_SOURCES *.cpp )below

add_library( component ${component_SOURCES} )

Top-dir CMakeLists.txt

project( gear2d )
add_subdirectory( component )
add_executable( gear2d object.cc main.cc )
target_link_libraries( gear2d component )
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!