arthur.sw
arthur.sw

Reputation: 11669

Link problem: the tiff library does not find cmath on mac (when compiled statically)

My program requires tiff.

Here is my CMakeLists.txt:

...

# Define the Tiff External Project

set(ep TIFF)

set(cmake_cache_args
  -DBUILD_SHARED_LIBS:BOOL=OFF
  -Dtiff-docs:BOOL=OFF
  -Dtiff-test:BOOL=OFF
  -Dtiff-tools:BOOL=OFF
  -Djpeg:BOOL=OFF
  -Doldjpeg:BOOL=OFF
  -Djpeg12:BOOL=OFF
  -Dlzma:BOOL=OFF
  -Dzstd:BOOL=OFF
  -Dwebp:BOOL=OFF
  -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_BINARY_DIR}/ep/${ep}
  )

ExternalProject_Add(${ep}
  PREFIX ${CMAKE_BINARY_DIR}/ep/${ep}
  GIT_REPOSITORY https://gitlab.com/faxguy/libtiff-tools.git
  GIT_TAG master
  CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release
  CMAKE_CACHE_ARGS ${cmake_cache_args}
  BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR>
  INSTALL_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target install
)

...

# Link and compile GcoPS project

find_package (TIFF REQUIRED COMPONENTS tiff)

set(TARGET_NAME GcoPS)
add_executable(${TARGET_NAME})
target_sources(${TARGET_NAME} PRIVATE main.cpp)
target_link_libraries (${TARGET_NAME} PUBLIC TIFF::tiff)

When I compile everything statically (on mac, arm64), I get the following error:


-- Configuring done (0.1s)
CMake Error at /path/to/GcoPS-build-static/ep/TIFF/lib/CMake/tiff/TiffTargets.cmake:61 (set_target_properties):
  The link interface of target "TIFF::tiff" contains:

    CMath::CMath

  but the target was not found.  Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.

Call Stack (most recent call first):
  /path/to/GcoPS-build-static/ep/TIFF/lib/CMake/tiff/TIFFConfig.cmake:23 (include)
  CMakeLists.txt:37 (find_package)

Upvotes: 0

Views: 92

Answers (1)

arthur.sw
arthur.sw

Reputation: 11669

The problem is that the tiff library creates and uses an internal target CMath::CMath.

CMath::CMath wraps the m lib as a cmake target. It is defined with the FindCMath.cmake file (path/to/build/TIFF/src/TIFF/cmake/FindCMath.cmake).

The folder of this cmake module must be added to the CMAKE_MODULE_PATH:

list(APPEND CMAKE_MODULE_PATH "${CMAKE_BINARY_DIR}/../ep/TIFF/src/TIFF/cmake/")

Then, the CMath target must be found before using tiff with:

find_package (CMath)

Here is the corrected CMakeLists.txt:

...
# ADD PATH TO THE FOLDER CONTAINING path/to/build/TIFF/src/TIFF/cmake/FindCMath.cmake
list(APPEND CMAKE_MODULE_PATH "${CMAKE_BINARY_DIR}/../ep/TIFF/src/TIFF/cmake/")

find_package (TIFF REQUIRED COMPONENTS tiff)

# ADD THE TIFF CMATH
find_package (CMath) 


set(TARGET_NAME GcoPS)
add_executable(${TARGET_NAME})
target_sources(${TARGET_NAME} PRIVATE main.cpp)
target_link_libraries (${TARGET_NAME} PUBLIC TIFF::tiff)

Upvotes: 1

Related Questions