我正在尝试在OS X下的不同目录中同时安装标准OpenCV作为自定义版本。这样做,我发现OpenCV CMake导致链接失败,当库安装到非 - 标准路径(即/ usr / local除外)。我能够通过在OpenCVModule.cmake
添加一行来解决这个问题:
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根据INSTALL_NAME_DIR
的内容有条件地设置CMAKE_INSTALL_PREFIX
?
答案 0 :(得分:0)
无法嵌套CMake命令:没有语法。但你可以在&#34;下执行任何命令;如果&#34;分支:
if(NOT CMAKE_INSTALL_PREFIX STREQUAL "/usr/local")
set_target_properties(${the_module} PROPERTIES
INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib
)
endif()
另请注意,比较变量值的首选方法&#34;如果&#34;子句是使用变量的名称,而不是解除引用它。 CMake将确定具有此名称的变量存在并自动取消引用它。 documentation中针对&#34;如果&#34;描述了这种行为。命令。