diff --git a/.github/license-check/license-config.json b/.github/license-check/license-config.json index 4ecad8c..e3a52c5 100644 --- a/.github/license-check/license-config.json +++ b/.github/license-check/license-config.json @@ -18,7 +18,8 @@ ".github/**/*.yml", "requirements.in", "cmake/*.cmake", - "WORKSPACE" + "cmake/*.cmake.in", + "**/WORKSPACE" ], "exclude": [ "third_party/**/*" diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d4815e..32620d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,9 @@ project( LANGUAGES CXX ) +# The export set for all of our headers. +set(AU_EXPORT_SET_NAME AuHeaders) + enable_testing() # Bring in GoogleTest so we can build and run the tests. @@ -52,4 +55,36 @@ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) FetchContent_MakeAvailable(googletest) include(GoogleTest) -add_subdirectory(au) +add_subdirectory(cmake/project_symlinks) + +# Configure how Au will be installed. +# +# (This is necessary for it to be usable in other CMake projects.) + +set(AU_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/Au) + +install( + EXPORT ${AU_EXPORT_SET_NAME} + DESTINATION ${AU_CMAKE_DIR} + NAMESPACE Au:: + FILE AuHeaders.cmake +) + +include(CMakePackageConfigHelpers) +configure_package_config_file( + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/AuConfig.cmake.in + AuConfig.cmake + INSTALL_DESTINATION ${AU_CMAKE_DIR} +) + +write_basic_package_version_file( + AuConfigVersion.cmake + COMPATIBILITY SameMinorVersion +) + +install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/AuConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/AuConfigVersion.cmake + DESTINATION ${AU_CMAKE_DIR} +) diff --git a/WORKSPACE b/WORKSPACE index a0e6259..4668587 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -216,3 +216,11 @@ http_archive( # END SECTION: Install buildifier. ################################################################################ + +# This is not a "real" local bazel repository. We define this in this WORKSPACE +# file because it will prevent bazel from looking for packages in this folder +# and its children. +local_repository( + name = "ignore_cmake", + path = "./cmake", +) diff --git a/au/CMakeLists.txt b/au/CMakeLists.txt index 7b237dc..3549241 100644 --- a/au/CMakeLists.txt +++ b/au/CMakeLists.txt @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -include(../cmake/HeaderOnlyLibrary.cmake) +include("${PROJECT_SOURCE_DIR}/cmake/HeaderOnlyLibrary.cmake") # # Publicly exported targets diff --git a/cmake/AuConfig.cmake.in b/cmake/AuConfig.cmake.in new file mode 100644 index 0000000..65da38a --- /dev/null +++ b/cmake/AuConfig.cmake.in @@ -0,0 +1,19 @@ +# Copyright 2024 Aurora Operations, Inc. +# +# 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. + +@PACKAGE_INIT@ + +include(${CMAKE_CURRENT_LIST_DIR}/AuHeaders.cmake) + +check_required_components(Au) diff --git a/cmake/HeaderOnlyLibrary.cmake b/cmake/HeaderOnlyLibrary.cmake index 65fdb75..aa1c7da 100644 --- a/cmake/HeaderOnlyLibrary.cmake +++ b/cmake/HeaderOnlyLibrary.cmake @@ -45,7 +45,7 @@ function(header_only_library) ${ARG_NAME} INTERFACE FILE_SET HEADERS - BASE_DIRS ${CMAKE_SOURCE_DIR} + BASE_DIRS "${PROJECT_SOURCE_DIR}/cmake/project_symlinks" FILES ${ARG_HEADERS} ) if (DEFINED ARG_DEPS) @@ -61,8 +61,19 @@ function(header_only_library) # See: https://stackoverflow.com/a/68321274 if (ARG_INTERNAL_ONLY) set_target_properties(${ARG_NAME} PROPERTIES EXPORT_NAME "_Au_private_${ARG_NAME}") + else() + add_library(Au::${ARG_NAME} ALIAS ${ARG_NAME}) endif() + # Install the library. (This is required for other projects to use Au via CMake.) + include(GNUInstallDirs) + install( + TARGETS ${ARG_NAME} + EXPORT ${AU_EXPORT_SET_NAME} + FILE_SET HEADERS + INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" + ) + # Add the test, if requested. if (DEFINED ARG_GTEST_SRCS) add_executable("${ARG_NAME}_test") diff --git a/cmake/WORKSPACE b/cmake/WORKSPACE new file mode 100644 index 0000000..c0dfd4d --- /dev/null +++ b/cmake/WORKSPACE @@ -0,0 +1,15 @@ +# Copyright 2024 Aurora Operations, Inc. +# +# 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. + +# This file exists so that bazel will ignore this folder. diff --git a/cmake/project_symlinks/CMakeLists.txt b/cmake/project_symlinks/CMakeLists.txt new file mode 100644 index 0000000..1def64a --- /dev/null +++ b/cmake/project_symlinks/CMakeLists.txt @@ -0,0 +1,15 @@ +# Copyright 2024 Aurora Operations, Inc. +# +# 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. + +add_subdirectory(au) diff --git a/cmake/project_symlinks/au b/cmake/project_symlinks/au new file mode 120000 index 0000000..d3a01f9 --- /dev/null +++ b/cmake/project_symlinks/au @@ -0,0 +1 @@ +../../au \ No newline at end of file