I am trying to add this header-only library to my project : https://github.com/CPPAlliance/url
My project structure :
├── build
│ ├── build.ninja
│ ├── CMakeCache.txt
│ ├── CMakeFiles
│ │ ├── 3.18.0-rc1
│ │ │ ├── CMakeCCompiler.cmake
│ │ │ ├── CMakeCXXCompiler.cmake
│ │ │ ├── CMakeDetermineCompilerABI_C.bin
│ │ │ ├── CMakeDetermineCompilerABI_CXX.bin
│ │ │ ├── CMakeSystem.cmake
│ │ │ ├── CompilerIdC
│ │ │ └── CompilerIdCXX
│ │ ├── cmake.check_cache
│ │ ├── CMakeError.log
│ │ ├── CMakeOutput.log
│ │ ├── CMakeTmp
│ │ ├── cmake.verify_globs
│ │ ├── hftbot.dir
│ │ │ ├── build.make
│ │ │ ├── cmake_clean.cmake
│ │ │ ├── CXX.includecache
│ │ │ ├── DependInfo.cmake
│ │ │ ├── depend.internal
│ │ │ ├── depend.make
│ │ │ ├── flags.make
│ │ │ ├── link.txt
│ │ │ ├── progress.make
│ │ │ └── src
│ │ ├── Makefile2
│ │ ├── Progress
│ │ │ ├── 1
│ │ │ └── count.txt
│ │ ├── progress.marks
│ │ ├── rules.ninja
│ │ ├── TargetDirectories.txt
│ │ └── VerifyGlobs.cmake
│ ├── cmake_install.cmake
│ ├── compile_commands.json
│ ├── details.json
│ ├── external
│ │ ├── json
│ │ │ ├── CMakeFiles
│ │ │ └── cmake_install.cmake
│ │ └── url
│ │ ├── CMakeFiles
│ │ └── cmake_install.cmake
│ ├── hftbot
│ ├── Makefile
│ └── src
│ ├── CMakeFiles
│ │ ├── CMakeDirectoryInformation.cmake
│ │ └── progress.marks
│ ├── cmake_install.cmake
│ └── Makefile
├── build.sh
├── CMakeLists.txt
├── configure.sh
├── details.json
├── external
│ └── urlib
│ ├── build
│ │ └── Jamfile
│ ├── cmake
│ │ ├── config.cmake.in
│ │ └── toolchains
│ ├── CMakeLists.txt
│ ├── doc
│ │ ├── images
│ │ ├── Jamfile
│ │ ├── javadoc.hpp
│ │ ├── qbk
│ │ ├── README.md
│ │ ├── tools
│ │ └── xsl
│ ├── extra
│ │ ├── include
│ │ └── test_main.cpp
│ ├── include
│ │ └── boost
│ ├── Jamfile
│ ├── LICENSE_1_0.txt
│ ├── meta
│ │ ├── explicit-failures-markup.xml
│ │ └── libraries.json
│ ├── README.md
│ ├── src
│ │ └── src.cpp
│ └── test
│ ├── CMakeLists.txt
│ ├── Jamfile
│ ├── limits
│ ├── unit
│ └── wpt
├── run.sh
└── src
├── CMakeLists.txt
├── httpClient.cpp
└── WebsocketClient.cpp
CMakeLists.txt
in the root folder :
cmake_minimum_required(VERSION 3.18.0)
project(hftbot)
find_package(Boost 1.79.0 REQUIRED COMPONENTS system thread filesystem container)
find_package(Threads REQUIRED)
add_subdirectory(src)
include_directories(SYSTEM external/urlib/include)
set(URLIB_DIRECTORY "external/urlib/include")
set(URLIB_HEADERS ${URLIB_DIRECTORY}/boost/url.hpp ${URLIB_DIRECTORY}/boost/url/src.hpp)
set(SOURCES src/httpClient.cpp)
add_executable(${PROJECT_NAME} ${SOURCES} ${URLIB_HEADERS})
target_include_directories(${PROJECT_NAME} PRIVATE ${URLIB_DIRECTORY})
As you can see i used target_include_directories()
to include header files into my project.
but it seems that something is wrong here.
#include <boost/url.hpp>
#include <boost/url/src.hpp>
When i try to include this one, it is showing me build error :
/usr/local/bin/cmake -S/home/user/Desktop/HFTBOT -B/home/user/Desktop/HFTBOT/build --check-build-system CMakeFiles/Makefile.cmake 0
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/Desktop/HFTBOT/build
/usr/local/bin/cmake -E cmake_progress_start /home/user/Desktop/HFTBOT/build/CMakeFiles /home/user/Desktop/HFTBOT/build//CMakeFiles/progress.marks
make -s -f CMakeFiles/Makefile2 all
Scanning dependencies of target hftbot
CMake Error: Directory Information file not found
[ 50%] Building CXX object CMakeFiles/hftbot.dir/src/httpClient.cpp.o
/home/user/Desktop/HFTBOT/src/httpClient.cpp:11:10: fatal error: boost/url/src.hpp: No such file or directory
11 | #include "boost/url/src.hpp"
| ^~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/hftbot.dir/build.make:83: CMakeFiles/hftbot.dir/src/httpClient.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:116: CMakeFiles/hftbot.dir/all] Error 2
make: *** [Makefile:104: all] Error 2
I got a feeling that is it because of the location of executable that produce this error ?
CodePudding user response:
Since your source is not in the project root but in src/
you might have to specify the relative path using ../external/url/include
. A more typical approach in CMake is to use absolute paths:
set(URLIB_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/external/urlib/include")