From 99ac7fa60d53050488f8d94adb72b74b4ff7d15d Mon Sep 17 00:00:00 2001 From: Christian Blichmann Date: Mon, 15 Jul 2019 04:12:55 -0700 Subject: [PATCH] Refactor CMake files * Move add_sapi_library() into a build defs file * Override protobuf_generate_cpp() instead of naming it sapi_protobuf_generate_cpp() * Factor out inclusion/find_package() calls of external dependencies PiperOrigin-RevId: 258133422 Change-Id: Ibdbab0c735157eac0ed6122ab78f9d583c6905cc --- CMakeLists.txt | 78 +------- cmake/SapiBuildDefs.cmake | 170 ++++++++++++++++++ cmake/SapiDeps.cmake | 76 ++++++++ ...{SuperBuild.cmake => SapiSuperBuild.cmake} | 2 +- cmake/SapiUtil.cmake | 162 +---------------- sandboxed_api/CMakeLists.txt | 2 +- sandboxed_api/sandbox2/CMakeLists.txt | 10 +- 7 files changed, 265 insertions(+), 235 deletions(-) create mode 100644 cmake/SapiBuildDefs.cmake create mode 100644 cmake/SapiDeps.cmake rename cmake/{SuperBuild.cmake => SapiSuperBuild.cmake} (97%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f7ceca..472e22c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,10 +14,10 @@ cmake_minimum_required(VERSION 3.10) -option(USE_SUPERBUILD "Whether or not a superbuild should be invoked" ON) -if(USE_SUPERBUILD) +option(SAPI_USE_SUPERBUILD "Whether or not a superbuild should be invoked" ON) +if(SAPI_USE_SUPERBUILD) project(superbuild NONE) - include(cmake/SuperBuild.cmake) + include(cmake/SapiSuperBuild.cmake) return() endif() project(sandboxed_api C CXX ASM) @@ -25,74 +25,13 @@ project(sandboxed_api C CXX ASM) # SAPI-wide setting for the language level set(SAPI_CXX_STANDARD 11) -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -list(APPEND CMAKE_PREFIX_PATH - "${PROJECT_BINARY_DIR}/Dependencies/Build/gflags" - "${PROJECT_BINARY_DIR}/Dependencies/Build/glog" - "${PROJECT_BINARY_DIR}/Dependencies/Build/protobuf" -) - -include(SapiUtil) +list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") +include(SapiDeps) +include(SapiUtil) # Needs to come after SapiDeps +include(SapiBuildDefs) include(GoogleTest) -# Build Abseil directly, as recommended upstream -find_path(absl_src_dir - absl/base/port.h - HINTS ${ABSL_ROOT_DIR} - PATHS ${PROJECT_BINARY_DIR}/Dependencies/Source/absl -) -set(_sapi_saved_CMAKE_CXX_STANDARD ${CMAKE_CXX_STANDARD}) -set(CMAKE_CXX_STANDARD ${SAPI_CXX_STANDARD}) -add_subdirectory(${absl_src_dir} - ${PROJECT_BINARY_DIR}/Dependencies/Build/absl - EXCLUDE_FROM_ALL) -if(_sapi_saved_CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD "${_sapi_saved_CMAKE_CXX_STANDARD}") -endif() - -# Build Googletest directly, as recommended upstream -find_path(googletest_src_dir - googletest/include/gtest/gtest.h - HINTS ${GOOGLETEST_ROOT_DIR} - PATHS ${PROJECT_BINARY_DIR}/Dependencies/Source/googletest -) -set(gtest_force_shared_crt ON CACHE BOOL "") -add_subdirectory(${googletest_src_dir} - ${PROJECT_BINARY_DIR}/Dependencies/Build/googletest - EXCLUDE_FROM_ALL) - -# Prefer to use static libraries -set(_sapi_saved_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) -if(WIN32) - set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) -else() - set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) -endif() - -find_package(gflags REQUIRED) -find_package(glog REQUIRED) -find_package(Libcap REQUIRED) -find_package(Libffi REQUIRED) -find_package(ZLIB REQUIRED) -find_package(Protobuf REQUIRED) - -if(CMAKE_VERSION VERSION_LESS "3.12") - # Work around FindPythonInterp sometimes not preferring Python 3. - foreach(v IN ITEMS 3 3.9 3.8 3.7 3.6 3.5 3.4 3.3 3.2 3.1 3.0) - list(APPEND _sapi_py_names python${v}) - endforeach() - find_program(Python3_EXECUTABLE NAMES ${_sapi_py_names}) - if(NOT Python3_EXECUTABLE) - message(FATAL_ERROR "No suitable version of Python 3 found") - endif() -else() - find_package(Python3 COMPONENTS Interpreter REQUIRED) -endif() - -# Undo global change -set(CMAKE_FIND_LIBRARY_SUFFIXES ${_sapi_saved_CMAKE_FIND_LIBRARY_SUFFIXES}) - -# Make Bazel-like includes work +# Make Bazel-style includes work configure_file(cmake/libcap_capability.h.in libcap/include/sys/capability.h @ONLY) @@ -126,6 +65,7 @@ target_include_directories(sapi_base INTERFACE if(UNIX) target_compile_options(sapi_base INTERFACE -Wno-deprecated + -Wno-psabi ) endif() diff --git a/cmake/SapiBuildDefs.cmake b/cmake/SapiBuildDefs.cmake new file mode 100644 index 0000000..1f6d512 --- /dev/null +++ b/cmake/SapiBuildDefs.cmake @@ -0,0 +1,170 @@ +# Copyright 2019 Google LLC. All Rights Reserved. +# +# 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. + +# Embeds arbitrary binary data into a static library. +# +# NAME specifies the name for this target. +# NAMESPACE is the C++ namespace the generated code is placed in. Can be empty. +# SOURCES is a list of files that should be embedded. If a source names a +# target the target binary is embedded instead. +macro(sapi_cc_embed_data) + cmake_parse_arguments(_sapi_embed "" "NAME;NAMESPACE" "SOURCES" ${ARGN}) + foreach(src ${_sapi_embed_SOURCES}) + if(TARGET ${src}) + list(APPEND _sapi_embed_in ${CMAKE_CURRENT_BINARY_DIR}/${src}) + else() + list(APPEND _sapi_embed_in ${src}) + endif() + endforeach() + file(RELATIVE_PATH _sapi_embed_pkg + ${PROJECT_BINARY_DIR} + ${CMAKE_CURRENT_BINARY_DIR}) + add_custom_command( + OUTPUT ${_sapi_embed_NAME}.h ${_sapi_embed_NAME}.cc + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND filewrapper ${_sapi_embed_pkg} + ${_sapi_embed_NAME} + "${_sapi_embed_NAMESPACE}" + ${CMAKE_CURRENT_BINARY_DIR}/${_sapi_embed_NAME}.h + ${CMAKE_CURRENT_BINARY_DIR}/${_sapi_embed_NAME}.cc + ${_sapi_embed_in} + DEPENDS ${_sapi_embed_SOURCES} + VERBATIM + ) + add_library(${_sapi_embed_NAME} STATIC + ${_sapi_embed_NAME}.h + ${_sapi_embed_NAME}.cc + ) + target_link_libraries(${_sapi_embed_NAME} PRIVATE + sapi::base + absl::core_headers + ) +endmacro() + +# Adds a library target implementing a sandboxed API for another library. +# The first argument is the target name, similar to the native add_library(). +# This function implements the same functionality as the Bazel version in +# sandboxed_api/bazel/sapi.bzl. +# +# SOURCES Any additional sources to include with the Sandboxed API library. +# Typically not necessary, unless the sandbox definition should be in a .cc +# file instead of the customary "sandbox.h" header. Bazel also has a "hdrs" +# attribute, but CMake does not distinguish headers from sources. +# FUNCTIONS A list of functions that to use in from host code. Leaving this +# list empty will export and wrap all functions found in the library. +# NOEMBED Whether the SAPI library should be embedded inside host code, so the +# SAPI Sandbox can be initialized with the +# ::sapi::Sandbox::Sandbox(FileToc*) constructor. +# LIBRARY The library target to sandbox and expose to the host code (required). +# LIBRARY_NAME The name of the class which will proxy the library functions +# from the functions list (required). You will call functions from the +# sandboxed library via instances of this class. +# INPUTS List of source files which the SAPI interface generator should scan +# for function declarations. Library header files are always scanned, so +# this can usually be empty/omitted. +# NAMESPACE C++ namespace identifier to place API class defined by +# LIBRARY_NAME into. +# HEADER If set, does not generate an interface header, but uses the one +# specified. +function(add_sapi_library) + set(_sapi_opts NOEMBED) + set(_sapi_one_value HEADER LIBRARY LIBRARY_NAME NAMESPACE) + set(_sapi_multi_value SOURCES FUNCTIONS INPUTS) + cmake_parse_arguments(_sapi + "${_sapi_opts}" + "${_sapi_one_value}" + "${_sapi_multi_value}" + ${ARGN}) + set(_sapi_NAME "${ARGV0}") + + set(_sapi_gen_header "${_sapi_NAME}.sapi.h") + foreach(func IN LISTS _sapi_FUNCTIONS) + list(APPEND _sapi_exported_funcs "-Wl,--export-dynamic-symbol,${func}") + endforeach() + if(NOT _sapi_exported_funcs) + set(_sapi_exported_funcs -Wl,--whole-archive + -Wl,--allow-multiple-definition) + endif() + + # The sandboxed binary + set(_sapi_bin "${_sapi_NAME}.bin") + set(_sapi_force_cxx_linkage + "${CMAKE_CURRENT_BINARY_DIR}/${_sapi_bin}_force_cxx_linkage.cc") + file(TOUCH "${_sapi_force_cxx_linkage}") + add_executable("${_sapi_bin}" "${_sapi_force_cxx_linkage}") + # TODO(cblichmann): Use target_link_options on CMake >= 3.13 + target_link_libraries("${_sapi_bin}" PRIVATE + -fuse-ld=gold + "${_sapi_LIBRARY}" + sapi::client + ${CMAKE_DL_LIBS} + -Wl,-E + ${_sapi_exported_funcs} + ) + + if(NOT _sapi_NOEMBED) + set(_sapi_embed "${_sapi_NAME}_embed") + sapi_cc_embed_data(NAME "${_sapi_embed}" + NAMESPACE "${_sapi_NAMESPACE}" + SOURCES "${_sapi_bin}" + ) + endif() + + # Interface + list(JOIN _sapi_FUNCTIONS "," _sapi_funcs) + foreach(src IN LISTS _sapi_INPUTS) + get_filename_component(src "${src}" ABSOLUTE) + list(APPEND _sapi_full_inputs "${src}") + endforeach() + list(JOIN _sapi_full_inputs "," _sapi_full_inputs) + if(NOT _sapi_NOEMBED) + set(_sapi_embed_dir "${CMAKE_CURRENT_BINARY_DIR}") + set(_sapi_embed_name "${_sapi_NAME}") + endif() + add_custom_command( + OUTPUT "${_sapi_gen_header}" + COMMAND "${Python3_EXECUTABLE}" -B + "${PROJECT_SOURCE_DIR}/sandboxed_api/tools/generator2/sapi_generator.py" + "--sapi_name=${_sapi_LIBRARY_NAME}" + "--sapi_out=${_sapi_gen_header}" + "--sapi_embed_dir=${_sapi_embed_dir}" + "--sapi_embed_name=${_sapi_embed_name}" + "--sapi_functions=${_sapi_funcs}" + "--sapi_ns=${_sapi_NAMESPACE}" + # TODO(cblichmann): Implement sapi_isystem + "--sapi_in=${_sapi_full_inputs}" + COMMENT "Generating interface" + ) + + # Library with the interface + if(NOT _sapi_SOURCES) + set(_sapi_force_cxx_linkage + "${CMAKE_CURRENT_BINARY_DIR}/${_sapi_NAME}_force_cxx_linkage.cc") + file(TOUCH "${_sapi_force_cxx_linkage}") + list(APPEND _sapi_SOURCES "${_sapi_force_cxx_linkage}") + endif() + add_library("${_sapi_NAME}" STATIC + ${_sapi_gen_header} + ${_sapi_SOURCES} + ) + target_link_libraries("${_sapi_NAME}" PRIVATE + sapi::sapi + sapi::vars + ) + if(NOT _sapi_NOEMBED) + target_link_libraries("${_sapi_NAME}" PRIVATE + "${_sapi_embed}" + ) + endif() +endfunction() diff --git a/cmake/SapiDeps.cmake b/cmake/SapiDeps.cmake new file mode 100644 index 0000000..f4e32ef --- /dev/null +++ b/cmake/SapiDeps.cmake @@ -0,0 +1,76 @@ +# Copyright 2019 Google LLC. All Rights Reserved. +# +# 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. + +list(APPEND CMAKE_PREFIX_PATH + "${PROJECT_BINARY_DIR}/Dependencies/Build/gflags" + "${PROJECT_BINARY_DIR}/Dependencies/Build/glog" + "${PROJECT_BINARY_DIR}/Dependencies/Build/protobuf" +) + +# Build Abseil directly, as recommended upstream +find_path(absl_src_dir + absl/base/port.h + HINTS ${ABSL_ROOT_DIR} + PATHS ${PROJECT_BINARY_DIR}/Dependencies/Source/absl +) +set(_sapi_saved_CMAKE_CXX_STANDARD ${CMAKE_CXX_STANDARD}) +set(CMAKE_CXX_STANDARD ${SAPI_CXX_STANDARD}) +add_subdirectory(${absl_src_dir} + ${PROJECT_BINARY_DIR}/Dependencies/Build/absl + EXCLUDE_FROM_ALL) +if(_sapi_saved_CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD "${_sapi_saved_CMAKE_CXX_STANDARD}") +endif() + +# Build Googletest directly, as recommended upstream +find_path(googletest_src_dir + googletest/include/gtest/gtest.h + HINTS ${GOOGLETEST_ROOT_DIR} + PATHS ${PROJECT_BINARY_DIR}/Dependencies/Source/googletest +) +set(gtest_force_shared_crt ON CACHE BOOL "") +add_subdirectory(${googletest_src_dir} + ${PROJECT_BINARY_DIR}/Dependencies/Build/googletest + EXCLUDE_FROM_ALL) + +# Prefer to use static libraries +set(_sapi_saved_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) +if(WIN32) + set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) +else() + set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) +endif() + +find_package(gflags REQUIRED) +find_package(glog REQUIRED) +find_package(Libcap REQUIRED) +find_package(Libffi REQUIRED) +find_package(ZLIB REQUIRED) +find_package(Protobuf REQUIRED) + +if(CMAKE_VERSION VERSION_LESS "3.12") + # Work around FindPythonInterp sometimes not preferring Python 3. + foreach(v IN ITEMS 3 3.9 3.8 3.7 3.6 3.5 3.4 3.3 3.2 3.1 3.0) + list(APPEND _sapi_py_names python${v}) + endforeach() + find_program(Python3_EXECUTABLE NAMES ${_sapi_py_names}) + if(NOT Python3_EXECUTABLE) + message(FATAL_ERROR "No suitable version of Python 3 found") + endif() +else() + find_package(Python3 COMPONENTS Interpreter REQUIRED) +endif() + +# Undo global change +set(CMAKE_FIND_LIBRARY_SUFFIXES ${_sapi_saved_CMAKE_FIND_LIBRARY_SUFFIXES}) diff --git a/cmake/SuperBuild.cmake b/cmake/SapiSuperBuild.cmake similarity index 97% rename from cmake/SuperBuild.cmake rename to cmake/SapiSuperBuild.cmake index 4938f03..2019274 100644 --- a/cmake/SuperBuild.cmake +++ b/cmake/SapiSuperBuild.cmake @@ -82,7 +82,7 @@ list(APPEND DEPENDENCIES protobuf) ExternalProject_Add(sandboxed_api DEPENDS ${DEPENDENCIES} SOURCE_DIR ${PROJECT_SOURCE_DIR} - CMAKE_ARGS -DUSE_SUPERBUILD=OFF ${EXTRA_CMAKE_ARGS} + CMAKE_ARGS -DSAPI_USE_SUPERBUILD=OFF ${EXTRA_CMAKE_ARGS} INSTALL_COMMAND "" BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} ) diff --git a/cmake/SapiUtil.cmake b/cmake/SapiUtil.cmake index 155dad9..11b976e 100644 --- a/cmake/SapiUtil.cmake +++ b/cmake/SapiUtil.cmake @@ -38,169 +38,13 @@ endfunction() # Helper function that behaves just like protobuf_generate_cpp(), except that # it strips import paths. This is necessary, because CMake's protobuf rules # don't work well with imports across different directories. -function(sapi_protobuf_generate_cpp SRCS HDRS PROTO) +function(protobuf_generate_cpp SRCS HDRS PROTO) file(READ ${PROTO} _pb_orig) string(REGEX REPLACE "import \".*/([^/]+\\.proto)\"" "import \"\\1\"" _pb_repl "${_pb_orig}") file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${PROTO} "${_pb_repl}") - protobuf_generate_cpp(_srcs _hdrs ${CMAKE_CURRENT_BINARY_DIR}/${PROTO}) + # Call original function + _protobuf_generate_cpp(_srcs _hdrs ${CMAKE_CURRENT_BINARY_DIR}/${PROTO}) set(${SRCS} ${_srcs} PARENT_SCOPE) set(${HDRS} ${_hdrs} PARENT_SCOPE) endfunction() - -# Embeds arbitrary binary data into a static library. -# -# NAME specifies the name for this target. -# NAMESPACE is the C++ namespace the generated code is placed in. Can be empty. -# SOURCES is a list of files that should be embedded. If a source names a -# target the target binary is embedded instead. -macro(sapi_cc_embed_data) - cmake_parse_arguments(_sapi_embed "" "NAME;NAMESPACE" "SOURCES" ${ARGN}) - foreach(src ${_sapi_embed_SOURCES}) - if(TARGET ${src}) - list(APPEND _sapi_embed_in ${CMAKE_CURRENT_BINARY_DIR}/${src}) - else() - list(APPEND _sapi_embed_in ${src}) - endif() - endforeach() - file(RELATIVE_PATH _sapi_embed_pkg - ${PROJECT_BINARY_DIR} - ${CMAKE_CURRENT_BINARY_DIR}) - add_custom_command( - OUTPUT ${_sapi_embed_NAME}.h ${_sapi_embed_NAME}.cc - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMAND filewrapper ${_sapi_embed_pkg} - ${_sapi_embed_NAME} - "${_sapi_embed_NAMESPACE}" - ${CMAKE_CURRENT_BINARY_DIR}/${_sapi_embed_NAME}.h - ${CMAKE_CURRENT_BINARY_DIR}/${_sapi_embed_NAME}.cc - ${_sapi_embed_in} - DEPENDS ${_sapi_embed_SOURCES} - VERBATIM - ) - add_library(${_sapi_embed_NAME} STATIC - ${_sapi_embed_NAME}.h - ${_sapi_embed_NAME}.cc - ) - target_link_libraries(${_sapi_embed_NAME} PRIVATE - sapi::base - absl::core_headers - ) -endmacro() - -# Adds a library target implementing a sandboxed API for another library. -# The first argument is the target name, similar to the native add_library(). -# This function implements the same functionality as the Bazel version in -# sandboxed_api/bazel/sapi.bzl. -# -# SOURCES Any additional sources to include with the Sandboxed API library. -# Typically not necessary, unless the sandbox definition should be in a .cc -# file instead of the customary "sandbox.h" header. Bazel also has a "hdrs" -# attribute, but CMake does not distinguish headers from sources. -# FUNCTIONS A list of functions that to use in from host code. Leaving this -# list empty will export and wrap all functions found in the library. -# NOEMBED Whether the SAPI library should be embedded inside host code, so the -# SAPI Sandbox can be initialized with the -# ::sapi::Sandbox::Sandbox(FileToc*) constructor. -# LIBRARY The library target to sandbox and expose to the host code (required). -# LIBRARY_NAME The name of the class which will proxy the library functions -# from the functions list (required). You will call functions from the -# sandboxed library via instances of this class. -# INPUTS List of source files which the SAPI interface generator should scan -# for function declarations. Library header files are always scanned, so -# this can usually be empty/omitted. -# NAMESPACE C++ namespace identifier to place API class defined by -# LIBRARY_NAME into. -# HEADER If set, does not generate an interface header, but uses the one -# specified. -function(add_sapi_library) - set(_sapi_opts NOEMBED) - set(_sapi_one_value HEADER LIBRARY LIBRARY_NAME NAMESPACE) - set(_sapi_multi_value SOURCES FUNCTIONS INPUTS) - cmake_parse_arguments(_sapi - "${_sapi_opts}" - "${_sapi_one_value}" - "${_sapi_multi_value}" - ${ARGN}) - set(_sapi_NAME "${ARGV0}") - - set(_sapi_gen_header "${_sapi_NAME}.sapi.h") - foreach(func IN LISTS _sapi_FUNCTIONS) - list(APPEND _sapi_exported_funcs "-Wl,--export-dynamic-symbol,${func}") - endforeach() - if(NOT _sapi_exported_funcs) - set(_sapi_exported_funcs -Wl,--whole-archive - -Wl,--allow-multiple-definition) - endif() - - # The sandboxed binary - set(_sapi_bin "${_sapi_NAME}.bin") - set(_sapi_force_cxx_linkage - "${CMAKE_CURRENT_BINARY_DIR}/${_sapi_bin}_force_cxx_linkage.cc") - file(TOUCH "${_sapi_force_cxx_linkage}") - add_executable("${_sapi_bin}" "${_sapi_force_cxx_linkage}") - # TODO(cblichmann): Use target_link_options on CMake >= 3.13 - target_link_libraries("${_sapi_bin}" PRIVATE - -fuse-ld=gold - "${_sapi_LIBRARY}" - sapi::client - ${CMAKE_DL_LIBS} - -Wl,-E - ${_sapi_exported_funcs} - ) - - if(NOT _sapi_NOEMBED) - set(_sapi_embed "${_sapi_NAME}_embed") - sapi_cc_embed_data(NAME "${_sapi_embed}" - NAMESPACE "${_sapi_NAMESPACE}" - SOURCES "${_sapi_bin}" - ) - endif() - - # Interface - list(JOIN _sapi_FUNCTIONS "," _sapi_funcs) - foreach(src IN LISTS _sapi_INPUTS) - get_filename_component(src "${src}" ABSOLUTE) - list(APPEND _sapi_full_inputs "${src}") - endforeach() - list(JOIN _sapi_full_inputs "," _sapi_full_inputs) - if(NOT _sapi_NOEMBED) - set(_sapi_embed_dir "${CMAKE_CURRENT_BINARY_DIR}") - set(_sapi_embed_name "${_sapi_NAME}") - endif() - add_custom_command( - OUTPUT "${_sapi_gen_header}" - COMMAND "${Python3_EXECUTABLE}" -B - "${PROJECT_SOURCE_DIR}/sandboxed_api/tools/generator2/sapi_generator.py" - "--sapi_name=${_sapi_LIBRARY_NAME}" - "--sapi_out=${_sapi_gen_header}" - "--sapi_embed_dir=${_sapi_embed_dir}" - "--sapi_embed_name=${_sapi_embed_name}" - "--sapi_functions=${_sapi_funcs}" - "--sapi_ns=${_sapi_NAMESPACE}" - # TODO(cblichmann): Implement sapi_isystem - "--sapi_in=${_sapi_full_inputs}" - COMMENT "Generating interface" - ) - - # Library with the interface - if(NOT _sapi_SOURCES) - set(_sapi_force_cxx_linkage - "${CMAKE_CURRENT_BINARY_DIR}/${_sapi_NAME}_force_cxx_linkage.cc") - file(TOUCH "${_sapi_force_cxx_linkage}") - list(APPEND _sapi_SOURCES "${_sapi_force_cxx_linkage}") - endif() - add_library("${_sapi_NAME}" STATIC - ${_sapi_gen_header} - ${_sapi_SOURCES} - ) - target_link_libraries("${_sapi_NAME}" PRIVATE - sapi::sapi - sapi::vars - ) - if(NOT _sapi_NOEMBED) - target_link_libraries("${_sapi_NAME}" PRIVATE - "${_sapi_embed}" - ) - endif() -endfunction() diff --git a/sandboxed_api/CMakeLists.txt b/sandboxed_api/CMakeLists.txt index 7e74d1a..98552ea 100644 --- a/sandboxed_api/CMakeLists.txt +++ b/sandboxed_api/CMakeLists.txt @@ -18,7 +18,7 @@ add_subdirectory(sandbox2) add_subdirectory(util) # sandboxed_api:proto_arg -sapi_protobuf_generate_cpp(_sapi_proto_arg_pb_cc _sapi_proto_arg_pb_h +protobuf_generate_cpp(_sapi_proto_arg_pb_cc _sapi_proto_arg_pb_h proto_arg.proto ) add_library(sapi_proto_arg_proto STATIC diff --git a/sandboxed_api/sandbox2/CMakeLists.txt b/sandboxed_api/sandbox2/CMakeLists.txt index 33104a5..8d91686 100644 --- a/sandboxed_api/sandbox2/CMakeLists.txt +++ b/sandboxed_api/sandbox2/CMakeLists.txt @@ -90,7 +90,7 @@ target_link_libraries(sandbox2_result PRIVATE ) # sandboxed_api/sandbox2:logserver_proto -sapi_protobuf_generate_cpp(_sandbox2_logserver_pb_h _sandbox2_logserver_pb_cc +protobuf_generate_cpp(_sandbox2_logserver_pb_h _sandbox2_logserver_pb_cc logserver.proto ) add_library(sandbox2_logserver_proto STATIC @@ -560,7 +560,7 @@ gtest_discover_tests(buffer_test PROPERTIES ) # sandboxed_api/sandbox2:forkserver_proto -sapi_protobuf_generate_cpp(_sandbox2_forkserver_pb_h _sandbox2_forkserver_pb_cc +protobuf_generate_cpp(_sandbox2_forkserver_pb_h _sandbox2_forkserver_pb_cc forkserver.proto ) add_library(sandbox2_forkserver_proto STATIC @@ -575,7 +575,7 @@ target_link_libraries(sandbox2_forkserver_proto PRIVATE ) # sandboxed_api/sandbox2:mounttree_proto -sapi_protobuf_generate_cpp(_sandbox2_mounttree_pb_h _sandbox2_mounttree_pb_cc +protobuf_generate_cpp(_sandbox2_mounttree_pb_h _sandbox2_mounttree_pb_cc mounttree.proto ) add_library(sandbox2_mounttree_proto STATIC @@ -611,7 +611,7 @@ target_link_libraries(sandbox2_comms PRIVATE ) # sandboxed_api/sandbox2:comms_test_proto -sapi_protobuf_generate_cpp(_sandbox2_comms_test_pb_h _sandbox2_comms_test_pb_cc +protobuf_generate_cpp(_sandbox2_comms_test_pb_h _sandbox2_comms_test_pb_cc comms_test.proto ) add_library(sandbox2_comms_test_proto STATIC @@ -855,7 +855,7 @@ target_link_libraries(sandbox2_testing PRIVATE ) # sandboxed_api/sandbox2:violation_proto -sapi_protobuf_generate_cpp(_sandbox2_violation_pb_cc _sandbox2_violation_pb_h +protobuf_generate_cpp(_sandbox2_violation_pb_cc _sandbox2_violation_pb_h violation.proto ) add_library(sandbox2_violation_proto STATIC