我正在尝试编写CMakeList.txt,但我遇到查找软件包的问题。 我想显式指定一些库的路径,我的CMakeList.txt中有以下代码:
var str = "the quick brown fox",
capitalized = str.split(" ").map(function(w){ return w[0].toUpperCase() + w.slice(1); }).join(" ");
console.log(capitalized); // "The Quick Brown Fox"
它按预期工作。 但我想将这些库的目标包含在主CMakeList.txt中。我做了以下事情:
set(ZLIB_ROOT ${CMAKE_SOURCE_DIR}/libs/zlib)
set(ZLIB_LIBRARY zlibstatic)
set(ZLIB_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/libs/zlib)
set(PNG_INCLUDE_DIR libs/lpng ${CMAKE_BINARY_DIR}/libs/lpng)
set(PNG_PNG_INCLUDE_DIR libs/lpng ${CMAKE_BINARY_DIR}/libs/lpng)
set(PNG_LIBRARIES png16_static)
set(PNG_LIBRARY png16_static)
set(JPEG_LIBRARY png16_static)
set(JPEG_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/libs/libjpeg)
set(JPEG_LIBRARY jpeg)
set(CURL_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/libs/curl/include)
set(CURL_LIBRARY libcurl)
FIND_PACKAGE(ZLIB REQUIRED)
FIND_PACKAGE(PNG REQUIRED)
FIND_PACKAGE(JPEG REQUIRED)
FIND_PACKAGE(CURL REQUIRED)
出于某种原因,对add_subdirectory (libs/curl)
add_subdirectory (libs/lpng)
add_subdirectory (libs/libjpeg)
add_subdirectory (libs/zlib)
的调用在库内失败。在第一次运行cmake时,我有以下错误:
FIND_PACKAGE(X)
在第二次运行中,我有不同的错误:
CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.4/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
Could NOT find ZLIB (missing: ZLIB_INCLUDE_DIR) (found version "1.2.8")
Call Stack (most recent call first):
C:/Program Files (x86)/CMake/share/cmake-3.4/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
C:/Program Files (x86)/CMake/share/cmake-3.4/Modules/FindZLIB.cmake:124 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
libs/lpng/CMakeLists.txt:24 (find_package)
第三轮:
CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.4/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
Could NOT find PNG (missing: PNG_PNG_INCLUDE_DIR)
Call Stack (most recent call first):
C:/Program Files (x86)/CMake/share/cmake-3.4/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
C:/Program Files (x86)/CMake/share/cmake-3.4/Modules/FindPNG.cmake:121 (find_package_handle_standard_args)
libs/libdvid-cpp/CMakeLists.txt:118 (FIND_PACKAGE)
最后在第四次运行中没有错误,一切都按预期工作。
我做错了什么?作为一个快速解决方案,我刚删除了上面所有库中的所有CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.4/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
Could NOT find CURL (missing: CURL_LIBRARY CURL_INCLUDE_DIR) (found version
"7.47.1")
Call Stack (most recent call first):
C:/Program Files (x86)/CMake/share/cmake-3.4/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
C:/Program Files (x86)/CMake/share/cmake-3.4/Modules/FindCURL.cmake:61 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
libs/libdvid-cpp/CMakeLists.txt:120 (FIND_PACKAGE)
,它运行正常。