After a long investigation of my own CMake scripts, I found out that CMake is not able to link with Polly libraries because the exported targets file is not generated correctly in the build directory when CONFIG is not set.
The generated file lib/cmake/polly/PollyExports-all.cmake
set_target_properties(LLVMPolly PROPERTIES IMPORTED_LOCATION_ my_build_dir/lib/LLVMPolly.so) set_target_properties(Polly PROPERTIES IMPORTED_LOCATION_ my_build_dir/lib/libPolly.a)
Please notice the additional underscore at the end of IMPORTED_LOCATION. The generation for install directory works correctly since the generator expression used there adds the underscore and config name only when it's defined. This patch simply adds this missing guard for cmake files generated in the build directory.