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 errors when not using embedded json #241

Closed
samwarring opened this issue May 26, 2022 · 1 comment
Closed

CMake errors when not using embedded json #241

samwarring opened this issue May 26, 2022 · 1 comment

Comments

@samwarring
Copy link

My project includes both inja and nlohmann/json as git submodules.

myproject
 - lib
   - json (git submodule)
   - inja (git submodule)
 - src
   - myproject.cpp
 - CMakeLists.txt

CMakeLists.txt pulls in the submodules with add_subdirectory(). By default INJA_USE_EMBEDDED_JSON is ON, and this results in the following CMake error:

 CMake Error at lib/inja/CMakeLists.txt:42 (add_library):
   add_library cannot create target "nlohmann_json" because another target
   with the same name already exists.  The existing target is an interface
   library created in source directory
   "/home/sam/GitHub/samwarring/nlf/lib/json".  See documentation for policy
   CMP0002 for more details.

This makes sense, since I've provided my own copy of nlohmann/json. However, if I set INJA_USE_EMBEDDED_JSON to OFF, I still get an error at generate-time:

 -- Configuring done
 CMake Error: install(EXPORT "injaTargets" ...) includes target "inja" which requires target "nlohmann_json" that is not in any export set.
 CMake Error in lib/inja/CMakeLists.txt:
   export called with target "inja" which requires target "nlohmann_json" that
   is not in any export set.
 
 
 -- Generating done
 CMake Generate step failed.  Build files cannot be regenerated correctly.

After disabling INJA_EXPORT and INJA_INSTALL, I'm still getting the above error. I think this is due to CMakeLists.txt:141 and CMakeLists:144, which have naked install and export commands that aren't wrapped with if (INJA_INSTALL) and if (INJA_EXPORT). I found wrapping those commands with if-statements fixes the problem. This might be the correct fix, but I could be misunderstanding.

@samwarring
Copy link
Author

I should have checked the commit and issue history 🤦‍♂️ Looks like it's already reported in #237 and fixed on master. I was using the latest official release so I didn't see the change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant