我試圖在OS X下的另一個目錄中同時安裝標準OpenCV作爲自定義版本。這樣做時,我發現OpenCV CMake導致鏈接失敗,標準路徑(即不是/ usr/local)。我可以通過添加一行OpenCVModule.cmake
解決這個問題:如何使用CMake有條件地爲OpenCV dylib文件設置屬性?
set_target_properties(${the_module} PROPERTIES OUTPUT_NAME "${the_module}${OPENCV_DLLVERSION}" DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" COMPILE_PDB_NAME "${the_module}${OPENCV_DLLVERSION}" COMPILE_PDB_NAME_DEBUG "${the_module}${OPENCV_DLLVERSION}${OPENCV_DEBUG_POSTFIX}" ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH} COMPILE_PDB_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH} LIBRARY_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH} RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib ## <--- Added this line )
我試圖回到OpenCV的項目提供這種變化。但在CMAKE_INSTALL_PREFIX
設置爲「/ usr/local」INSTALL_NAME_DIR
不應設置的情況下。我試着加入if
聲明:
set_target_properties(${the_module} PROPERTIES OUTPUT_NAME "${the_module}${OPENCV_DLLVERSION}" DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" COMPILE_PDB_NAME "${the_module}${OPENCV_DLLVERSION}" COMPILE_PDB_NAME_DEBUG "${the_module}${OPENCV_DLLVERSION}${OPENCV_DEBUG_POSTFIX}" ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH} COMPILE_PDB_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH} LIBRARY_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH} RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} if(NOT ${CMAKE_INSTALL_PREFIX} STREQUAL "/usr/local") ## <--- this always evaluates to FALSE INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib endif() )
我還沒有發現,將導致if
語句來計算,以true
任何語法。有沒有辦法讓CMake根據CMAKE_INSTALL_PREFIX
的內容有條件設置INSTALL_NAME_DIR
?