[CMake] project() and SLN files

Miguel A. Figueroa-Villanueva miguelf at ieee.org
Fri Jul 3 18:02:09 EDT 2009


On Fri, Jul 3, 2009 at 4:33 PM, Robert Dailey wrote:
> On Fri, Jul 3, 2009 at 3:31 PM, Robert Dailey wrote:
>> On Fri, Jul 3, 2009 at 2:54 PM, James Bigler wrote:
>>> On Wed, Jul 1, 2009 at 4:34 PM, Robert Dailey wrote:
[...]
> Interesting, this seems to work:
> project( foo )
> add_library( foo1 STATIC foo1.cpp )
> add_library( foo2 STATIC foo2.cpp )
> add_library( foo3 STATIC foo3.cpp )
> This creates a solution called "foo.sln" and 3 projects: "foo1.vcproj",
> "foo2.vcproj", "foo3.vcproj". Why does this work? I thought for every
> add_library() there must be 1 call to project(). Since I didn't call
> project() for foo1, foo2, or foo3, I don't know why it's letting me create
> those libraries. Can someone explain this behavior?

There is no place that I have read that indicates that you need more
than one project. In fact, it doesn't make much sense to me to have
more than one cmake project command per directory.

I many times use multiple nested project commands so that in IDEs like
MS Visual Studio I get a solution file for each (of course, each is in
different directories). This allows me to load only a small number of
Visual Studio Projects (*.vcproj), which are created per each CMake
target.

You might be confusing a CMake project with Visual Studio's notion of
a project which would be created for each target as opposed to each
cmake project instruction.

Below is the help, which clearly states what the command is for:

$ cmake --help-command project
cmake version 2.7.20090329
------------------------------------------------------------------------------
SingleItem

  project
       Set a name for the entire project.

         project(<projectname> [languageName1 languageName2 ... ] )

       Sets the name of the project.  Additionally this sets the variables
       <projectName>_BINARY_DIR and <projectName>_SOURCE_DIR to the
       respective values.

       Optionally you can specify which languages your project supports.
       Example languages are CXX (i.e.  C++), C, Fortran, etc.  By default C
       and CXX are enabled.  E.g.  if you do not have a C++ compiler, you can
       disable the check for it by explicitely listing the languages you want
       to support, e.g.  C.  By using the special language "NONE" all checks
       for any language can be disabled.

--Miguel


More information about the CMake mailing list