Coder Social home page Coder Social logo

arthursonzogni / nlohmann_json_cmake_fetchcontent Goto Github PK

View Code? Open in Web Editor NEW
76.0 5.0 25.0 563 KB

A lightweight Release-tracking repository for nlohmann/json. Suitable for CMake fetchcontent. Automatically upgraded every weeks.

License: MIT License

CMake 2.40% Meson 0.07% Python 0.39% C++ 97.15%
cmake nlohmann json fetchcontent

nlohmann_json_cmake_fetchcontent's Introduction

This repository is not more useful. Indeed, since v3.11.3, you can use:

include(FetchContent)

FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz)
FetchContent_MakeAvailable(json)

target_link_libraries(foo PRIVATE nlohmann_json::nlohmann_json)

Release-tracking repository for nlohmann/json

Goal is to provide a lightweight and autonomous repository tracking every releases of nlohmann/json.

It is meant to be used with CMake FetchContent.

You can always replace the URL by the official repository: https://github.com/nlohmann/json. The only differences are:

Example

include(FetchContent)

# Optional: set this to ON if your target publicly links to nlohmann_json and needs to install() 
# set(JSON_Install ON)

FetchContent_Declare(json
  GIT_REPOSITORY https://github.com/ArthurSonzogni/nlohmann_json_cmake_fetchcontent
  GIT_PROGRESS TRUE  GIT_SHALLOW TRUE
  GIT_TAG v3.11.2)

FetchContent_MakeAvailable(json)

target_link_libraries(foo PRIVATE nlohmann_json::nlohmann_json)

Unsupported options

The following options are currently not supported. This is done on purpose because they do not really make sense for a mirror repository, or they have not been thoroughly tested. Consider using the official repository if you need these options.

  • JSON_CI
  • JSON_BuildTests

Updates

This repository is fully autonomous. It updates itself every week using github actions.

Thanks

This repository is based on: astoeckel/json.

Addressed nlohmann/json issues:

nlohmann_json_cmake_fetchcontent's People

Contributors

actions-user avatar arthursonzogni avatar frago9876543210 avatar nicolasiragne avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

nlohmann_json_cmake_fetchcontent's Issues

Last update is broken if using MSVC

Linking to json gives the following error:

[cmake] CMake Error at CMakeLists.txt:299 (add_library):
[cmake]   Cannot find source file:
[cmake] 
[cmake]     C:/Users/nicor/source/repos/TestProject/build/_deps/json-src/nlohmann_json.natvis
[cmake] 
[cmake] 

This is due to this bit from the upstream CMakeLists.txt:

## add debug view definition file for msvc (natvis)
if (MSVC)
    set(NLOHMANN_ADD_NATVIS TRUE)
    set(NLOHMANN_NATVIS_FILE "nlohmann_json.natvis")
    target_sources(
        ${NLOHMANN_JSON_TARGET_NAME}
        INTERFACE
            $<INSTALL_INTERFACE:${NLOHMANN_NATVIS_FILE}>
            $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${NLOHMANN_NATVIS_FILE}>
    )
endif()

The INTERFACE keyword causes the file to be added to the sources of any target that links to nlohmann_json::nlohmann_json.

Cant seem to include library with cmake fetch.

I'm trying to build an application with this library but either I'm making a mistake(most likely) or cmake fetch is not working.

I copied the code section exactly as it is in the readme and I can see that it downloads the repo, creates the files and headers but the compiler cant seem to find the header.

What could I be doing wrong?

Here is my cmake file as it is now:

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)

include(FetchContent)
LINK_DIRECTORIES(/usr/local/lib)

FetchContent_Declare(json
  GIT_REPOSITORY https://github.com/ArthurSonzogni/nlohmann_json_cmake_fetchcontent.git
  GIT_TAG v3.9.1)
  
  FetchContent_GetProperties(json)
