json/cmake/CreateBazelConfig.cmake

57 lines
1.9 KiB
CMake
Raw Normal View History

# ~~~
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
2019-07-27 01:25:03 +03:00
# 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
2019-07-27 01:25:03 +03:00
# list. The generated file can be loaded from a BUILD file to create the
# corresponding targets in Bazel.
2019-07-27 01:25:03 +03:00
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)
2019-07-27 01:25:03 +03:00
foreach (src ${_LIST})
if("${src}" MATCHES "\\.hpp$")
list(APPEND H ${src})
2019-07-27 01:25:03 +03:00
elseif("${src}" MATCHES "\\.cpp$")
list(APPEND CC ${src})
endif ()
endforeach ()
file(APPEND "${filename}" [=[
"""Automatically generated source lists for ]=]
)
2019-07-27 01:25:03 +03:00
file(APPEND "${filename}" "nlohmann_json")
file(APPEND "${filename}" [=[ - DO NOT EDIT."""
]=]
)
2019-07-27 01:25:03 +03:00
file(APPEND "${filename}" "nlohmann_json_hdrs = [\n")
foreach (src ${H})
file(APPEND "${filename}" " \"${src}\",\n")
endforeach ()
file(APPEND "${filename}" "]\n\n")
2019-07-27 01:25:03 +03:00
file(APPEND "${filename}" "nlohmann_json_srcs = [\n")
foreach (src ${CC})
file(APPEND "${filename}" " \"${src}\",\n")
endforeach ()
file(APPEND "${filename}" "]\n")
endfunction ()