Zoeken…


Eenvoudige aanpak zonder pakketten

Voorbeeld dat een uitvoerbaar bestand (editor) bouwt en er een bibliotheek (markering) aan koppelt. Projectstructuur is eenvoudig, het heeft een master CMakeLists en een map nodig voor elk subproject:

CMakeLists.txt
editor/
    CMakeLists.txt
    src/
        editor.cpp
highlight/
    CMakeLists.txt
    include/
        highlight.h
    src/
        highlight.cpp

De master CMakeLists.txt bevat globale definities en add_subdirectory aanroep voor elk subproject:

cmake_minimum_required(VERSION 3.0)
project(Example)

add_subdirectory(highlight)
add_subdirectory(editor)

CMakeLists.txt voor de bibliotheek wijst bronnen toe en neemt er mappen aan op. Door target_include_directories() plaats van include_directories() de include-mappen doorgegeven aan bibliotheekgebruikers:

cmake_minimum_required(VERSION 3.0)
project(highlight)

add_library(${PROJECT_NAME} src/highlight.cpp)
target_include_directories(${PROJECT_NAME} PUBLIC include)

CMakeLists.txt voor de toepassing wijst bronnen toe en koppelt de markeringsbibliotheek. Paden naar binaire hightlighter en omvat worden automatisch behandeld door cmake:

cmake_minimum_required(VERSION 3.0)
project(editor)

add_executable(${PROJECT_NAME} src/editor.cpp)
target_link_libraries(${PROJECT_NAME} PUBLIC highlight)


Modified text is an extract of the original Stack Overflow Documentation
Licentie onder CC BY-SA 3.0
Niet aangesloten bij Stack Overflow