Make project name a target

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Make project name a target

Marcel Loose
Hi all,

I was wondering whether it's a good idea to make the project name (i.e.
the argument to the 'project' command) a target.

Rationale: I have a project that consists of numerous sub-projects and I
would like to be able to build some of these separately. Wrapping the
'project' command in a macro is not a solution, because AFAIK CMake
*must* see a 'project' command in the top-level CMakeLists.txt file; a
'myproject' macro, wrapping the 'project' command, will not do.

Any comments?

Best regards,
Marcel Loose.


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Make project name a target

David Cole
When you say "make the project name a target" what do you mean by that?

(1) internally create a CMake target with the given name?
(2) create a makefile target with that name that builds all the cmake targets in that cmake project?
(3) something else?

(1) is probably not feasible for most folks -- because many people use the same name for their PROJECT statement and the main library or executable for that project.... which is already a cmake target (and a makefile target) with that name.


On Fri, Sep 11, 2009 at 3:51 AM, Marcel Loose <[hidden email]> wrote:
Hi all,

I was wondering whether it's a good idea to make the project name (i.e.
the argument to the 'project' command) a target.

Rationale: I have a project that consists of numerous sub-projects and I
would like to be able to build some of these separately. Wrapping the
'project' command in a macro is not a solution, because AFAIK CMake
*must* see a 'project' command in the top-level CMakeLists.txt file; a
'myproject' macro, wrapping the 'project' command, will not do.

Any comments?

Best regards,
Marcel Loose.


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Make project name a target

Marcel Loose
In reply to this post by Marcel Loose
Hi David,

