I'm using the submodule GitHub inside my project and now I want to use the target_include_directories
for including the file inside the my project class
This is my cmake configuration
cmake_minimum_required(VERSION 3.9)
project(SpyCBlock)
set(CMAKE_CXX_STANDARD 14)
#bitcoin rpc lib
find_library(bitcoinapi 0.3 REQUIRED)
target_include_directories(rapidjson PUBLIC include/rapidjson/include)
target_include_directories(spycblockrpc PUBLIC include/spycblockrpc)
target_include_directories(btccryptography PUBLIC include/bitcoin-cryptography-library)
add_executable(
${PROJECT_NAME}
#other inclusion file cpp
#cpp-properties file include
include/cpp-properties/src/Properties.cpp
include/cpp-properties/src/PropertiesParser.cpp
include/cpp-properties/src/PropertiesUtils.cpp
#include bitcoin-cryptography-library
include/bitcoin-cryptography-library/cpp/Sha256.cpp
include/bitcoin-cryptography-library/cpp/Sha256Hash.cpp
include/bitcoin-cryptography-library/cpp/Utils.cpp
#include spycblocrpc
include/spycblockrpc/core/graph/TransactionGraph.cpp
include/spycblockrpc/core/graph/WrapperInformations.cpp
include/spycblockrpc/ConfiguratorSingleton.cpp
include/spycblockrpc/commands/DecodeScriptCommand.cpp
include/spycblockrpc/commands/DecodeRawTransaction.cpp
include/spycblockrpc/commands/HeightBlockchainCommand.cpp
include/spycblockrpc/commands/DecodeBlockAtIndexCommand.cpp
)
#bitcoin rpc lib
target_link_libraries(SpyCBlockTests bitcoinapi)
target_link_libraries(${PROJECT_NAME} bitcoinapi)
When run CMake I have this error
Starting to parse CMake project.
CMake Error at CMakeLists.txt:20 (target_include_directories):
Cannot specify include directories for target "rapidjson" which is not
built by this project.
CMake Error at CMakeLists.txt:22 (target_include_directories):
Cannot specify include directories for target "spycblockrpc" which is not
built by this project.
CMake Error at CMakeLists.txt:24 (target_include_directories):
Cannot specify include directories for target "btccryptography" which is
not built by this project.
CMake Error at CMakeLists.txt:26 (target_compile_definitions):
Cannot specify compile definitions for target "cppproperties" which is not
built by this project.
I'm new with the C++ and the cmake and I can't understand what I'm wrong
include_directories(x/y) affects directory scope. All targets in this CMakeList, as well as those in all subdirectories added after the point of its call, will have the path x/y added to their include path. target_include_directories(t x/y) has target scope—it adds x/y to the include path for target t .
To include headers in CMake targets, use the command target_include_directories(...) . Depending on the purpose of the included directories, you will need to define the scope specifier – either PUBLIC , PRIVATE or INTERFACE .
Specifies include directories to use when compiling a given target. The named <target> must have been created by a command such as add_executable() or add_library() and must not be an ALIAS target. By using AFTER or BEFORE explicitly, you can select between appending and prepending, independent of the default.
A CMake-based buildsystem is organized as a set of high-level logical targets. Each target corresponds to an executable or library, or is a custom target containing custom commands.
I want to add the solution to this problem, as suggested in the comments, the code has two problems:
target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>/include/rapidjson/include)
target_include_directories(SpyCBlock ...)
is defined before the add_executable(${PROJECT_NAME} ...)
A minimal correct example is:
add_executable(
${PROJECT_NAME}
#other inclusion file cpp
#cpp-properties file include
include/cpp-properties/src/Properties.cpp
include/cpp-properties/src/PropertiesParser.cpp
include/cpp-properties/src/PropertiesUtils.cpp
#include bitcoin-cryptography-library
include/bitcoin-cryptography-library/cpp/Sha256.cpp
include/bitcoin-cryptography-library/cpp/Sha256Hash.cpp
include/bitcoin-cryptography-library/cpp/Utils.cpp
#include spycblocrpc
include/spycblockrpc/core/graph/TransactionGraph.cpp
include/spycblockrpc/core/graph/WrapperInformations.cpp
include/spycblockrpc/ConfiguratorSingleton.cpp
include/spycblockrpc/commands/DecodeScriptCommand.cpp
include/spycblockrpc/commands/DecodeRawTransaction.cpp
include/spycblockrpc/commands/HeightBlockchainCommand.cpp
include/spycblockrpc/commands/DecodeBlockAtIndexCommand.cpp
)
target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>/include/rapidjson/include)
Now I can include the library like this <bitcoin-cryptography-library/Sha256.h>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With