Dan Liew
2015-Jun-18 20:39 UTC
[LLVMdev] [CMake] Generated LLVMConfig.cmake and LLVMExports.cmake broken under Visual Studio 2015
Hi, Myself and a colleague of mine are trying to use LLVM's exported targets [1] on trunk and I've noticed that the generated CMake files (LLVMConfig.cmake and LLVMExport.cmake) are broken when trying to use Visual Studio 2015 (using CMake 3.2.1). ## Broken target properties in LLVMExports.cmake LLVM itself builds fine but when our project tries to do ``find_package(LLVM)`` we get the following error message (see [2] for context). ``` -- Looking for LLVM CMake Warning (dev) at C:/Users/me/Documents/halide/llvm-build/share/llvm/cmake/LLVMExports.cmake:232 (set_target_properties): Syntax error in cmake code at C:/Users/me/Documents/halide/llvm-build/share/llvm/cmake/LLVMExports.cmake:233 when parsing string LLVMObject;LLVMSupport;C:\Program Files (x86)\Microsoft Visual Studio 14.0\DIA SDK\lib\diaguids.lib Invalid escape sequence \P Policy CMP0010 is not set: Bad variable reference syntax is an error. Run "cmake --help-policy CMP0010" for policy details. Use the cmake_policy command to set the policy and suppress this warning. Call Stack (most recent call first): c:/Users/me/Documents/halide/llvm-build/share/llvm/cmake/LLVMConfig.cmake:174 (include) CMakeLists.txt:14 (find_package) This warning is for project developers. Use -Wno-dev to suppress it. ``` The issue is the that that generated LLVMExports.cmake file has this in it ``` # Create imported target LLVMDebugInfoPDB add_library(LLVMDebugInfoPDB STATIC IMPORTED) set_target_properties(LLVMDebugInfoPDB PROPERTIES INTERFACE_LINK_LIBRARIES "LLVMObject;LLVMSupport;C:\Program Files (x86)\Microsoft Visual Studio 14.0\DIA SDK\lib\diaguids.lib" ) ``` The problem is that the path to diaguids.lib is a windows path and not a CMake style path so the backslashes get interpreted as escape sequences. I think this is a bug in CMake. @Brad: Do you agree? ## Broken paths in LLVMConfig.cmake This is a minor issue but I'm not sure if this a bug or an artifact of using Visual Studio but some of the paths specified in LLVMConfig.cmake are not real paths because they contain ``$(Configuration)``. ``` set(LLVM_BUILD_LIBRARY_DIR "C:/Users/alexander.APRELEV/Documents/halide/llvm-build/$(Configuration)/lib") ... set(LLVM_TOOLS_BINARY_DIR "C:/Users/alexander.APRELEV/Documents/halide/llvm-build/$(Configuration)/bin") ``` The problem is that I was trying to check if ${LLVM_TOOLS_BINARY_DIR}/clang${CMAKE_EXECUTABLE_SUFFIX} exists at configure time (which works on OSX and Linux) but this fails when using Visual Studio because ``$(Configuration)`` is in the path. Is this intentional? [1] http://llvm.org/docs/CMake.html#embedding-llvm-in-your-project [2] https://github.com/halide/Halide/pull/825 Thanks, Dan.
Dan Liew
2015-Jun-18 22:46 UTC
[LLVMdev] [CMake] Generated LLVMConfig.cmake and LLVMExports.cmake broken under Visual Studio 2015
> I think this is a bug in CMake. > > @Brad: Do you agree? > >Hmm actually this might be a bug in the ``/lib/DebugInfo/PDB/CMakeLists.txt`` file. CC'ing Zach Turner seeing as he appears to be the author. I have an untested patch to the CMakeLists.txt that **might** fix the broken LLVMExports.cmake file I'm seeing I'm seeing but unfortunately I can't test it right now as I don't have access to a Visual Studio box right now. Anyone feel like testing it? -------------- next part -------------- A non-text attachment was scrubbed... Name: libpdb_additional_libraries_cmake_path.patch Type: text/x-patch Size: 552 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150618/f7e9d729/attachment.bin>
Brad King
2015-Jun-19 12:41 UTC
[LLVMdev] [CMake] Generated LLVMConfig.cmake and LLVMExports.cmake broken under Visual Studio 2015
On 06/18/2015 06:46 PM, Dan Liew wrote:>> The issue is the that that generated LLVMExports.cmake file has this in it >> INTERFACE_LINK_LIBRARIES "LLVMObject;LLVMSupport;C:\Program Files (x86)\Microsoft Visual Studio 14.0\DIA SDK\lib\diaguids.lib" > > Hmm actually this might be a bug in the > ``/lib/DebugInfo/PDB/CMakeLists.txt`` file. CC'ing Zach Turner seeing > as he appears to be the author. > > - set(LIBPDB_ADDITIONAL_LIBRARIES "${LIBPDB_LINK_FOLDERS}\\diaguids.lib") > + file(TO_CMAKE_PATH "${LIBPDB_LINK_FOLDERS}\\diaguids.lib" LIBPDB_ADDITIONAL_LIBRARIES)That should resolve the issue for LLVM with no changes to CMake. However, CMake should also be taught to escape the backslashes correctly when generating the export files. Take a look at Source/cmExportFileGenerator.cxx Source/cmExportBuildFileGenerator.cxx Source/cmExportInstallFileGenerator.cxx in the CMake source tree. There are several places that just generate double quotes around a raw value that should instead use EscapeForCMake. Thanks, -Brad
Maybe Matching Threads
- [LLVMdev] [CMake] Generated LLVMConfig.cmake and LLVMExports.cmake broken under Visual Studio 2015
- llvm 5.0.1 requires downstream workaround for diaguids.lib
- Include all the things
- [LLVMdev] LLVMConfig not found
- [LLVMdev] [cfe-dev] 3.6.2-rc1 has been tagged. Testers needed.