This is an automated email from the ASF dual-hosted git repository. cmcfarlen pushed a commit to branch 10.0.x in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit 6ee2bb6259c7c5c7b3ffb364aaa6d96b1f8eed44 Author: Chris McFarlen <[email protected]> AuthorDate: Thu Jun 27 14:42:46 2024 -0500 Add optional way to extend the build (#11487) * Add ext dir and option to extend the build to add plugins or cripts bundles * cleanup * Check for CMakeLists.txt and warn if not found --------- Co-authored-by: Chris McFarlen <[email protected]> (cherry picked from commit 12d7a6dcc9569dbd0a9fd2c8340eaf3b6768993c) --- CMakeLists.txt | 4 ++++ cmake/add_cripts_bundle.cmake | 34 ++++++++++++++++++++++++++++++++++ ext/CMakeLists.txt | 40 ++++++++++++++++++++++++++++++++++++++++ ext/README.md | 29 +++++++++++++++++++++++++++++ 4 files changed, 107 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index c13ca45af9..b2a30b1afa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -647,6 +647,7 @@ if(CURSES_FOUND) add_subdirectory(src/traffic_top) endif() add_subdirectory(src/traffic_via) + if(ENABLE_CRIPTS) add_subdirectory(src/cripts) endif() @@ -672,6 +673,9 @@ if(ENABLE_EXAMPLE) add_subdirectory(example) endif() +# add any extra subdirectories to the build here +add_subdirectory(ext) + if(ENABLE_DOCS) set(DOC_LANG en diff --git a/cmake/add_cripts_bundle.cmake b/cmake/add_cripts_bundle.cmake new file mode 100644 index 0000000000..a0c774fe12 --- /dev/null +++ b/cmake/add_cripts_bundle.cmake @@ -0,0 +1,34 @@ +####################### +# +# Licensed to the Apache Software Foundation (ASF) under one or more contributor license +# agreements. See the NOTICE file distributed with this work for additional information regarding +# copyright ownership. The ASF licenses this file to you 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. +# +####################### + +function(cripts_sources) + target_sources(cripts PUBLIC ${ARGN}) +endfunction() + +function(cripts_include_directories) + foreach(DIR ${ARGN}) + target_include_directories(cripts AFTER PUBLIC $<BUILD_INTERFACE:${DIR}>) + endforeach() +endfunction() + +function(cripts_link_libraries) + target_link_libraries(cripts PUBLIC ${ARGN}) +endfunction() + +function(cripts_install_bundle_headers bundle) + install(FILES ${ARGN} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/cripts/${bundle}) +endfunction() diff --git a/ext/CMakeLists.txt b/ext/CMakeLists.txt new file mode 100644 index 0000000000..b8838de85e --- /dev/null +++ b/ext/CMakeLists.txt @@ -0,0 +1,40 @@ +####################### +# +# Licensed to the Apache Software Foundation (ASF) under one or more contributor license +# agreements. See the NOTICE file distributed with this work for additional information regarding +# copyright ownership. The ASF licenses this file to you 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. +# +####################### + +# +# This directory can be used to extend the ATS cmake build to include additional plugins or cripts +# directly in the ATS build +# + +include(add_atsplugin) +include(add_cripts_bundle) + +file( + GLOB EXT_SUBDIRS + LIST_DIRECTORIES true + * +) + +foreach(SDIR ${EXT_SUBDIRS}) + if(IS_DIRECTORY ${SDIR}) + if(EXISTS ${SDIR}/CMakeLists.txt) + add_subdirectory(${SDIR}) + else() + message(WARNING "Extra directory ${SDIR} does not contain a CMakeLists.txt file. Ignoring") + endif() + endif() +endforeach() diff --git a/ext/README.md b/ext/README.md new file mode 100644 index 0000000000..3653291c2b --- /dev/null +++ b/ext/README.md @@ -0,0 +1,29 @@ +External build extension directory +---------------------------------- + +Placing directories in this directoy will automatically include them in the build. If you +want to include additional plugins or cripts bundles in your build, you can do so using this +mechanism. + +Below is an example CMakeFiles.txt to include an additional cripts bundle for your cripts to use. + +``` +# Include additional source files with the feature implementation +cripts_sources( + ${CMAKE_CURRENT_SOURCE_DIR}/src/MyBundle/Feature1.cc + ${CMAKE_CURRENT_SOURCE_DIR}/src/MyBundle/Feature2.cc +) +# Add the local include directories +cripts_include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include>) +# Its even possible to link additional libraries should your bundle need +cripts_link_libraries(yaml-cpp::yaml-cpp) + +# finally, install the additional bundle headers that your cripts +# can include to access the new features. +cripts_install_bundle_headers(MyBundle + ${CMAKE_CURRENT_SOURCE_DIR}/include/cripts/MyBundle/Feature1.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/cripts/MyBundle/Feature1.hpp +) +``` + +
