CMake subdirectories dependency

后端 未结 1 2009
长发绾君心
长发绾君心 2021-02-05 08:34

I am very new to CMake. In fact, I am trying it through Kdevelop4 widh C++.

I have the habit of creating subdirs for every namespace I create, even if all the sources mu

1条回答
  •  爱一瞬间的悲伤
    2021-02-05 09:11

    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 )
    

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