在我的项目中,我使用了differend 3rd 库,它已经预先构建并添加到external-debs 子目录中。我使用多个 FindXXX CMake 脚本来定位这些需求。
当我尝试查找 FreeImage 预构建时,CMake 成功找到该库,但总是返回错误的路径 lib/libfreeimage.a 而不是 ./external-debs/freeimage/lib/windows/x64/libfreeimage.a
这是我的搜索操作:
FIND_LIBRARY(FREE_IMAGE_LIBRARY
NAMES ${LIB_PREFIX}freeimage.${LIB_POSTFIX}
HINTS ${FREE_IMAGE_LIBRARY_DIR}
)
这是我的预定义:
# Determine platform architecture
IF (CMAKE_SIZEOF_VOID_P EQUAL 8 )
SET(ARCHITECTURE "x64")
ELSE()
SET(ARCHITECTURE "x86")
ENDIF()
#Determine platform specific include and library
#paths settings.
IF (WIN32)
IF (MINGW)
SET (LIB_PREFIX "lib")
SET (LIB_POSTFIX "a")
ELSEIF (MSVC)
SET (LIB_POSTFIX "lib")
ENDIF(MINGW)
SET (PLATFORM "windows")
ELSE (UNIX)
SET (LIB_PREFIX "lib")
SET (LIB_POSTFIX "a")
SET (PLATFORM "linux")
ENDIF (WIN32)
SET(FREE_IMAGE_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/external-deps/freeimage/include)
SET(FREE_IMAGE_LIBRARY_DIR ${CMAKE_SOURCE_DIR}/external-deps/freeimage/lib/${PLATFORM}/${ARCHITECTURE})
我使用相同的代码来定位位于同一 external-deps 子文件夹中的其他预构建 3rd 库依赖项(jsoncpp),没有任何问题。
Execute: FindJSON.cmake
-- [INFO]: Find JSON include: ./external-deps/jsoncpp/include
-- [INFO]: Find JSON lib: ./external-deps/jsoncpp/lib/windows/x64/libjsoncpp.a
Execute: FindFreeImage.cmake
-- [INFO]: Find FreeImage include: ./external-deps/freeimage/include
-- [INFO]: Find FreeImage lib: /lib/libfreeimage.a
我在 Windows 平台上使用 CMake 2.8.x。有谁知道为什么 CMake 有时会返回错误的库路径?