-
Notifications
You must be signed in to change notification settings - Fork 31
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 optional binary relocatability in downstream libraries #334
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# For the tests, we make sure that the relative path in the build location is the same | ||
# of the install, and we make sure that the value returned by the shared library is ${CMAKE_BINARY_DIR} | ||
# while for the static library we make sure that the value returned is ${CMAKE_INSTALL_PREFIX} | ||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}") | ||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}") | ||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}") | ||
|
||
include(GzUtils) | ||
|
||
# dladdr from dl is a compulsory requirement for | ||
# gz_add_get_install_prefix_impl | ||
gz_find_package(DL REQUIRED) | ||
|
||
# shared test | ||
add_library(get-install-prefix-test-shared SHARED) | ||
set(PROJECT_LIBRARY_TARGET_NAME get-install-prefix-test-shared) | ||
|
||
gz_add_get_install_prefix_impl(GET_INSTALL_PREFIX_HEADER get_install_prefix_test_shared.h | ||
GET_INSTALL_PREFIX_FUNCTION gz::cmake::test::sharedlib::getInstallPrefix | ||
OVERRIDE_INSTALL_PREFIX_ENV_VARIABLE GET_INSTALL_PREFIX_TEST_INSTALL_PREFIX) | ||
set_target_properties(get-install-prefix-test-shared PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON) | ||
target_include_directories(get-install-prefix-test-shared PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) | ||
target_compile_features(get-install-prefix-test-shared PRIVATE cxx_std_17) | ||
|
||
|
||
# static test | ||
add_library(get-install-prefix-test-static STATIC) | ||
set(PROJECT_LIBRARY_TARGET_NAME get-install-prefix-test-static) | ||
|
||
gz_add_get_install_prefix_impl(GET_INSTALL_PREFIX_HEADER get_install_prefix_test_static.h | ||
GET_INSTALL_PREFIX_FUNCTION gz::cmake::test::staticlib::getInstallPrefix | ||
OVERRIDE_INSTALL_PREFIX_ENV_VARIABLE GET_INSTALL_PREFIX_TEST_INSTALL_PREFIX) | ||
target_include_directories(get-install-prefix-test-static PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) | ||
target_compile_features(get-install-prefix-test-static PRIVATE cxx_std_17) | ||
|
||
|
||
# Write header with CMake variables to check | ||
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/get_install_prefix_test_cmake_variables.h | ||
"#pragma once | ||
|
||
#define CMAKE_INSTALL_PREFIX \"${CMAKE_INSTALL_PREFIX}\" | ||
#define CMAKE_BINARY_DIR \"${CMAKE_BINARY_DIR}\" | ||
|
||
") | ||
|
||
|
||
|
||
# Add test executable | ||
add_executable(get_install_prefix_test get_install_prefix_test.cc) | ||
target_include_directories(get_install_prefix_test PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) | ||
target_link_libraries(get_install_prefix_test PRIVATE get-install-prefix-test-shared | ||
get-install-prefix-test-static) | ||
target_compile_features(get_install_prefix_test PRIVATE cxx_std_17) | ||
|
||
# Add the test only if GZ_ENABLE_RELOCATABLE_INSTALL is enabled, | ||
# as the test on gz_add_get_install_prefix_impl rely on GZ_ENABLE_RELOCATABLE_INSTALL | ||
# being enabled | ||
if(GZ_ENABLE_RELOCATABLE_INSTALL) | ||
add_test(NAME get_install_prefix_test COMMAND get_install_prefix_test) | ||
endif() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could we add please the documentation for the
GET_INSTALL_PREFIX_FUNCTION
,GET_INSTALL_PREFIX_HEADER
andOVERRIDE_INSTALL_PREFIX_ENV_VARIABLE
using the same format that the rest of the GzUtils file?snippet from gz_build_executables
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.
Done in d7708fc . After writing the "Example" part, I wonder if it could make sense to make the arguments optional, and use as default values the one that I put as example. What do you think?