-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[WIP] CMake Install rule proposal #182
Conversation
In the interest of incremental change, can we wait until #136 is in, and then add this to absl_cc_library? |
a5f17b1
to
f114e0d
Compare
I think first we should use [0]─[~/work/abseil-cpp]
[^v^]─corentinl@corentinl %grepc -RIin "absl_\(library\|header\)" absl
absl/meta/CMakeLists.txt:32:absl_header_library(
absl/types/CMakeLists.txt:28:absl_header_library(
absl/types/CMakeLists.txt:43:absl_header_library(
absl/types/CMakeLists.txt:59:absl_library(
absl/types/CMakeLists.txt:75:absl_library(
absl/types/CMakeLists.txt:94:absl_library(
absl/types/CMakeLists.txt:106:absl_library(
absl/algorithm/CMakeLists.txt:34:absl_header_library(
absl/memory/CMakeLists.txt:22:absl_header_library(
absl/container/CMakeLists.txt:51:absl_header_library(
absl/container/CMakeLists.txt:70:absl_library(
absl/utility/CMakeLists.txt:22:absl_header_library(
absl/strings/CMakeLists.txt:72:absl_library(
absl/strings/CMakeLists.txt:84:absl_header_library(
absl/strings/CMakeLists.txt:94:absl_library(
absl/strings/CMakeLists.txt:121:absl_library(
absl/debugging/CMakeLists.txt:72:absl_library(
absl/debugging/CMakeLists.txt:81:absl_library(
absl/debugging/CMakeLists.txt:93:absl_library(
absl/debugging/CMakeLists.txt:106:absl_library(
absl/debugging/CMakeLists.txt:121:absl_library(
absl/debugging/CMakeLists.txt:134:absl_header_library(
absl/debugging/CMakeLists.txt:152:absl_library(
absl/numeric/CMakeLists.txt:27:absl_library(
absl/numeric/CMakeLists.txt:39:absl_header_library(
absl/hash/CMakeLists.txt:36:absl_library(
absl/synchronization/CMakeLists.txt:50:absl_library(
absl/time/CMakeLists.txt:60:absl_library(
absl/base/CMakeLists.txt:74:absl_library(
absl/base/CMakeLists.txt:124:absl_library(
[0]─[~/work/abseil-cpp]
[^v^]─corentinl@corentinl %grepc -RIin "absl_cc_library(" absl
absl/base/CMakeLists.txt:86:absl_cc_library(
absl/base/CMakeLists.txt:101:absl_cc_library(
absl/base/CMakeLists.txt:131:absl_cc_library(
absl/base/CMakeLists.txt:141:absl_cc_library( EDIT: done internally and make their way outside... |
cf4e749
to
7df7969
Compare
e372b9a
to
f18b05d
Compare
set(ABSL_VERSION @PROJECT_VERSION@) | ||
|
||
@PACKAGE_INIT@ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to have more meta data here, e.g.
set_and_check(@PROJECT_NAME@_HOME "${PACKAGE_PREFIX_DIR}")
set_and_check(@PROJECT_NAME@_INCLUDEDIR "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_INCLUDEDIR@")
set_and_check(@PROJECT_NAME@_LIBDIR "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_LIBDIR@")
set(@PROJECT_NAME@_TARGETS absl::* absl::*_internal)
set(@PROJECT_NAME@_PUBLIC_TARGETS absl::*)
set(@PROJECT_NAME@_PRIVATE_TARGETS absl::*_internal)
The paths may be extracted from the target properties, but experience shows, it is nicer to have them at hand in a convenient variable (${PACKAGE_PREFIX_DIR}
is populated by the code generated via @PACKAGE_INIT@
at import time).
The entries in the proposed target lists could e.g. easily be collected in the absl_cc_library
function.
Note: @PROJECT_NAME@
is case-sensitive. You may wish to convert to upper case characters.
Note: If you decide to export a path via set_and_check
as proposed in my example above, make sure, this is done only in the cases, when something is installed into these paths. E.g. if you had a build option, which would result in nothing being installed into the lib directory, it is likely the lib directory will not be created and set_and_check
will fail.
@@ -100,9 +111,14 @@ function(absl_cc_library) | |||
|
|||
if(NOT ABSL_CC_LIB_IS_INTERFACE) | |||
add_library(${_NAME} STATIC "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To support shared libraries (Please ignore, if this is not a desired feature at all):
add_library(${_NAME} STATIC "") | |
add_library(${_NAME}) |
The user can now choose between static and shared libraries via -DBUILD_SHARED_LIBS=ON/OFF
. For good practice, you may want to explicitely declare this build switch with an explicit default via option()
. Without declaring it as an option, the default is OFF
(=> static).
Because there are library dependencies within the absl
package, it is recommended to add relative RPATH
entries for relocatability. Here is a snippet how we usually add such entries on Linux and MacOS:
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" isSystemDir)
if("${isSystemDir}" STREQUAL "-1")
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} "-Wl,--enable-new-dtags")
set(CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS} "-Wl,--enable-new-dtags")
set(CMAKE_INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(CMAKE_INSTALL_RPATH "@loader_path/../${CMAKE_INSTALL_LIBDIR}")
endif()
endif()
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
CLAs look good, thanks! |
FYI to "Discuss and review the changes in this comparison with others."
Add install rule to fix #111
absl_cc_library()
functionnote: This is what I would use to integrate abseil-cpp to our Makefile-based/CMake-based build of https://github.com/google/or-tools (cf google/or-tools#871)
note: For Googlers, backported (and pending) as CL 225323703