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

[WIP] CMake Install rule proposal #182

Closed
wants to merge 1 commit into from
Closed

Conversation

Mizux
Copy link
Contributor

@Mizux Mizux commented Oct 4, 2018

FYI to "Discuss and review the changes in this comparison with others."
Add install rule to fix #111

  • Add install rule to absl_cc_library() function
  • Add abslConfig.cmake

note: 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

@Mizux Mizux changed the title CMake Update proposal CMake Update proposal (Install rule) Oct 4, 2018
@JonathanDCohen
Copy link
Contributor

In the interest of incremental change, can we wait until #136 is in, and then add this to absl_cc_library?

@Mizux Mizux changed the title CMake Update proposal (Install rule) CMake Install rule proposal (stall by #136) Oct 19, 2018
@Mizux Mizux force-pushed the master branch 3 times, most recently from a5f17b1 to f114e0d Compare October 19, 2018 09:53
@Mizux
Copy link
Contributor Author

Mizux commented Oct 23, 2018

I think first we should use absl_cc_library() everywhere since the merge of #136
Currently on master:

[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...

@Mizux Mizux changed the title CMake Install rule proposal (stall by #136) [WIP] CMake Install rule proposal Oct 23, 2018
@Mizux Mizux force-pushed the master branch 7 times, most recently from cf4e749 to 7df7969 Compare October 24, 2018 13:31
@Mizux Mizux mentioned this pull request Oct 24, 2018
17 tasks
@Mizux Mizux changed the title [WIP] CMake Install rule proposal [WIP] CMake Install rule proposal (Stall by #199) Oct 25, 2018
@Mizux Mizux force-pushed the master branch 2 times, most recently from e372b9a to f18b05d Compare October 26, 2018 11:41
@Mizux Mizux changed the title [WIP] CMake Install rule proposal (Stall by #199) [WIP] CMake Install rule proposal Jan 3, 2019
set(ABSL_VERSION @PROJECT_VERSION@)

@PACKAGE_INIT@

Copy link

@dennisklein dennisklein Jan 8, 2019

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 "")
Copy link

@dennisklein dennisklein Jan 8, 2019

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):

Suggested change
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()

@googlebot
Copy link

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.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

@googlebot
Copy link

CLAs look good, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Step 6: Allow Abseil to be installed and used with find_package()
5 participants