I’m working on a C++ project that exports a bunch of libraries and tries to make use of CMakePackageConfigHelpers
to be findable using find_package
. After installation, projects attempting to make use of it, like:
cmake_minimum_required(VERSION 3.18)
project(jsontoolkit_hello VERSION 0.0.1 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
find_package(JSONToolkit REQUIRED)
add_executable(jsontoolkit_hello hello.cc)
target_link_libraries(jsontoolkit_hello PRIVATE sourcemeta::jsontoolkit::json)
Face the following error:
CMake Error in CMakeLists.txt:
Imported target "sourcemeta::jsontoolkit::json" includes non-existent path
"/include"
in its INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:
* The path was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and references files it does not
provide.
The find_package
command correctly finds JSONToolkit, which on my system is located at: <prefix>/lib/cmake/jsontoolkit/JSONToolkitConfig.cmake
. I can confirm this file is getting loaded if add any message()
commands to it. This file does the following:
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_jsontoolkit_json.cmake")
Which is located at lib/cmake/jsontoolkit/sourcemeta_jsontoolkit_json.cmake
and correctly gets loaded. This file contains the following:
set_target_properties(sourcemeta::jsontoolkit::json PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "JSONTOOLKIT_BACKEND_RAPIDJSON"
INTERFACE_COMPILE_OPTIONS "<..............>"
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
INTERFACE_LINK_LIBRARIES "rapidjson"
)
If I print ${_IMPORT_PREFIX}/include
next to this declaration, I get: /Users/jviotti/Projects/sourcemeta/jsontoolkit/build/dist/include
, which exists and matches the expected prefix:
$ tree /Users/jviotti/Projects/sourcemeta/jsontoolkit/build/dist/include
/Users/jviotti/Projects/sourcemeta/jsontoolkit/build/dist/include
└── jsontoolkit
├── json
│ ├── iterators.h
│ ├── rapidjson
│ │ ├── common.h
│ │ ├── iterators.h
│ │ ├── read.h
│ │ └── write.h
│ ├── read.h
│ └── write.h
├── json.h
├── jsonschema
│ └── resolver.h
└── jsonschema.h
5 directories, 10 files
So why can’t CMake find it? I can confirm the error is around the INTERFACE_INCLUDE_DIRECTORIES
, as if I modify the declaration of that line, the error message is reflected accordingly.
Am I missing anything?
Relevant links, in case its useful:
- Repository and commit (in case you want to try it out locally): GitHub - sourcemeta/jsontoolkit at ed13d9a696b8de53d44713ae832ca13892a65326
- Declaration of the
sourcemeta::jsontoolkit::json
library: https://github.com/sourcemeta/jsontoolkit/blob/ed13d9a696b8de53d44713ae832ca13892a65326/src/json/CMakeLists.txt - Config in file: https://github.com/sourcemeta/jsontoolkit/blob/ed13d9a696b8de53d44713ae832ca13892a65326/cmake/JSONToolkitConfig.cmake.in
Here is a GitHub Actions run highlighting steps being ran and a full example of the error: Make the project consumable by CMake `find_package()` · sourcemeta/jsontoolkit@ed13d9a · GitHub