MantisBT - CMake
View Issue Details
0016053CMakeCMakepublic2016-04-07 11:262016-06-10 14:21
Guillaume Dumont 
 
normalminoralways
closedno change required 
WindowsWindows10
CMake 3.5 
 
0016053: $<SHELL_PATH:...> should return a short path on Windows when containing spaces
I am trying to build OpenCV from sources using MSVC and the Ninja Generator and I have a failing build because of linker flags added to the target_link_libraries. OpenCV's CMakeLists.txt uses this line of CMake code:

set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} -L${p})

OPENCV_LINKER_LIBS is passed to target_link_libraries afterwards. The problem with this line is that it does not work on Windows with the Ninja generator. I tried:

set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${CMAKE_LIBRARY_PATH_FLAG}$<SHELL_PATH:${p}>)

but that does not work either because the even though we end up using /LIBPATH: instead of /L and backslashes instead of forward slashes the path contains spaces and ninja throws a link error.

Shouldn't SHELL_PATH return a short path, or a path between quotes when the path contains spaces on Windows?
Try to build OpenCV 3.1.0 on Windows with Ninja.
See OpenCV issue: https://github.com/Itseez/opencv/issues/6372 [^]
No tags attached.
Issue History
2016-04-07 11:26Guillaume DumontNew Issue
2016-04-07 11:46Brad KingNote Added: 0040823
2016-04-07 11:46Brad KingStatusnew => resolved
2016-04-07 11:46Brad KingResolutionopen => no change required
2016-04-07 12:18Guillaume DumontNote Added: 0040824
2016-04-07 14:25Brad KingNote Added: 0040825
2016-06-10 14:21Kitware RobotNote Added: 0041199
2016-06-10 14:21Kitware RobotStatusresolved => closed

Notes
(0040823)
Brad King   
2016-04-07 11:46   
The purpose of SHELL_PATH is to convert drive letters and slashes. It is not to produce a fully quoted/escaped/etc. path for use on a command line. Typically it is used in a context that has proper escaping done later. Flags given to target_link_libraries is not such a context (for historical reasons).

I'm not familiar with OpenCV's use case but there must be another solution. The -L option is for link directories, and we already have a command for that. CMake encourages use of full paths to libraries so linker search directories are rarely needed.
(0040824)
Guillaume Dumont   
2016-04-07 12:18   
Thanks for answering. I understand that SHELL_PATH was not intended for this use case.

I think OpenCV's use case is to avoid having dependencies to CUDA libraries as an absolute path in the exported targets file so that the package remains relocatable. I assuming that since they extract the libraries name for the paths returned by FindCuda.cmake and add their directory to the link_directories command.

I guess the recommended way would be to export the library names with the full path to libraries. But this is sub-optimal since the package could be relocated anymore?

Or, convert CUDA libraries to imported targets and distribute an appropriately modified FindCuda module with the package?
(0040825)
Brad King   
2016-04-07 14:25   
Re 0016053:0040824: Yes, having imported target names as the exported dependencies is a good approach. Of course it is up to their package configuration file to ensure that the imported targets are again made available in the client configuration.
(0041199)
Kitware Robot   
2016-06-10 14:21   
This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.