Skip to content

Commit d91879f

Browse files
cblichmanncopybara-github
authored andcommitted
Ensure compatibility with CMake 3.10
This fixes some CMake-3.12+-isms, like `list(JOIN ...)` and setting link properties on OBJECT libraries. PiperOrigin-RevId: 265033725 Change-Id: I0ee1ec0e1b1097ea8226ad6fdeff794a97c2881b
1 parent c966f21 commit d91879f

File tree

7 files changed

+24
-11
lines changed

7 files changed

+24
-11
lines changed

.bazelci/presubmit.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
---
22
tasks:
33
ubuntu1804:
4+
shell_commands:
5+
- apt-get update && apt-get install libcap-dev
6+
- pip3 install absl-py clang
47
build_targets:
58
- "..."

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ configure_file(cmake/libcap_capability.h.in
3838

3939
# Library with basic project settings. The empty file is there to be able to
4040
# define header-only libraries without cumbersome target_sources() hacks.
41-
file(TOUCH ${SAPI_BINARY_DIR}/sapi_base_force_cxx_linkage.cc)
41+
file(WRITE ${SAPI_BINARY_DIR}/sapi_base_force_cxx_linkage.cc "")
4242
add_library(sapi_base STATIC
4343
"${SAPI_BINARY_DIR}/sapi_base_force_cxx_linkage.cc"
4444
)

cmake/SapiBuildDefs.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function(add_sapi_library)
102102
set(_sapi_bin "${_sapi_NAME}.bin")
103103
set(_sapi_force_cxx_linkage
104104
"${CMAKE_CURRENT_BINARY_DIR}/${_sapi_bin}_force_cxx_linkage.cc")
105-
file(TOUCH "${_sapi_force_cxx_linkage}")
105+
file(WRITE "${_sapi_force_cxx_linkage}" "")
106106
add_executable("${_sapi_bin}" "${_sapi_force_cxx_linkage}")
107107
# TODO(cblichmann): Use target_link_options on CMake >= 3.13
108108
target_link_libraries("${_sapi_bin}" PRIVATE
@@ -123,12 +123,12 @@ function(add_sapi_library)
123123
endif()
124124

125125
# Interface
126-
list(JOIN _sapi_FUNCTIONS "," _sapi_funcs)
126+
list_join(_sapi_FUNCTIONS "," _sapi_funcs)
127127
foreach(src IN LISTS _sapi_INPUTS)
128128
get_filename_component(src "${src}" ABSOLUTE)
129129
list(APPEND _sapi_full_inputs "${src}")
130130
endforeach()
131-
list(JOIN _sapi_full_inputs "," _sapi_full_inputs)
131+
list_join(_sapi_full_inputs "," _sapi_full_inputs)
132132
if(NOT _sapi_NOEMBED)
133133
set(_sapi_embed_dir "${CMAKE_CURRENT_BINARY_DIR}")
134134
set(_sapi_embed_name "${_sapi_NAME}")
@@ -152,7 +152,7 @@ function(add_sapi_library)
152152
if(NOT _sapi_SOURCES)
153153
set(_sapi_force_cxx_linkage
154154
"${CMAKE_CURRENT_BINARY_DIR}/${_sapi_NAME}_force_cxx_linkage.cc")
155-
file(TOUCH "${_sapi_force_cxx_linkage}")
155+
file(WRITE "${_sapi_force_cxx_linkage}" "")
156156
list(APPEND _sapi_SOURCES "${_sapi_force_cxx_linkage}")
157157
endif()
158158
add_library("${_sapi_NAME}" STATIC

cmake/SapiUtil.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ function(create_directory_symlink SOURCE DESTINATION)
3535
endif()
3636
endfunction()
3737

38+
# Implements list(JOIN ...) for CMake < 3.12.
39+
function(list_join LIST SEP OUTPUT)
40+
foreach(item IN LISTS ${LIST})
41+
set(_concat "${_concat}${SEP}${item}")
42+
endforeach()
43+
string(LENGTH "${SEP}" _len)
44+
string(SUBSTRING "${_concat}" ${_len} -1 _concat)
45+
set(${OUTPUT} "${_concat}" PARENT_SCOPE)
46+
endfunction()
47+
3848
# Helper function that behaves just like Protobuf's protobuf_generate_cpp(),
3949
# except that it strips import paths. This is necessary, because CMake's
4050
# protobuf rules don't work well with imports across different directories.

cmake/protobuf/Download.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@ set(protobuf_WITH_ZLIB OFF CACHE BOOL "")
3838

3939
add_subdirectory("${CMAKE_BINARY_DIR}/protobuf-src/cmake"
4040
"${CMAKE_BINARY_DIR}/protobuf-build" EXCLUDE_FROM_ALL)
41+
get_property(Protobuf_INCLUDE_DIRS TARGET protobuf::libprotobuf
42+
PROPERTY INCLUDE_DIRECTORIES)

sandboxed_api/examples/stringop/lib/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ add_library(sapi_stringop_params_proto OBJECT
2323
${_sapi_stringop_params_pb_h}
2424
)
2525
add_library(sapi::stringop_params_proto ALIAS sapi_stringop_params_proto)
26-
target_link_libraries(sapi_stringop_params_proto
27-
PRIVATE sapi::base
28-
PUBLIC protobuf::libprotobuf
26+
target_include_directories(sapi_stringop_params_proto PUBLIC
27+
${Protobuf_INCLUDE_DIRS}
2928
)
3029

3130
# sandboxed_api/examples/stringop/lib:stringop

sandboxed_api/examples/sum/lib/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ add_library(sapi_sum_params_proto OBJECT
2323
${_sapi_sum_params_pb_h}
2424
)
2525
add_library(sapi::sum_params_proto ALIAS sapi_sum_params_proto)
26-
target_link_libraries(sapi_sum_params_proto
27-
PRIVATE sapi::base
28-
PUBLIC protobuf::libprotobuf
26+
target_include_directories(sapi_sum_params_proto PUBLIC
27+
${Protobuf_INCLUDE_DIRS}
2928
)
3029

3130
# sandboxed_api/examples/sum/lib:sum

0 commit comments

Comments
 (0)