Closed stevn closed 2 years ago
Conan logs show shared is being set to OFF:
-- Conan toolchain: Setting BUILD_SHARED_LIBS = OFF
But later in the libtiff CMake, it is set to ON:
-- Build shared libraries: ON
The CMake cache variable is set to ON by default here by libtiff's root CMakeLists.txt:
https://gitlab.com/libtiff/libtiff/-/blob/v4.4.0/CMakeLists.txt#L43
set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries")
In the Conan toolchain file this is set to OFF:
C:\wrk\.conan\data\libtiff\4.4.0\_\_\build\6783500b4f0c78e0f2a6c78a711270cc09b59dec\build\generators\conan_toolchain.cmake
message(STATUS "Conan toolchain: Setting BUILD_SHARED_LIBS = OFF")
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries")
https://cmake.org/cmake/help/latest/command/set.html
Sets the given cache
(cache entry). Since cache entries are meant to provide user-settable values this does not overwrite existing cache entries by default. Use the FORCE option to overwrite existing entries.
So it seems to boil down to the question in which order these CMake set commands are executed.
The relevant CMake command is:
libtiff/4.4.0: CMake command: cmake -G "Visual Studio 16 2019" -DCMAKE_TOOLCHAIN_FILE="C:/wrk/.conan/data/libtiff/4.4.0/_/_/build/6783500b4f0c78e0f2a6c78a711270cc09b59dec/build/generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="C:/wrk/.conan/data/libtiff/4.4.0/_/_/package/6783500b4f0c78e0f2a6c78a711270cc09b59dec" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" "C:\wrk\.conan\data\libtiff\4.4.0\_\_\build\6783500b4f0c78e0f2a6c78a711270cc09b59dec\src"
The CMake documentation indicates that the CMAKE_TOOLCHAIN_FILE is interpreted "early". It is unclear what "early" means exactly.
https://cmake.org/cmake/help/latest/variable/CMAKE_TOOLCHAIN_FILE.html
It is the path to a file which is read early in the CMake run and which specifies locations for compilers and toolchain utilities, and other target platform and compiler related information.
Here the usage of cache variables via CMake toolchain files is discouraged:
https://discourse.cmake.org/t/configurable-in-cmake-toolchain-file-files/1122/3
Because it is a cache variable, it will only set the value of SOME_VAR if it is not already set. It is not wrong to do so, but usually not the best approach. I tend to only need to set plain variables in toolchain files.
The project() command trigger most of CMake's detection magic (including reading from the Toolchain.txt file).
It seems to me that the CMake toolchain file is being interpreted on the first project() call (line 52). However, just before that project() call, the libtiff root CMakeLists.txt is setting the cache variable (line 43), which means that the set() call in the toolchain file has no effect.
CMakeLists.txt:
set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries")
# Disable deprecated features to ensure clean build
add_definitions(-DTIFF_DISABLE_DEPRECATED)
# Project definition
set(CMAKE_C_STANDARD 99)
project(tiff
VERSION "${LIBTIFF_VERSION}"
LANGUAGES C CXX)`
So building static libtiff 4.4.0 with CMake toolchain files (which set the cache variable BUILD_SHARED_LIBS without FORCE) seems to be broken. Maybe this should be brought to the attention of the libtiff developers.
Seems like there are some other people having similar problems:
https://gitlab.kitware.com/cmake/cmake/-/issues/23237 https://github.com/conan-io/conan/issues/7831 https://github.com/conan-io/conan/issues/7832 https://github.com/conan-io/conan/pull/8124 https://github.com/conan-io/conan/issues/11224 https://github.com/conan-io/conan/projects/35#card-47728228 https://github.com/conan-io/conan/issues/11840 https://github.com/conan-io/conan/pull/12401
will be fixed by https://github.com/conan-io/conan-center-index/pull/14210
The root cause is that in upstream CMakeLists, there is set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries")
, so CMakeToolchain in conan < 1.54.0 can't handle this case properly. Moreover, even conan 1.54.0 (https://github.com/conan-io/conan/pull/12401) can't work out of the box because this set(BUILD_SHARED_LIBS
is put before project()
.
The only solution is to pass -DBUILD_SHARED_LIBS=OFF
in CMake command line (so tc.cache_variables
in CMakeToolchain).
Might already be fixed in libtiff master branch:
https://gitlab.com/libtiff/libtiff/-/blob/master/CMakeLists.txt#L51
Description
There are a few different recipe revisions of libtiff/4.4.0 available on Conan Center. When building the newest one as static library on Windows, the shared library (.dll) is built instead.
This can be seen in the libtiff CMake log as the following entry:
For static build we want this to be OFF and expect to be able to achieve this by adding "-o libtiff:shared=False" to the Conan command.
Please note that the pre-built binaries downloaded from the conancenter are OK (they are static builds) as far as I know. So if you don't rebuild libtiff from source, it just downloads the correct static built binaries (.lib files for Windows) and everything works. But if you need to disable the jbig option for example to disable GPL code, you need to rebuild from source, which seems to be broken.
This recipe revision is the last one that works OK for static builds:
These recipe revisions are broken (producing .dll files on Windows):
Package and Environment Details
Conan profile
Steps to reproduce
Logs
Click to expand log
``` Microsoft Windows [Version 10.0.19044.2251] (c) Microsoft Corporation. All rights reserved. C:\wrk>set CONAN_USER_HOME=C:\wrk C:\wrk>conan config set general.revisions_enabled=1 C:\wrk>conan install libtiff/4.4.0@ -o libtiff:shared=False -o libtiff:jbig=False --build=missing -s:b compiler.version=16 -s:h compiler.version=16 Auto detecting your dev setup to initialize the default profile (C:\wrk\.conan\profiles\default) Found Visual Studio 17 Found gcc 8.3 Default settings os=Windows os_build=Windows arch=x86_64 arch_build=x86_64 compiler=Visual Studio compiler.version=17 build_type=Release *** You can change them in C:\wrk\.conan\profiles\default *** *** Or override with -s compiler='other' -s ...s*** WARN: Remotes registry file missing, creating default one in C:\wrk\.conan\remotes.json Configuration (profile_host): [settings] arch=x86_64 arch_build=x86_64 build_type=Release compiler=Visual Studio compiler.runtime=MD compiler.version=16 os=Windows os_build=Windows [options] libtiff:jbig=False libtiff:shared=False [build_requires] [env] Configuration (profile_build): [settings] arch=x86_64 arch_build=x86_64 build_type=Release compiler=Visual Studio compiler.runtime=MD compiler.version=16 os=Windows os_build=Windows [options] [build_requires] [env] libtiff/4.4.0: Not found in local cache, looking in remotes... libtiff/4.4.0: Trying with 'conancenter'... Downloading conanmanifest.txt completed [0.19k] Downloading conanfile.py completed [7.67k] Downloading conan_export.tgz completed [0.32k] Decompressing conan_export.tgz completed [0.00k] libtiff/4.4.0: Downloaded recipe revision 604133fe6dfacb0f213409b4395ceedc zlib/1.2.13: Not found in local cache, looking in remotes... zlib/1.2.13: Trying with 'conancenter'... Downloading conanmanifest.txt completed [0.28k] Downloading conanfile.py completed [4.04k] Downloading conan_export.tgz completed [0.29k] Decompressing conan_export.tgz completed [0.00k] zlib/1.2.13: Downloaded recipe revision 13c96f538b52e1600c40b88994de240f libdeflate/1.12: Not found in local cache, looking in remotes... libdeflate/1.12: Trying with 'conancenter'... Downloading conanmanifest.txt completed [0.19k] Downloading conanfile.py completed [4.91k] Downloading conan_export.tgz completed [0.35k] Decompressing conan_export.tgz completed [0.00k] libdeflate/1.12: Downloaded recipe revision 1bf16d0e3c7c43d8b44ebd368425b462 xz_utils/5.2.5: Not found in local cache, looking in remotes... xz_utils/5.2.5: Trying with 'conancenter'... Downloading conanmanifest.txt completed [0.10k] Downloading conanfile.py completed [11.03k] Downloading conan_export.tgz completed [0.23k] Decompressing conan_export.tgz completed [0.00k] xz_utils/5.2.5: Downloaded recipe revision 7315e0f635fed3f9a91b8bfd5456b72c libjpeg/9e: Not found in local cache, looking in remotes... libjpeg/9e: Trying with 'conancenter'... Downloading conanmanifest.txt completed [0.26k] Downloading conanfile.py completed [8.16k] Downloading conan_export.tgz completed [0.28k] Decompressing conan_export.tgz completed [0.00k] libjpeg/9e: Downloaded recipe revision 129230c05b9705a9bbd6724f5de8eb98 zstd/1.5.2: Not found in local cache, looking in remotes... zstd/1.5.2: Trying with 'conancenter'... Downloading conanmanifest.txt completed [0.20k] Downloading conanfile.py completed [3.65k] Downloading conan_export.tgz completed [0.29k] Decompressing conan_export.tgz completed [0.00k] zstd/1.5.2: Downloaded recipe revision 32ecc755aa20cb076cd7e851e3ad3f52 libwebp/1.2.4: Not found in local cache, looking in remotes... libwebp/1.2.4: Trying with 'conancenter'... Downloading conanmanifest.txt completed [0.18k] Downloading conanfile.py completed [5.72k] Downloading conan_export.tgz completed [0.28k] Decompressing conan_export.tgz completed [0.00k] libwebp/1.2.4: Downloaded recipe revision ea598b8eae9729538cffc84de170462f Installing package: libtiff/4.4.0 Requirements libdeflate/1.12 from 'conancenter' - Downloaded libjpeg/9e from 'conancenter' - Downloaded libtiff/4.4.0 from 'conancenter' - Downloaded libwebp/1.2.4 from 'conancenter' - Downloaded xz_utils/5.2.5 from 'conancenter' - Downloaded zlib/1.2.13 from 'conancenter' - Downloaded zstd/1.5.2 from 'conancenter' - Downloaded Packages libdeflate/1.12:3fb49604f9c2f729b85ba3115852006824e72cab - Download libjpeg/9e:3fb49604f9c2f729b85ba3115852006824e72cab - Download libtiff/4.4.0:6783500b4f0c78e0f2a6c78a711270cc09b59dec - Build libwebp/1.2.4:638042d3fd356128c913f5e725646a0c2af264c7 - Download xz_utils/5.2.5:3fb49604f9c2f729b85ba3115852006824e72cab - Download zlib/1.2.13:3fb49604f9c2f729b85ba3115852006824e72cab - Download zstd/1.5.2:72381fc5a05da7a9f5e4d254cd58aa074c20b053 - Download Installing (downloading, building) binaries... libdeflate/1.12: Retrieving package 3fb49604f9c2f729b85ba3115852006824e72cab from remote 'conancenter' Downloading conanmanifest.txt completed [0.22k] Downloading conaninfo.txt completed [0.43k] Downloading conan_package.tgz completed [60.50k] Decompressing conan_package.tgz completed [0.00k] libdeflate/1.12: Package installed 3fb49604f9c2f729b85ba3115852006824e72cab libdeflate/1.12: Downloaded package revision 93488f354325d0d52fed332ebf5e07b6 libjpeg/9e: Retrieving package 3fb49604f9c2f729b85ba3115852006824e72cab from remote 'conancenter' Downloading conanmanifest.txt completed [0.56k] Downloading conaninfo.txt completed [0.43k] Downloading conan_package.tgz completed [269.31k] Decompressing conan_package.tgz completed [0.00k] libjpeg/9e: Package installed 3fb49604f9c2f729b85ba3115852006824e72cab libjpeg/9e: Downloaded package revision 5139f5214cb2364a0ca735875c333254 libwebp/1.2.4: Retrieving package 638042d3fd356128c913f5e725646a0c2af264c7 from remote 'conancenter' Downloading conanmanifest.txt completed [0.63k] Downloading conaninfo.txt completed [0.56k] Downloading conan_package.tgz completed [555.49k] Decompressing conan_package.tgz completed [0.00k] libwebp/1.2.4: Package installed 638042d3fd356128c913f5e725646a0c2af264c7 libwebp/1.2.4: Downloaded package revision c455d00da184708eb0bae98563c40792 xz_utils/5.2.5: Retrieving package 3fb49604f9c2f729b85ba3115852006824e72cab from remote 'conancenter' Downloading conanmanifest.txt completed [1.05k] Downloading conaninfo.txt completed [0.43k] Downloading conan_package.tgz completed [334.69k] Decompressing conan_package.tgz completed [0.00k] xz_utils/5.2.5: Package installed 3fb49604f9c2f729b85ba3115852006824e72cab xz_utils/5.2.5: Downloaded package revision 016a8982e7c3311501a775d00099543e zlib/1.2.13: Retrieving package 3fb49604f9c2f729b85ba3115852006824e72cab from remote 'conancenter' Downloading conanmanifest.txt completed [0.25k] Downloading conaninfo.txt completed [0.43k] Downloading conan_package.tgz completed [97.10k] Decompressing conan_package.tgz completed [0.00k] zlib/1.2.13: Package installed 3fb49604f9c2f729b85ba3115852006824e72cab zlib/1.2.13: Downloaded package revision af3348b4caca1d82c42531a352a4cc25 zstd/1.5.2: Retrieving package 72381fc5a05da7a9f5e4d254cd58aa074c20b053 from remote 'conancenter' Downloading conanmanifest.txt completed [0.31k] Downloading conaninfo.txt completed [0.46k] Downloading conan_package.tgz completed [378.13k] Decompressing conan_package.tgz completed [0.00k] zstd/1.5.2: Package installed 72381fc5a05da7a9f5e4d254cd58aa074c20b053 zstd/1.5.2: Downloaded package revision 68b8097e07c66d6a1ca79244fc28d802 Downloading conan_sources.tgz completed [1.00k] Decompressing conan_sources.tgz completed [0.00k] libtiff/4.4.0: Configuring sources in C:\wrk\.conan\data\libtiff\4.4.0\_\_\source\src Downloading tiff-4.4.0.tar.gz completed [2774.49k] libtiff/4.4.0: /4.4.0: libtiff/4.4.0: libtiff/4.4.0: Copying sources to build folder libtiff/4.4.0: Building your package in C:\wrk\.conan\data\libtiff\4.4.0\_\_\build\6783500b4f0c78e0f2a6c78a711270cc09b59dec libtiff/4.4.0: Generator txt created conanbuildinfo.txt libtiff/4.4.0: Calling generate() libtiff/4.4.0: Preset 'default' added to CMakePresets.json. Invoke it manually using 'cmake --preset default' libtiff/4.4.0: If your CMake version is not compatible with CMakePresets (<3.19) call cmake like: 'cmake