diff --git a/BUILD.bazel b/BUILD.bazel index 4485ede47..15d84f16b 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,6 +1,6 @@ cc_library( name = "json", - hdrs = glob([ + hdrs = [ "include/nlohmann/adl_serializer.hpp", "include/nlohmann/byte_container_with_subtype.hpp", "include/nlohmann/detail/abi_macros.hpp", @@ -46,7 +46,7 @@ cc_library( "include/nlohmann/ordered_map.hpp", "include/nlohmann/thirdparty/hedley/hedley.hpp", "include/nlohmann/thirdparty/hedley/hedley_undef.hpp", - ]), + ], includes = ["include"], visibility = ["//visibility:public"], alwayslink = True, diff --git a/CMakeLists.txt b/CMakeLists.txt index 654ba7dd6..d65b94d27 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,11 +41,11 @@ option(JSON_BuildTests "Build the unit tests when BUILD_TEST option(JSON_CI "Enable CI build targets." OFF) option(JSON_Diagnostics "Use extended diagnostic messages." OFF) option(JSON_DisableEnumSerialization "Disable default integer enum serialization." OFF) -option(JSON_GenerateBazelBuildFiles "Generate Bazel Build files." OFF) option(JSON_GlobalUDLs "Place use-defined string literals in the global namespace." ON) option(JSON_ImplicitConversions "Enable implicit conversions." ON) +option(JSON_DisableEnumSerialization "Disable default integer enum serialization." OFF) +option(JSON_LegacyDiscardedValueComparison "Enable legacy discarded value comparison." OFF) option(JSON_Install "Install CMake targets during install step." ${MAIN_PROJECT}) -option(JSON_LegacyDiscardedValueComparison "Enable legacy discarded value comparison." OFF) option(JSON_MultipleHeaders "Use non-amalgamated version of the library." ON) option(JSON_SystemInclude "Include as system headers (skip for clang-tidy)." OFF) @@ -154,15 +154,6 @@ if (JSON_BuildTests) add_subdirectory(tests) endif() -## -## BAZEL -## create Bazel BUILD file -## -if (JSON_BuildTests) - include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/create_bazel_build_file.cmake) - create_bazel_build_file(${NLOHMANN_JSON_INCLUDE_BUILD_DIR}) -endif() - ## ## INSTALL ## install header files, generate and install cmake config files for find_package() diff --git a/Makefile b/Makefile index 18b08a51a..e03b49eee 100644 --- a/Makefile +++ b/Makefile @@ -192,6 +192,8 @@ check-amalgamation: @mv $(AMALGAMATED_FILE)~ $(AMALGAMATED_FILE) @mv $(AMALGAMATED_FWD_FILE)~ $(AMALGAMATED_FWD_FILE) +BUILD.bazel: $(SRCS) + cmake -P cmake/scripts/gen_bazel_build_file.cmake ########################################################################## # ChangeLog diff --git a/cmake/create_bazel_build_file.cmake b/cmake/create_bazel_build_file.cmake deleted file mode 100644 index 2b0c8507a..000000000 --- a/cmake/create_bazel_build_file.cmake +++ /dev/null @@ -1,21 +0,0 @@ -function (create_bazel_build_file NLOHMANN_JSON_INCLUDE_BUILD_DIR) - message(STATUS "Generating Bazel BUILD file") - - file(GLOB_RECURSE NLOHMANN_JSON_HEADERS "${NLOHMANN_JSON_INCLUDE_BUILD_DIR}/*.hpp") - - set(filename "BUILD.bazel") - file(WRITE "${filename}" "cc_library(\n") - file(APPEND "${filename}" " name = \"json\",\n") - file(APPEND "${filename}" " hdrs = glob([\n") - - foreach(_header ${NLOHMANN_JSON_HEADERS}) - file(RELATIVE_PATH _header_rel ${PROJECT_SOURCE_DIR} ${_header}) - file(APPEND "${filename}" " \"${_header_rel}\",\n") - endforeach() - - file(APPEND "${filename}" " ]),\n") - file(APPEND "${filename}" " includes = [\"include\"],\n") - file(APPEND "${filename}" " visibility = [\"//visibility:public\"],\n") - file(APPEND "${filename}" " alwayslink = True,\n") - file(APPEND "${filename}" ")\n") -endfunction () diff --git a/cmake/scripts/gen_bazel_build_file.cmake b/cmake/scripts/gen_bazel_build_file.cmake new file mode 100644 index 000000000..e9b9f2f5b --- /dev/null +++ b/cmake/scripts/gen_bazel_build_file.cmake @@ -0,0 +1,24 @@ +# generate Bazel BUILD file + +set(PROJECT_ROOT "${CMAKE_CURRENT_LIST_DIR}/../..") +set(BUILD_FILE "${PROJECT_ROOT}/BUILD.bazel") + +file(GLOB_RECURSE HEADERS LIST_DIRECTORIES false RELATIVE "${PROJECT_ROOT}" "include/*.hpp") + +file(WRITE "${BUILD_FILE}" [=[ +cc_library( + name = "json", + hdrs = [ +]=]) + +foreach(header ${HEADERS}) + file(APPEND "${BUILD_FILE}" " \"${header}\",\n") +endforeach() + +file(APPEND "${BUILD_FILE}" [=[ + ], + includes = ["include"], + visibility = ["//visibility:public"], + alwayslink = True, +) +]=])