Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CMake install commands for Au #265

Merged
merged 6 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/license-check/license-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
".github/**/*.yml",
"requirements.in",
"cmake/*.cmake",
"WORKSPACE"
"cmake/*.cmake.in",
"**/WORKSPACE"
],
"exclude": [
"third_party/**/*"
Expand Down
37 changes: 36 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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}
)
8 changes: 8 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
2 changes: 1 addition & 1 deletion au/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions cmake/AuConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -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)
13 changes: 12 additions & 1 deletion cmake/HeaderOnlyLibrary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand Down
15 changes: 15 additions & 0 deletions cmake/WORKSPACE
Original file line number Diff line number Diff line change
@@ -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.
15 changes: 15 additions & 0 deletions cmake/project_symlinks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions cmake/project_symlinks/au
Loading