Skip to content

Commit 82dc7af

Browse files
committed
- Just use CMAKE_INSTALL_LIBDIR etc, instead of making custom variables like LIBRARY_DIRECTORY. Since every platform can do include(GnuInstallDirs), it's fine to rely on the variables it defines, so let's just use them explicitly.
- Explicitly include(GNUInstallDirs) in every CMakeLists.txt that uses the vars it defines (e.g. CMAKE_INSTALL_LIBDIR). I could get away omitting this include, since the AwsSharedLibsSetup.cmake helper script also pulls it in, but it seems like good practice. - Remove custom code that was setting FIND_LIBRARY_USE_LIB64_PATHS. In the PR that introduced this #226 the reviewer called out that this probably wasn't necessary. ChatGPT agrees. CMake is supposed to figure this out automatically. And if it's not working, then it's a weird cross-compile situation where the person building should be setting this to fix things. It shouldn't be up to every library on earth to do this hack. So, this PR started with me thinking that, if we're getting all the shared scripts via `find_package(aws-c-common)`, and the shared scripts are where FIND_LIBRARY_USE_LIB64_PATHS gets customized, but we need to customize FIND_LIBRARY_USE_LIB64_PATHS before we can do `find_package(aws-c-common)`, then ALL projects need to copy/paste the code that customizes FIND_LIBRARY_USE_LIB64_PATHS before doing `find_package(aws-c-common)`. So I set down that path. Then when writing the commit message I was like ... wait a minute this is ridiculous. So did some more research, and learned the FIND_LIBRARY_USE_LIB64_PATHS stuff was probably unnecessary.
1 parent 2b3320d commit 82dc7af

File tree

3 files changed

+11
-20
lines changed

3 files changed

+11
-20
lines changed

CMakeLists.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ include(AwsSanitizers)
1919
include(AwsThreadAffinity)
2020
include(AwsThreadName)
2121
include(CTest)
22+
include(GNUInstallDirs)
2223

2324
set(GENERATED_ROOT_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated")
2425
set(GENERATED_INCLUDE_DIR "${GENERATED_ROOT_DIR}/include")
@@ -257,7 +258,7 @@ foreach(HEADER_SRCPATH IN ITEMS ${AWS_COMMON_HEADERS} ${AWS_COMMON_OS_HEADERS} $
257258
endif()
258259

259260
install(FILES ${HEADER_SRCPATH}
260-
DESTINATION "${INCLUDE_DIRECTORY}/${HEADER_DSTDIR}"
261+
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${HEADER_DSTDIR}"
261262
COMPONENT Development)
262263
endforeach()
263264

@@ -274,12 +275,12 @@ else()
274275
endif()
275276

276277
install(EXPORT "${PROJECT_NAME}-targets"
277-
DESTINATION "${LIBRARY_DIRECTORY}/cmake/${PROJECT_NAME}/${TARGET_DIR}"
278+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}/${TARGET_DIR}"
278279
NAMESPACE AWS::
279280
COMPONENT Development)
280281

281282
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
282-
DESTINATION "${LIBRARY_DIRECTORY}/cmake/${PROJECT_NAME}"
283+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
283284
COMPONENT Development)
284285

285286
list(APPEND EXPORT_MODULES
@@ -296,7 +297,7 @@ list(APPEND EXPORT_MODULES
296297
)
297298

298299
install(FILES ${EXPORT_MODULES}
299-
DESTINATION "${LIBRARY_DIRECTORY}/cmake/${PROJECT_NAME}/modules"
300+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}/modules"
300301
COMPONENT Development)
301302

302303
# This should come last, to ensure all variables defined by cmake will be available for export

cmake/AwsSharedLibSetup.cmake

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,32 @@
11
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0.
33

4-
# NOTE: GNUInstallDirs is also fine for Windows and Mac. It sets reasonable defaults like "lib" and "bin"
54
include(GNUInstallDirs)
6-
set(LIBRARY_DIRECTORY ${CMAKE_INSTALL_LIBDIR})
7-
set(RUNTIME_DIRECTORY ${CMAKE_INSTALL_BINDIR})
8-
set(INCLUDE_DIRECTORY ${CMAKE_INSTALL_INCLUDEDIR})
9-
10-
# this is the absolute dumbest thing in the world, but find_package won't work without it
11-
# also I verified this is correctly NOT "lib64" when CMAKE_C_FLAGS includes "-m32"
12-
if (${LIBRARY_DIRECTORY} STREQUAL "lib64")
13-
set(FIND_LIBRARY_USE_LIB64_PATHS true)
14-
endif()
155

166
function(aws_prepare_shared_lib_exports target)
177
if (BUILD_SHARED_LIBS)
188
install(TARGETS ${target}
199
EXPORT ${target}-targets
2010
ARCHIVE
21-
DESTINATION ${LIBRARY_DIRECTORY}
11+
DESTINATION ${CMAKE_INSTALL_LIBDIR}
2212
COMPONENT Development
2313
LIBRARY
24-
DESTINATION ${LIBRARY_DIRECTORY}
14+
DESTINATION ${CMAKE_INSTALL_LIBDIR}
2515
NAMELINK_SKIP
2616
COMPONENT Runtime
2717
RUNTIME
28-
DESTINATION ${RUNTIME_DIRECTORY}
18+
DESTINATION ${CMAKE_INSTALL_BINDIR}
2919
COMPONENT Runtime)
3020
install(TARGETS ${target}
3121
EXPORT ${target}-targets
3222
LIBRARY
33-
DESTINATION ${LIBRARY_DIRECTORY}
23+
DESTINATION ${CMAKE_INSTALL_LIBDIR}
3424
NAMELINK_ONLY
3525
COMPONENT Development)
3626
else()
3727
install(TARGETS ${target}
3828
EXPORT ${target}-targets
39-
ARCHIVE DESTINATION ${LIBRARY_DIRECTORY}
29+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
4030
COMPONENT Development)
4131
endif()
4232
endfunction()

cmake/CPackConfig.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ endif()
6262
# By default, we'll try to claim the cmake directory under the library directory
6363
# and the aws include directory. We have to share both of these
6464
set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION
65-
/usr/${LIBRARY_DIRECTORY}/cmake
65+
/usr/${CMAKE_INSTALL_LIBDIR}/cmake
6666
/usr/include/aws)
6767

6868
# Include CPack, which generates the package target

0 commit comments

Comments
 (0)