MantisBT - CMake
View Issue Details
0011793CMakeCMakepublic2011-02-03 11:102014-06-02 08:37
Peter Kuemmel 
Peter Kuemmel 
normalfeaturealways
closedwon't fix 
All platforms
 
 
0011793: namespace support
Several commands have the directory as scope,
for instance add_definitions:

add_definitions(-DX)
add_library(X x.cpp)
add_library(antiX antiX.cpp)

When antiX.cpp doesn't compile with the definition X set
then it is not possible to write such a cmake file.

Support of namespace could fix this:

namespace(x)
  add_definitions(-DX)
  add_library(X x.cpp)
endnamespace()
add_library/antiX antiX.cpp)


Attached a patch which adds this feature.

The only critical part is the usage of the new
member variables current*, otherwise not using
namespace() is 100% backward compatible when no
variable with that name is used.



No tags attached.
patch namespace.patch (33,452) 2011-02-03 11:10
https://public.kitware.com/Bug/file/3672/namespace.patch
patch namespace-2.patch (33,457) 2011-02-03 11:43
https://public.kitware.com/Bug/file/3673/namespace-2.patch
Issue History
2011-02-03 11:10Peter KuemmelNew Issue
2011-02-03 11:10Peter KuemmelFile Added: namespace.patch
2011-02-03 11:43Peter KuemmelFile Added: namespace-2.patch
2011-02-03 11:44Peter KuemmelNote Added: 0025236
2011-02-03 13:50Brad KingNote Added: 0025247
2011-02-03 15:48Peter KuemmelNote Added: 0025252
2011-02-03 15:56Brad KingNote Added: 0025253
2011-02-03 16:08Peter KuemmelNote Added: 0025254
2012-08-11 11:09David ColeStatusnew => backlog
2012-08-11 11:09David ColeNote Added: 0030228
2012-08-13 08:40Peter KuemmelAssigned To => Peter Kuemmel
2012-08-13 08:40Peter KuemmelStatusbacklog => assigned
2012-08-13 08:41Peter KuemmelNote Added: 0030467
2012-08-13 08:41Peter KuemmelStatusassigned => backlog
2012-08-27 07:04Stephen KellyNote Added: 0030773
2013-11-02 09:45Stephen KellyNote Added: 0034318
2013-11-02 09:45Stephen KellyStatusbacklog => resolved
2013-11-02 09:45Stephen KellyResolutionopen => fixed
2013-11-03 02:44Peter KuemmelNote Added: 0034337
2013-11-03 02:44Peter KuemmelStatusresolved => feedback
2013-11-03 02:44Peter KuemmelResolutionfixed => reopened
2013-11-03 02:45Peter KuemmelStatusfeedback => resolved
2013-11-03 02:45Peter KuemmelResolutionreopened => won't fix
2014-06-02 08:37Robert MaynardNote Added: 0035996
2014-06-02 08:37Robert MaynardStatusresolved => closed

Notes
(0025236)
Peter Kuemmel   
2011-02-03 11:44   
namespace.patch is buggy use namespace-2.patch.
(0025247)
Brad King   
2011-02-03 13:50   
Instead of

add_definitions(-DX)
add_library(X x.cpp)
add_library(antiX antiX.cpp)

use

add_library(X x.cpp)
set_property(TARGET X PROPERTY COMPILE_DEFINITIONS X)
add_library(antiX antiX.cpp)
(0025252)
Peter Kuemmel   
2011-02-03 15:48   
> set_property(TARGET X PROPERTY COMPILE_DEFINITIONS X)
add_definitions was an example only.

What about include_directories? Even adding a
INCLUDE_DIRECTORIES property wouldn't do the same:

set(x x1)
message(STATUS "x = ${x}")
namespace(nx)
    set(x x2)
    message(STATUS "x = ${x}")
endnamespace()
message(STATUS "x = ${x}")

Output:
-- x = x1
-- x = x2
-- x = x1


The patch isn't perfect, it's a proposal to see
if there is any chance to get it upstream.

E.g.'namespace' as command name is misleading because
entering the namespace again wouldn't make previously
settings available. A better name must be found.

And cmMakefile::AddNamespace could be merged with
cmMakefile::AddSubDirectory.
(0025253)
Brad King   
2011-02-03 15:56   
Why not just organize your project with an actual subdirectory? I think the scoping rules are complicated enough.
(0025254)
Peter Kuemmel   
2011-02-03 16:08   
I already have subdirectories but I find it much more
elegant and simpler to maintain if I could write all
the identical build rules in one file.

And the scoping rule are so complicated that I (as normal
user) only know that all the settings done in a subdirectory
are only visible in this directory or below.

Adding something like namespace would simplify the scoping rules
because everybody understands the concept of namespaces.
(0030228)
David Cole   
2012-08-11 11:09   
Sending old, never assigned issues to the backlog.

(The age of the bug, plus the fact that it's never been assigned to anyone means that nobody is actively working on it...)

If an issue you care about is sent to the backlog when you feel it should have been addressed in a different manner, please bring it up on the CMake mailing list for discussion. Sign up for the mailing list here, if you're not already on it: http://www.cmake.org/mailman/listinfo/cmake [^]

It's easy to re-activate a bug here if you can find a CMake developer who has the bandwidth to take it on, and ferry a fix through to our 'next' branch for dashboard testing.
(0030467)
Peter Kuemmel   
2012-08-13 08:41   
postpone
(0030773)
Stephen Kelly   
2012-08-27 07:04   
Is this still needed? We have target-scoped include directories since CMake 2.8.8. Are there other commands where directory-scoping is a problem but there is no target-scoped property? We can fill those gaps.
(0034318)
Stephen Kelly   
2013-11-02 09:45   
We have target_compile_options, target_compile_definitions, and target_include_directories now. I'm sure this is not needed.
(0034337)
Peter Kuemmel   
2013-11-03 02:44   
I still like this feature.
Especially when using only one CMake file for several directories the namespace is very comfortable, for instance just use add_definitions() like before.

But it seems all love it to pollute the directory tree CMakeLists.txt file.

So the status is "won't fix", or similar, decided by others.
(0035996)
Robert Maynard   
2014-06-02 08:37   
Closing resolved issues that have not been updated in more than 4 months.