I'm trying to build a program that uses nlohmann::json but I'm having an issue with the includes. As per the instructions I'm using find_package(nlohmann_json 3.9.0 REQUIRED)
and CMake will find the package but when I build I get an error telling me: fatal error: nlohmann\json.hpp: No such file or directory
This is the output of CMake:
Found nlohmann_json: /usr/local/lib64/cmake/nlohmann_json/nlohmann_jsonConfig.cmake (found suitable version "3.9.1", minimum required is "3.9.0")
-- Configuring done
-- Generating done
-- Build files have been written to: /root/vts/build
And here is my full CMake file
cmake_minimum_required(VERSION 3.10)
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
project(vitanza-service CXX)
add_subdirectory(VitanzaService)
add_executable(vts ${vts_SRC})
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set_target_properties(vts PROPERTIES CXX_STANDARD 14)
set_target_properties(vts PROPERTIES CXX_STANDARD_REQUIRED ON)
LINK_DIRECTORIES(/usr/local/lib)
if (NOT WIN32)
add_compile_options(-Wall -Werror -pipe -fvisibility=hidden)
endif ()
set(CMAKE_CXX_FLAGS_PERFORMANCE "${CMAKE_CXX_FLAGS_RELEASE} -march=native")
if (CMAKE_COMPILER_IS_GNUCXX)
add_compile_options(-fno-strict-aliasing)
endif ()
find_package(AWSSDK REQUIRED COMPONENTS dynamodb)
find_package(MySQL REQUIRED)
find_package(Boost 1.53.0 REQUIRED COMPONENTS system)
find_package(nlohmann_json 3.9.0 REQUIRED)
include_directories(${Boost_INCLUDE_DIRS} ${MYSQL_INCLUDE_DIR})
target_link_libraries(vts PRIVATE
Boost::system
${AWSSDK_LINK_LIBRARIES}
${MYSQL_CLIENT_LIBS}
nlohmann_json::nlohmann_json
served libserved.so
)
I'm not sure what the issue is. Am I supposed to add another variable in include_directories
? I even tried adding the path to the include directory but that did not work either.
I also tried using add_path and adding that path to include_directories:
find_path(JSON_INCLUDE_DIR nlohmann/json.hpp
/usr/local/include)
...
include_directories(${JSON_INCLUDE_DIR})
Finally I tried using FetchContent as outlined here, but nothing seems to work.
I'm on CentOS 8 using GCC 8 and the latest version of nlohmann::json(I built it from source, including make install
). Just tried it in Debian 10 and I have the same issue.
Thanks!