-
In particular to support Windows users of my Python wheel, I want to statically link zlib, which is fetched. (expat is also fetched/linked). But I'm running into some issues with this, which go out of my knowledge of CMake. A mocked up, minimal example: cmake_minimum_required(VERSION 3.24)
project(myproject VERSION 0.0.1)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build a static library for all libraries" FORCE)
# Some other library configuration here, like disabling Brotli, etc
FetchContent_Declare(
Zlib
GIT_REPOSITORY https://github.com/madler/zlib.git
GIT_TAG v1.3.1
GIT_SHALLOW TRUE
OVERRIDE_FIND_PACKAGE)
FetchContent_MakeAvailable(Zlib)
add_library(ZLIB::ZLIB ALIAS zlibstatic)
FetchContent_Declare(
EXPAT
GIT_REPOSITORY https://github.com/libexpat/libexpat.git
GIT_TAG R_2_7_1
GIT_SHALLOW TRUE
SOURCE_SUBDIR expat OVERRIDE_FIND_PACKAGE)
FetchContent_MakeAvailable(expat)
add_library(EXPAT::EXPAT ALIAS expat)
FetchContent_Declare(
exiv2
GIT_REPOSITORY https://github.com/Exiv2/exiv2.git
GIT_TAG v0.28.5
GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(exiv2)
target_link_libraries(mytarget PRIVATE Exiv2::exiv2lib) If I do not include the
But with those, I get:
I'm not really sure what that is saying or how to resolve it. I would appriciate any help or ideas from those more knowledgeable in CMake. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
@stumpylog I don't know the answer to your question, however I have a question for you! Does the code in mylibrary reference zlib or expat? If mylibrary doesn't explicitly use zlib or expat I believe you should only link/add_library Exiv2::exiv2lib. |
Beta Was this translation helpful? Give feedback.
-
Well done, @stumpylog for digging into this. Your code is very neat and clear. Good Job. I'm not a CMake expert, however I'm surprised you need so much code in CMakeLists.txt. I wrote instructions about linking code for exiv2 v0.27. I only needed 8 lines in CMakeLists.txt 2.6 Consuming Exiv2 with CMake When exiv2 is installed, the files required to consume Exiv2 are installed in ${CMAKE_INSTALL_PREFIX}/lib/cmake/exiv2 You can build samples/exifprint.cpp as follows: $ cd <exiv2dir>
$ mkdir exifprint
$ cd exifprint
$ cat - > CMakeLists.txt <<EOF
cmake_minimum_required(VERSION 3.8)
project(exifprint VERSION 0.0.1 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 98)
set(CMAKE_CXX_EXTENSIONS OFF)
find_package(exiv2 REQUIRED CONFIG NAMES exiv2) # search ${CMAKE_INSTALL_PREFIX}/lib/cmake/exiv2/
add_executable(exifprint ../samples/exifprint.cpp) # compile this
target_link_libraries(exifprint exiv2lib) # link exiv2lib
EOF
$ cmake . # generate the makefile
$ make # build the code
$ ./exifprint # test your executable
Usage: bin/exifprint [ path | --version | --version-test ]
$ Anyway, you've written some nice code which will be of use to another user. Thanks for your contribution. |
Beta Was this translation helpful? Give feedback.
The only target_link_libraries is to Exiv2. The rest was just hacks to get it happy enough to configure and build.
The full, not so trivial file: https://github.com/stumpylog/exifmwg/blob/develop/CMakeLists.txt