I don't see the exact difference between (1) and (2). And yes, I was
thinking of using the project name as a target. You are right, that it
might cause clashes with existing projects, though :-(

We use the convention that project names are always capitalized, so we
usually don't run into problems.

Is there a nifty trick to wrap the 'project' command? I never succeeded
in doing that.

Best regards,
Marcel Loose.


On Fri, 2009-09-11 at 07:09 -0400, David Cole wrote:

> When you say "make the project name a target" what do you mean by
> that?
>
>
> (1) internally create a CMake target with the given name?
> (2) create a makefile target with that name that builds all the cmake
> targets in that cmake project?
> (3) something else?
>
>
> (1) is probably not feasible for most folks -- because many people use
> the same name for their PROJECT statement and the main library or
> executable for that project.... which is already a cmake target (and a
> makefile target) with that name.
>
>
>
> On Fri, Sep 11, 2009 at 3:51 AM, Marcel Loose <[hidden email]> wrote:
>         Hi all,
>        
>         I was wondering whether it's a good idea to make the project
>         name (i.e.
>         the argument to the 'project' command) a target.
>        
>         Rationale: I have a project that consists of numerous
>         sub-projects and I
>         would like to be able to build some of these separately.
>         Wrapping the
>         'project' command in a macro is not a solution, because AFAIK
>         CMake
>         *must* see a 'project' command in the top-level CMakeLists.txt
>         file; a
>         'myproject' macro, wrapping the 'project' command, will not
>         do.
>        
>         Any comments?
>        
>         Best regards,
>         Marcel Loose.
>        
>        
>         _______________________________________________
>         Powered by www.kitware.com
>        
>         Visit other Kitware open-source projects at
>         http://www.kitware.com/opensource/opensource.html
>        
>         Please keep messages on-topic and check the CMake FAQ at:
>         http://www.cmake.org/Wiki/CMake_FAQ
>        
>         Follow this link to subscribe/unsubscribe:
>         http://www.cmake.org/mailman/listinfo/cmake
>
>

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Make project name a target

Jeroen Dierckx
On Fri, Sep 11, 2009 at 4:22 PM, Marcel Loose <[hidden email]> wrote:

> Hi David,
>
> I don't see the exact difference between (1) and (2). And yes, I was
> thinking of using the project name as a target. You are right, that it
> might cause clashes with existing projects, though :-(
>
> We use the convention that project names are always capitalized, so we
> usually don't run into problems.
>
> Is there a nifty trick to wrap the 'project' command? I never succeeded
> in doing that.

I did this once inside a macro, and that should work as expected. The
code of the macro should behave just as if it was copy-pasted to the
place where you call the macro, so scope and such will be that of the
place where you call it.

Greetings,
JeDi


>
> Best regards,
> Marcel Loose.
>
>
> On Fri, 2009-09-11 at 07:09 -0400, David Cole wrote:
>> When you say "make the project name a target" what do you mean by
>> that?
>>
>>
>> (1) internally create a CMake target with the given name?
>> (2) create a makefile target with that name that builds all the cmake
>> targets in that cmake project?
>> (3) something else?
>>
>>
>> (1) is probably not feasible for most folks -- because many people use
>> the same name for their PROJECT statement and the main library or
>> executable for that project.... which is already a cmake target (and a
>> makefile target) with that name.
>>
>>
>>
>> On Fri, Sep 11, 2009 at 3:51 AM, Marcel Loose <[hidden email]> wrote:
>>         Hi all,
>>
>>         I was wondering whether it's a good idea to make the project
>>         name (i.e.
>>         the argument to the 'project' command) a target.
>>
>>         Rationale: I have a project that consists of numerous
>>         sub-projects and I
>>         would like to be able to build some of these separately.
>>         Wrapping the
>>         'project' command in a macro is not a solution, because AFAIK
>>         CMake
>>         *must* see a 'project' command in the top-level CMakeLists.txt
>>         file; a
>>         'myproject' macro, wrapping the 'project' command, will not
>>         do.
>>
>>         Any comments?
>>
>>         Best regards,
>>         Marcel Loose.
>>
>>
>>         _______________________________________________
>>         Powered by www.kitware.com
>>
>>         Visit other Kitware open-source projects at
>>         http://www.kitware.com/opensource/opensource.html
>>
>>         Please keep messages on-topic and check the CMake FAQ at:
>>         http://www.cmake.org/Wiki/CMake_FAQ
>>
>>         Follow this link to subscribe/unsubscribe:
>>         http://www.cmake.org/mailman/listinfo/cmake
>>
>>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Make project name a target

Alexander Neundorf-3
In reply to this post by David Cole
On Friday 11 September 2009, David Cole wrote:
> When you say "make the project name a target" what do you mean by that?
> (1) internally create a CMake target with the given name?
> (2) create a makefile target with that name that builds all the cmake
> targets in that cmake project?

I think this should be more or less the same as invoking make without specific
target in <project>_BINARY_DIR.

Alex
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Make project name a target

Marcel Loose
In reply to this post by Jeroen Dierckx
Hi JeDi,

If you look carefully, you will notice that, when you create a project
through a macro (e.g. myproject), CMake will create a dummy project
named "Project" and assume you're using C and C++ as default languages.

Note that I intentionally chose a non-supported language, CPP, in the
example below. Look at the line printing PROJECT_NAME. But you'll notice
a significant difference in output anyway.

Best regards,
Marcel Loose.


CMakeLists.txt with direct call of project() command:
----------------------------------------------------
$ pwd
/home/loose/work/cmake/build

$ cat ../proj/CMakeLists.txt
cmake_minimum_required(VERSION 2.6)
message(STATUS "PROJECT_NAME = ${PROJECT_NAME}")
project(main CPP)

$ cmake -DCMAKE_MODULE_PATH:PATH=$HOME/work/cmake/proj ../proj
-- PROJECT_NAME =
CMake Error: Error required internal CMake variable not set, cmake may
be not be built correctly.
Missing variable is:
CMAKE_CPP_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may
be not be built correctly.
Missing variable is:
CMAKE_CPP_COMPILER
CMake Error: Could not find cmake module
file:/home/loose/work/cmake/build/CMakeFiles/CMakeCPPCompiler.cmake
CMake Error: Could not find cmake module file:CMakeCPPInformation.cmake
CMake Error: CMAKE_CPP_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!


CMakeLists.txt with call of project() through myproject macro:
-------------------------------------------------------------
$ cat CMakeLists.txt
cmake_minimum_required(VERSION 2.6)
message(STATUS "PROJECT_NAME = ${PROJECT_NAME}")
include(myproject)
myproject(main CPP)

$ cmake -DCMAKE_MODULE_PATH:PATH=$HOME/work/cmake/proj ../proj
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- PROJECT_NAME = Project
CMake Error: Error required internal CMake variable not set, cmake may
be not be built correctly.
Missing variable is:
CMAKE_CPP_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may
be not be built correctly.
Missing variable is:
CMAKE_CPP_COMPILER
CMake Error: Could not find cmake module
file:/home/loose/work/cmake/build/CMakeFiles/CMakeCPPCompiler.cmake
CMake Error: Could not find cmake module file:CMakeCPPInformation.cmake
CMake Error: CMAKE_CPP_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!

On Fri, 2009-09-11 at 16:34 +0200, Jeroen Dierckx wrote:

> On Fri, Sep 11, 2009 at 4:22 PM, Marcel Loose <[hidden email]> wrote:
> > Hi David,
> >
> > I don't see the exact difference between (1) and (2). And yes, I was
> > thinking of using the project name as a target. You are right, that it
> > might cause clashes with existing projects, though :-(
> >
> > We use the convention that project names are always capitalized, so we
> > usually don't run into problems.
> >
> > Is there a nifty trick to wrap the 'project' command? I never succeeded
> > in doing that.
>
> I did this once inside a macro, and that should work as expected. The
> code of the macro should behave just as if it was copy-pasted to the
> place where you call the macro, so scope and such will be that of the
> place where you call it.
>
> Greetings,
> JeDi
>
>
> >
> > Best regards,
> > Marcel Loose.
> >
> >
> > On Fri, 2009-09-11 at 07:09 -0400, David Cole wrote:
> >> When you say "make the project name a target" what do you mean by
> >> that?
> >>
> >>
> >> (1) internally create a CMake target with the given name?
> >> (2) create a makefile target with that name that builds all the cmake
> >> targets in that cmake project?
> >> (3) something else?
> >>
> >>
> >> (1) is probably not feasible for most folks -- because many people use
> >> the same name for their PROJECT statement and the main library or
> >> executable for that project.... which is already a cmake target (and a
> >> makefile target) with that name.
> >>
> >>
> >>
> >> On Fri, Sep 11, 2009 at 3:51 AM, Marcel Loose <[hidden email]> wrote:
> >>         Hi all,
> >>
> >>         I was wondering whether it's a good idea to make the project
> >>         name (i.e.
> >>         the argument to the 'project' command) a target.
> >>
> >>         Rationale: I have a project that consists of numerous
> >>         sub-projects and I
> >>         would like to be able to build some of these separately.
> >>         Wrapping the
> >>         'project' command in a macro is not a solution, because AFAIK
> >>         CMake
> >>         *must* see a 'project' command in the top-level CMakeLists.txt
> >>         file; a
> >>         'myproject' macro, wrapping the 'project' command, will not
> >>         do.
> >>
> >>         Any comments?
> >>
> >>         Best regards,
> >>         Marcel Loose.
> >>
> >>
> >>         _______________________________________________
> >>         Powered by www.kitware.com
> >>
> >>         Visit other Kitware open-source projects at
> >>         http://www.kitware.com/opensource/opensource.html
> >>
> >>         Please keep messages on-topic and check the CMake FAQ at:
> >>         http://www.cmake.org/Wiki/CMake_FAQ
> >>
> >>         Follow this link to subscribe/unsubscribe:
> >>         http://www.cmake.org/mailman/listinfo/cmake
> >>
> >>
> >
> > _______________________________________________
> > Powered by www.kitware.com
> >
> > Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
> >
> > Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
> >
> > Follow this link to subscribe/unsubscribe:
> > http://www.cmake.org/mailman/listinfo/cmake
> >

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake