[CMake] Visual Studio 2010 generator broke?

J Decker d3ck0r at gmail.com
Sat Sep 25 14:59:32 EDT 2010


I only can test 2010, might be all for all I know...

I have a directory that contains a source.  That source, is used by
multiple targets, some static executables, some dynamic libraries, and
a executable linked to a dynamic library.  They all do the same job;
they just don't all link the same way.

Should I handle this by creating 3 folders in that project each with
its own CMakeLists.txt, to build the three targets, or can I just make
3 projects in a single CMakeFile.txt in the directory?

The reason I ask is one way will work right now, with all code
generators, the other way will not.

Using the MinGW Makefiles generator, either way works just fine...
because .obj files of sources in the current directory are put into
${CMAKE_PROJECT_DIR}/CMakeFiles/${PROJECT_NAME}.dir/<file>.obj
and files that are from sources outside of this are put into
${CMAKE_PROJECT_DIR}/CMakeFiles/${PROJECT_NAME}.dir/(other file's path
substituting _ for .)/<file>.obj

(../../netlib/network.c == __/__/netlib/network.c.obj )

Using the Visual Studio 2010 generator .obj files of sources which are
not in the current directory are put into
${CMAKE_PROJECT_DIR}/Debug/<file.obj>
and files that are from sources outside of this are put into
${CMAKE_PROJECT_DIR}/CMakeFiles/${PROJECT_NAME}.dir/Debug/<file>.obj

This would be fine, but since all Project()s use the same path
'${CMAKE_PROJECT_DIR}/Debug/<file.obj>' depending on the build order
it will build or not, and a clean build of any said project will get
it to build.


I can make some subdirectories which will ensure that the same common
source is in a different subdirectory of the build output.


More information about the CMake mailing list