Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake target nlohmann_json does not have src into its interface includes #741

Closed
sogartar opened this issue Sep 13, 2017 · 14 comments
Closed
Assignees
Labels
solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Milestone

Comments

@sogartar
Copy link

If you do in CMake:

add_subdirectory(nlohmann/json)
target_link_libraries(my_target PRIVATE nlohmann_json)

Then my_target does not have nlohmann/json/src into its includes, where json.hpp is. You can not properly include this project into other CMake projects.
Note that in v2.1.1 it used to be OK.

@nlohmann
Copy link
Owner

maybe related: #695

@dan-42
Copy link
Contributor

dan-42 commented Sep 19, 2017

@sogartar what system do you use? Windows? Mac? Linux?
have you installed it first via?

cmake
make
make install

If the usage you described is a common one (I did never useed 3rdparty CMake-Projekts like this)
Then indeed this might be a BUG.
Please not that the up comming version V3.0.0 will bring breaking changes including the usage of build-tools and package-managers. see #698

@dan-42
Copy link
Contributor

dan-42 commented Sep 19, 2017

@sogartar I forgot, a simpler oneliner for your case could be

include_directory(nlohmann/json/src)

@nlohmann
Copy link
Owner

Is there anything to be done to close this issue?

@sogartar
Copy link
Author

I think you should add nlohmann/json/src to the public includes of the nlohmann_json target. See target_include_directories.

@dan-42
Copy link
Contributor

dan-42 commented Oct 2, 2017

Well @sogartar thx for answering any of my questions. so IMHO I would ignore it.

But I will have a look and see what impact the suggestion would be.

@nlohmann nlohmann added state: help needed the issue needs help to proceed state: please discuss please discuss the issue or vote for your favorite option labels Oct 2, 2017
@nlohmann
Copy link
Owner

nlohmann commented Oct 5, 2017

Does anyone has an idea how to proceed here?

@nlohmann
Copy link
Owner

Issue #790 also proposes to change the include dir.

@nlohmann
Copy link
Owner

Sorry, #790 is unrelated to this issue.

@nlohmann nlohmann added state: needs more info the author of the issue needs to provide more details and removed state: help needed the issue needs help to proceed state: please discuss please discuss the issue or vote for your favorite option labels Nov 25, 2017
@nlohmann
Copy link
Owner

I need more info on this issue. What needs to be fixed? Is there example code to demonstrate the issue?

@theodelrieu
Copy link
Contributor

Playing with target_include_directories and generator expressions should do the trick.

I'll open a PR tomorrow morning.

@nlohmann nlohmann added solution: proposed fix a fix for the issue has been proposed and waits for confirmation and removed state: needs more info the author of the issue needs to provide more details labels Dec 6, 2017
@nlohmann nlohmann self-assigned this Dec 6, 2017
@nlohmann nlohmann added this to the Release 3.0.0 milestone Dec 6, 2017
@pfaco
Copy link

pfaco commented Jul 2, 2018

I think there is still some problem in the include directories.

I installed the lib with the following commands:

cmake -DCMAKE_INSTALL_PREFIX=C:/cmake -G "Unix Makefiles"
make install

So I got the lib at C:/cmake/include/nlohmann/json.hpp
and the cmake files at C:/cmake/lib/cmake/nlohmann_json

My cmake project is really simple:

cmake_minimum_required(VERSION 3.10)
project(test_cpp)

set(CMAKE_CXX_STANDARD 17)

find_package(nlohmann_json 3.1.2)

add_executable(test_cpp main.cpp)

target_link_libraries(test_cpp PRIVATE nlohmann_json)

The find_package and target_link_libraries commands work well.
When trying to include the header it doesn't work (cannot find the header).
I tried the following without success:
#include <nlohmann/json.hpp>
#include <json.hpp>

I'm not so experienced with cmake so I might be doing something wrong, although I have successfully used many other libraries following the same procedure.

Any sugestions on how to tackle this? @dan-42 @theodelrieu

@theodelrieu
Copy link
Contributor

Could you try nlohmann_json::nlohmann_json? The target should be inside a namespace IIRC.

@pfaco
Copy link

pfaco commented Jul 2, 2018

Could you try nlohmann_json::nlohmann_json? The target should be inside a namespace IIRC.

Yes, that solved it! Just added nlohmann_json::nlohmann_json to the target_link_libraries command. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

5 participants