Arbeiten mit Unterverzeichnissen

Letzte Änderung: 13.01.2018

Frage: Wie bringe ich CMake die Unterverzeichnisse auch mit zu verwenden?

Antwort 1: Verzeichnisname vor die Datei schreiben

set(SOURCE
    main.cpp
    foo/fooA.cpp
    foo/fooB.cpp
    bar/fileA.cpp
    bar/barx/file1.cpp
)
add_executable(MYAPP ${SOURCE})

Antwort 2: Baum von mehreren CMakeLists.txt anlegen

  • Jedes Verzeichnis enthält eine CMakeLists.txt
  • Jede CMakeLists.txt bindet die Sourcen und die Unterverzeichnisse ein
add_subdirectory(log)
add_subdirectory(net)
add_subdirectory(parallel)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/parallel SRC_LIST)

set(SOURCES
    ${SOURCES}
    # header only
    ${CMAKE_CURRENT_SOURCE_DIR}/ttnassert.h
    ${CMAKE_CURRENT_SOURCE_DIR}/ttnbyte.h
    ${CMAKE_CURRENT_SOURCE_DIR}/ttnlib.h
    ${CMAKE_CURRENT_SOURCE_DIR}/ttndefine.h
    ${CMAKE_CURRENT_SOURCE_DIR}/ttntypecast.h
    # implementations
    ${CMAKE_CURRENT_SOURCE_DIR}/ttnbitvector.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/ttndatetime.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/ttnfile.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/ttnfileinfo.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/ttnlogic.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/ttnpath.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/ttnstring.cpp
    PARENT_SCOPE
)




© 2003-2018 th-thielemann.de