diff --git a/CMakeLists.txt b/CMakeLists.txt index 5796610fa..fd0b24f2b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,12 +28,15 @@ set(NLOHMANN_JSON_TARGET_NAME ${PROJECT_NAME}) set(NLOHMANN_JSON_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" CACHE INTERNAL "") set(NLOHMANN_JSON_INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}") set(NLOHMANN_JSON_TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets") -set(NLOHMANN_JSON_CMAKE_CONFIG_TEMPLATE "cmake/config.cmake.in") +set(NLOHMANN_JSON_CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") +set(NLOHMANN_JSON_CMAKE_CONFIG_TEMPLATE "${NLOHMANN_JSON_CMAKE_MODULE_PATH}/config.cmake.in") set(NLOHMANN_JSON_CMAKE_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}") set(NLOHMANN_JSON_CMAKE_VERSION_CONFIG_FILE "${NLOHMANN_JSON_CMAKE_CONFIG_DIR}/${PROJECT_NAME}ConfigVersion.cmake") set(NLOHMANN_JSON_CMAKE_PROJECT_CONFIG_FILE "${NLOHMANN_JSON_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Config.cmake") set(NLOHMANN_JSON_CMAKE_PROJECT_TARGETS_FILE "${NLOHMANN_JSON_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Targets.cmake") +list(APPEND CMAKE_MODULE_PATH "${NLOHMANN_JSON_CMAKE_MODULE_PATH}") + if (JSON_MultipleHeaders) set(NLOHMANN_JSON_INCLUDE_BUILD_DIR "${PROJECT_SOURCE_DIR}/include/") message(STATUS "Using the multi-header code from ${NLOHMANN_JSON_INCLUDE_BUILD_DIR}") @@ -47,6 +50,44 @@ endif() ## create target and add include path ## add_library(${NLOHMANN_JSON_TARGET_NAME} INTERFACE) + +## We need to list files explicitly before exporting them to Bazel. +set(NLOHMANN_JSON_HEADERS + nlohmann/adl_serializer.hpp + nlohmann/json_fwd.hpp + nlohmann/thirdparty/hedley/hedley_undef.hpp + nlohmann/thirdparty/hedley/hedley.hpp + nlohmann/json.hpp + nlohmann/detail/json_pointer.hpp + nlohmann/detail/value_t.hpp + nlohmann/detail/input/json_sax.hpp + nlohmann/detail/input/lexer.hpp + nlohmann/detail/input/input_adapters.hpp + nlohmann/detail/input/position_t.hpp + nlohmann/detail/input/binary_reader.hpp + nlohmann/detail/input/parser.hpp + nlohmann/detail/iterators/internal_iterator.hpp + nlohmann/detail/iterators/iteration_proxy.hpp + nlohmann/detail/iterators/json_reverse_iterator.hpp + nlohmann/detail/iterators/iterator_traits.hpp + nlohmann/detail/iterators/iter_impl.hpp + nlohmann/detail/iterators/primitive_iterator.hpp + nlohmann/detail/json_ref.hpp + nlohmann/detail/macro_scope.hpp + nlohmann/detail/macro_unscope.hpp + nlohmann/detail/exceptions.hpp + nlohmann/detail/output/output_adapters.hpp + nlohmann/detail/output/serializer.hpp + nlohmann/detail/output/binary_writer.hpp + nlohmann/detail/conversions/from_json.hpp + nlohmann/detail/conversions/to_chars.hpp + nlohmann/detail/conversions/to_json.hpp + nlohmann/detail/meta/void_t.hpp + nlohmann/detail/meta/cpp_future.hpp + nlohmann/detail/meta/detected.hpp + nlohmann/detail/meta/is_sax.hpp + nlohmann/detail/meta/type_traits.hpp +) add_library(${PROJECT_NAME}::${NLOHMANN_JSON_TARGET_NAME} ALIAS ${NLOHMANN_JSON_TARGET_NAME}) if (${CMAKE_VERSION} VERSION_LESS "3.8.0") target_compile_features(${NLOHMANN_JSON_TARGET_NAME} INTERFACE cxx_range_for) @@ -61,6 +102,9 @@ target_include_directories( $ ) +include(CreateBazelConfig) +create_bazel_config(${NLOHMANN_JSON_HEADERS}) + ## add debug view definition file for msvc (natvis) if (MSVC) set(NLOHMANN_ADD_NATVIS TRUE) diff --git a/cmake/CreateBazelConfig.cmake b/cmake/CreateBazelConfig.cmake index 8caa2b4d2..d4fe21f2d 100644 --- a/cmake/CreateBazelConfig.cmake +++ b/cmake/CreateBazelConfig.cmake @@ -13,43 +13,42 @@ # See the License for the specific language governing permissions and # limitations under the License. # -# Tommy Nguyen 07-26-2019 Remove functions we don't need. +# Tommy Nguyen 07-26-2019 Remove functions we don't need. Have the function +# take a list of sources rather than a target. # ~~~ # Generate a Bazel configuration file with the headers and sources for a given -# target. The generated file can be loaded from a BUILD file to create the +# list. The generated file can be loaded from a BUILD file to create the # corresponding targets in Bazel. -function (create_bazel_config TARGET) - if (NOT TARGET ${TARGET}) - message( - FATAL_ERROR "create_bazel_config requires a target name: ${TARGET}") - endif () - set(filename "${TARGET}.bzl") +function (create_bazel_config LIST) + # No need to check for an empty list. CMake will complain for us. + set(_LIST ${LIST} ${ARGN}) + set(filename "nlohmann_json.bzl") + # Create a new file each time. + file(WRITE "${filename}") set(H) set(CC) - get_target_property(target_type ${TARGET} TYPE) - get_target_property(sources ${TARGET} INTERFACE_SOURCES) - foreach (src ${sources}) + foreach (src ${_LIST}) if("${src}" MATCHES "\\.hpp$") list(APPEND H ${src}) - elseif("${src}" MATCHES "\\.cc$") + elseif("${src}" MATCHES "\\.cpp$") list(APPEND CC ${src}) endif () endforeach () file(APPEND "${filename}" [=[ """Automatically generated source lists for ]=] ) - file(APPEND "${filename}" ${TARGET}) + file(APPEND "${filename}" "nlohmann_json") file(APPEND "${filename}" [=[ - DO NOT EDIT.""" ]=] ) - file(APPEND "${filename}" "${TARGET}_hdrs = [\n") + file(APPEND "${filename}" "nlohmann_json_hdrs = [\n") foreach (src ${H}) file(APPEND "${filename}" " \"${src}\",\n") endforeach () file(APPEND "${filename}" "]\n\n") - file(APPEND "${filename}" "${TARGET}_srcs = [\n") + file(APPEND "${filename}" "nlohmann_json_srcs = [\n") foreach (src ${CC}) file(APPEND "${filename}" " \"${src}\",\n") endforeach () diff --git a/nlohmann_json.bzl b/nlohmann_json.bzl new file mode 100644 index 000000000..39fed0e16 --- /dev/null +++ b/nlohmann_json.bzl @@ -0,0 +1,41 @@ +"""Automatically generated source lists for nlohmann_json - DO NOT EDIT.""" + +nlohmann_json_hdrs = [ + "nlohmann/adl_serializer.hpp", + "nlohmann/json_fwd.hpp", + "nlohmann/thirdparty/hedley/hedley_undef.hpp", + "nlohmann/thirdparty/hedley/hedley.hpp", + "nlohmann/json.hpp", + "nlohmann/detail/json_pointer.hpp", + "nlohmann/detail/value_t.hpp", + "nlohmann/detail/input/json_sax.hpp", + "nlohmann/detail/input/lexer.hpp", + "nlohmann/detail/input/input_adapters.hpp", + "nlohmann/detail/input/position_t.hpp", + "nlohmann/detail/input/binary_reader.hpp", + "nlohmann/detail/input/parser.hpp", + "nlohmann/detail/iterators/internal_iterator.hpp", + "nlohmann/detail/iterators/iteration_proxy.hpp", + "nlohmann/detail/iterators/json_reverse_iterator.hpp", + "nlohmann/detail/iterators/iterator_traits.hpp", + "nlohmann/detail/iterators/iter_impl.hpp", + "nlohmann/detail/iterators/primitive_iterator.hpp", + "nlohmann/detail/json_ref.hpp", + "nlohmann/detail/macro_scope.hpp", + "nlohmann/detail/macro_unscope.hpp", + "nlohmann/detail/exceptions.hpp", + "nlohmann/detail/output/output_adapters.hpp", + "nlohmann/detail/output/serializer.hpp", + "nlohmann/detail/output/binary_writer.hpp", + "nlohmann/detail/conversions/from_json.hpp", + "nlohmann/detail/conversions/to_chars.hpp", + "nlohmann/detail/conversions/to_json.hpp", + "nlohmann/detail/meta/void_t.hpp", + "nlohmann/detail/meta/cpp_future.hpp", + "nlohmann/detail/meta/detected.hpp", + "nlohmann/detail/meta/is_sax.hpp", + "nlohmann/detail/meta/type_traits.hpp", +] + +nlohmann_json_srcs = [ +]