Merge pull request #1 from falbrechtskirchinger/add-bazel-support

Add Bazel build support
This commit is contained in:
Vertexwahn 2022-09-11 10:20:58 +02:00 committed by GitHub
commit 02d4f80943
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 34 deletions

View File

@ -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,

View File

@ -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()

View File

@ -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

View File

@ -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 ()

View File

@ -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,
)
]=])