[cmake-developers] CMAKE_CURRENT_SOURCE_DIR points to build dir at build time
Paul Cercueil
paul.cercueil at analog.com
Fri May 15 05:09:42 EDT 2015
Hi,
I'm facing a strange issue with CMake 3.2.2 when building with Visual
Studio.
This code snippet shows the problem:
--
set(CS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/MyLib.cs
${CMAKE_CURRENT_SOURCE_DIR}/AssemblyInfo.cs)
add_custom_command(OUTPUT mylib.dll
COMMAND mcs /target:library /out:mylib.dll /debug
/keyfile:${CMAKE_CURRENT_SOURCE_DIR}/key.snk ${CS_SOURCES})
--
This will generate and build fine under Linux, using both Makefile or
Ninja generators.
Under Windows, it will generate fine but Visual Studio will fail to
build, stating that the "C:\build\Mylib.cs" and
"C:\build\AssemblyInfo.cs" files cannot be found (source dir is
"C:\src"). This indicates that it is in fact trying to find those files
in the build directory, instead of the source directory.
This seems to happen only at the building step; at the generation step,
${CMAKE_CURRENT_SOURCE_DIR} correctly points to "C:\src".
For a real-world example, this issue happens when compiling the libiio
library with the C# bindings: http://github.com/analogdevicesinc/libiio.git
My current workaround is to copy the source files to the build directory:
https://gist.github.com/pcercuei/380550a3205c91f15b82
--
--
Analog Devices GmbH Wilhelm-Wagenfeld-Str. 6 80807 Muenchen
Sitz der Gesellschaft: Muenchen; Registergericht: Muenchen HRB 40368;
Geschaeftsfuehrer:Dr.Carsten Suckrow, William A. Martin, Margaret Seif
More information about the cmake-developers
mailing list