diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite index db03315..767335a 100644 Binary files a/.vs/slnx.sqlite and b/.vs/slnx.sqlite differ diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ecb5af..d4e26cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,10 +33,9 @@ source_group(TREE ${SRC_DIR} PREFIX "src" FILES ${SRC_MAIN} ) target_include_directories(SCAPI PRIVATE "${SRC_DIR}" - "${json_SOURCE_DIR}/single_include" ) -target_link_libraries(SCAPI PRIVATE botan pugixml cpr json) +target_link_libraries(SCAPI PRIVATE botan pugixml cpr nlohmann_json::nlohmann_json) # Warnings as errors set_property(TARGET SCAPI PROPERTY COMPILE_WARNING_AS_ERROR ON) diff --git a/scripts/json.cmake b/scripts/json.cmake index 652c52c..9c846cb 100644 --- a/scripts/json.cmake +++ b/scripts/json.cmake @@ -7,4 +7,33 @@ FetchContent_Declare( GIT_PROGRESS TRUE ) message("json") -FetchContent_MakeAvailable(json) \ No newline at end of file + +FetchContent_MakeAvailable(json) + +# Some nlohmann json CMake scripts add a reference to a natvis file +# which may be missing in certain FetchContent sources. Create an empty +# natvis file for MSVC builds to avoid "Cannot find source file" errors. +if(MSVC) + if(NOT EXISTS "${json_SOURCE_DIR}/nlohmann_json.natvis") + file(WRITE "${json_SOURCE_DIR}/nlohmann_json.natvis" "\n") + endif() +endif() + +# Remove any .natvis INTERFACE source added by the nlohmann_json target to avoid +# CMake complaining about missing files when the natvis is not present in the +# fetchcontent checkout. This filters SOURCES on the imported target. +if(TARGET nlohmann_json) + get_target_property(_json_sources nlohmann_json SOURCES) + if(_json_sources) + set(_filtered_json_sources) + foreach(_s IN LISTS _json_sources) + if(NOT _s MATCHES ".*\\.natvis$") + list(APPEND _filtered_json_sources "${_s}") + endif() + endforeach() + if(_filtered_json_sources) + # overwrite SOURCES property without natvis entries + set_property(TARGET nlohmann_json PROPERTY SOURCES "${_filtered_json_sources}") + endif() + endif() +endif()