2016-06-08 81 views
0

我試圖在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

回答

0

CMake命令不能嵌套:沒有這種語法。但是,你可以在「如果」分支執行任何命令:

​​

還要注意,在比較變量的值是首選的方式,「如果」條款是使用變量的名稱,而不是取消引用它。 CMake將確定具有該名稱的變量存在並自動對其進行解引用。 「if」命令在documentation中描述了此行爲。

相關問題