-
Notifications
You must be signed in to change notification settings - Fork 207
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
cmake config: Use find_dependency to make linked targets available #1339
base: main
Are you sure you want to change the base?
cmake config: Use find_dependency to make linked targets available #1339
Conversation
e7bc8ce
to
01bae06
Compare
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.
Thanks for the patch. I made a similar fix in libwebp a little while ago.
I extended our tests to include an executable to make sure the dependencies worked. Maybe .github/workflows/ci-unix-static.yml
can be extended similarly.
cat > CMakeLists.txt <<EOF
cmake_minimum_required(VERSION 2.8.12)
project(libwebp C)
find_package(WebP)
if(NOT WebP_FOUND)
message(FATAL_ERROR "WebP package not found")
endif()
message("WebP_FOUND: \${WebP_FOUND}")
message("WebP_INCLUDE_DIRS: \${WebP_INCLUDE_DIRS}")
message("WebP_LIBRARIES: \${WebP_LIBRARIES}")
message("WEBP_INCLUDE_DIRS: \${WEBP_INCLUDE_DIRS}")
message("WEBP_LIBRARIES: \${WEBP_LIBRARIES}")
if(POLICY CMP0028)
cmake_policy(SET CMP0028 NEW)
endif()
add_executable(main "main.c")
target_link_libraries(main WebP::webp)
target_include_directories(main PRIVATE ${WEBP_INCLUDE_DIRS})
EOF
cat > main.c << EOF
#include "webp/encode.h"
int main() { return WebPGetEncoderVersion(); }
EOF
@@ -605,6 +605,29 @@ if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL) | |||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake | |||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} | |||
) | |||
|
|||
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake.in "@PACKAGE_INIT@\n") | |||
if(UNIX AND NOT BUILD_SHARED_LIBS) |
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.
I suppose in the shared object case, the library's dependency is enough.
if(UNIX AND NOT BUILD_SHARED_LIBS) | ||
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake.in " | ||
include(CMakeFindDependencyMacro) | ||
set(CMAKE_THREAD_PREFER_PTHREADS ON) |
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.
CMAKE_THREAD_PREFER_PTHREAD
?
It looks like this flag went away somewhere between 3.2.x and 3.26.x (or it's left out from the documentation)
https://cmake.org/cmake/help/v3.2/module/FindThreads.html
https://cmake.org/cmake/help/latest/module/FindThreads.html
I forgot to include the invocation:
|
I'm sorry, I lost track of this. There have been changes to the cmake files and this will need to be rebased. cc: @fdintino |
When compiled as static lib the generated config contains the following
but the target
Threads::Threads
is not known because the following is missing:like in the CMakeLists.txt