cmake config: Use find_dependency to make linked targets available#1339
cmake config: Use find_dependency to make linked targets available#1339autoantwort wants to merge 1 commit intoAOMediaCodec:mainfrom
Conversation
e7bc8ce to
01bae06
Compare
jzern
left a comment
There was a problem hiding this comment.
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
| ) | ||
|
|
||
| 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.
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.
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::Threadsis not known because the following is missing:like in the CMakeLists.txt