if(NOT json_POPULATED)
  FetchContent_Populate(json)
  add_subdirectory(${json_SOURCE_DIR} ${json_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()


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 )


include_directories(${Boost_INCLUDE_DIRS} ${MYSQL_INCLUDE_DIR} ${json_SOURCE_DIR})

target_link_libraries(vts PRIVATE
        Boost::system
		${AWSSDK_LINK_LIBRARIES}
        ${MYSQL_CLIENT_LIBS}
		nlohmann_json::nlohmann_json
		served libserved.so
        )

I also tried downloading, building and installing the library manually and using find_package(nlohmann_json 3.2.0 REQUIRED) and it will find the package and begin compiling but it also failed to find the include files.

Also tried adding /include after ${json_SOURCE_DIR}

CMake shows no errors, I'm on CentOS 8 and using GCC 8. Thanks!

json_fwd.hpp broken since v3.11.0

Since v3.11.0 the json_fwd.hpp contains an include of nlohmann/detail/abi_macros.hpp which is of course missing from this repo. As a result including json_fwd.hpp fails.

While the amalgamated json_fwd.hpp is missing from v3.11.0 and v3.11.1 in the original repo, there's one for v3.11.2 with the include correctly amalgamated: nlohmann/json/.../json_fwd.hpp

Build with MSVC is broken

Attempt to use nlohmann_json_cmake_fetchcontent with Visual Studio result in this error:

CMake Error at CMakeLists.txt:14 (add_executable):
  Cannot find source file:

    build/_deps/json-src/nlohmann_json.natvis

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
  .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .ispc


-- Generating done
CMake Generate step failed.  Build files cannot be regenerated correctly.
  • it's because of this section in the CMakeLists.txt:
## add debug view definition file for msvc (natvis)
if (MSVC)
    set(NLOHMANN_ADD_NATVIS TRUE)
    set(NLOHMANN_NATVIS_FILE "nlohmann_json.natvis")
.....

nlohmann_json.natvis needs to be added to this repo

Invalid fetch content link

I accidentally noticed that the link for fetch content does not matches with repository name
img1
maybe rename repo to more shorter name back?

JSON_MultipleHeaders is turned on by default, but include folder is not there

Given the following CMakeLists.txt:

include(FetchContent)

FetchContent_Declare(json
        GIT_REPOSITORY https://github.com/ArthurSonzogni/nlohmann_json_cmake_fetchcontent
        GIT_PROGRESS TRUE
        GIT_SHALLOW TRUE
        GIT_TAG v3.11.2)
FetchContent_MakeAvailable(json)

target_link_libraries(MineSweeperSolver PRIVATE nlohmann_json::nlohmann_json)

I saw this error:

[1/10] Building CXX object CMakeFiles/MineSweeperSolver.dir/main.cpp.o
FAILED: CMakeFiles/MineSweeperSolver.dir/main.cpp.o 
/usr/bin/c++  -I/home/b1f6c1c4/MineSweeperProb/MineSweeperSolver/cmake-build-debug/_deps/json-src/include -g -flto -fno-fat-lto-objects -march=znver3 -Wall -Wextra -Werror -Wno-parentheses -Wno-missing-field-initializers -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wno-unknown-pragmas -Wno-sign-compare -std=gnu++23 -MD -MT CMakeFiles/MineSweeperSolver.dir/main.cpp.o -MF CMakeFiles/MineSweeperSolver.dir/main.cpp.o.d -o CMakeFiles/MineSweeperSolver.dir/main.cpp.o -c /home/b1f6c1c4/MineSweeperProb/MineSweeperSolver/main.cpp
/home/b1f6c1c4/MineSweeperProb/MineSweeperSolver/main.cpp:7:10: fatal error: nlohmann/json.hpp: No such file or directory
    7 | #include <nlohmann/json.hpp>
      |          ^~~~~~~~~~~~~~~~~~~
compilation terminated.
[9/10] Building CXX object CMakeFiles/MineSweeperSolver.dir/BinomialHelper.cpp.o
ninja: build stopped: subcommand failed.

Looking into cmake-build-debug/_deps/json-src/ I could not find the include folder.

The fix should be adding the following to CMakeLists.txt:

set(JSON_MultipleHeaders OFF)

Commit hash of version tag has changed

First of all, thank you for this repo. It is very helpful for minimizing bandwidth consumption during continuous integration.

I use the repo via CMake's FetchContent, but referring to the commit hash rather than to the version tag, to avoid that CMake checks the repo each time. I observed that the hash corresponding with v3.7.3 has changed. Is this a one time change, or will that happen again in the future ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.