mercredi 1 avril 2020

CMake does not include path to link libraries when compiling

So my directory structure is like

/
-- CMakeLists.txt

-- bencode/
---- bType.hpp
---- bType.cpp
---- Decoder.hpp
---- Decoder.cpp
---- CMakeLists.txt

-- torrent/
---- main.cpp
---- Torrent.hpp
---- Torrent.cpp
---- Tracker.hpp
---- Tracker.cpp
---- CMakeLists.txt

The root CMakeLists.txt is

cmake_minimum_required(VERSION 3.16)
project(Torrent VERSION 1.0.0)
add_subdirectory(bencode)
add_subdirectory(torrent)

The bencode/CMakeLists.txt is

add_library(
    Decoder
    Decoder.hpp
    Decoder.cpp
)
add_library(
    bType
    bType.hpp
    bType.cpp
)
target_include_directories(bType PRIVATE "${CMAKE_CURRENT_SOURCE/_DIR}")
target_include_directories(Decoder PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")

The torrent/CMakeLists.txt is

add_library(
    Torrent
    Torrent.hpp
    Torrent.cpp
)
add_library(
    Tracker
    Tracker.hpp
    Tracker.cpp
)
add_executable(main main.cpp)
target_link_libraries(
    main PRIVATE
    Torrent Tracker
    Decoder bType
)

Whenever I build, the Torrent.cpp compilation fails, as it includes Decoder.hpp which is not in the same directory, and the build command does not inlcude the path while compilation

[build] ../torrent/Torrent.cpp:5:10: fatal error: Decoder.hpp: No such file or directory
[build]  #include <Decoder.hpp>
[build]           ^~~~~~~~~~~~~
[build] comp

There should have been a -I flag while compiling but there isn't.

Help me figure out why?

Aucun commentaire:

Enregistrer un commentaire