Re: [CMake] Settings different flags in sub projects

2014-08-03 Thread Magnus Therning
On Sun, Aug 03, 2014 at 05:46:40PM -0500, David Zemon wrote:
> Hello,
> 
> For the simple case of three directories and two projects - /root, /root/p1,
> and /root/p2 - I would like to set some common flags for both projects and
> then other flags should be independent. For instance, p1 should be compiled
> with "-std=c99 -Os" and p2 should be compiled with "-std=c99 -O1". The first
> flag, -std=c99, is common to all projects and the second, -Os, might be
> changed from project to project. How do I do this?
> 
> I thought I could create MyRulesOverride.cmake with the content:
> 
>set(CMAKE_C_FLAGS_INIT "-std=c99")
> 
> And that would be the end of it, but apparently not. The CMakeLists.txt
> files in each project have a line such as " set(CMAKE_C_FLAGS "-Os")" which
> is apparently overwriting the cached value from CMakeCInformation.cmake. I
> can't write a line like "set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Os")" because
> then the result is "-std=c99 -std=c99 -Os" for the second project.
> 
> Any help would be greatly appreciated.

I haven't tested this, but would you have to *add* to the flag?  AFAIU
setting always over writes the previous value.

/M

-- 
Magnus Therning  OpenPGP: 0xAB4DFBA4 
email: mag...@therning.org   jabber: mag...@therning.org
twitter: magthe   http://therning.org/magnus

The results point out the fragility of programmer expertise: advanced
programmers have strong expectations about what programs should look like,
and when those expectations are violated--in seemingly innocuous
ways--their performance drops drastically.
 -- Elliot Soloway and Kate Ehrlich


pgpQosC5nlS6D.pgp
Description: PGP signature
-- 

Powered by www.kitware.com

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

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

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

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

[CMake] Settings different flags in sub projects

2014-08-03 Thread David Zemon

Hello,

For the simple case of three directories and two projects - /root, 
/root/p1, and /root/p2 - I would like to set some common flags for both 
projects and then other flags should be independent. For instance, p1 
should be compiled with "-std=c99 -Os" and p2 should be compiled with 
"-std=c99 -O1". The first flag, -std=c99, is common to all projects and 
the second, -Os, might be changed from project to project. How do I do this?


I thought I could create MyRulesOverride.cmake with the content:

   set(CMAKE_C_FLAGS_INIT "-std=c99")

And that would be the end of it, but apparently not. The CMakeLists.txt 
files in each project have a line such as " set(CMAKE_C_FLAGS "-Os")" 
which is apparently overwriting the cached value from 
CMakeCInformation.cmake. I can't write a line like "set(CMAKE_C_FLAGS 
"${CMAKE_C_FLAGS} -Os")" because then the result is "-std=c99 -std=c99 
-Os" for the second project.


Any help would be greatly appreciated.

David
-- 

Powered by www.kitware.com

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

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

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

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Re: [CMake] Spaces in a command

2014-08-03 Thread Glenn Coombs
Not for me it doesn't:

$ make VERBOSE=yes
/usr/bin/cmake -H/home/glenn/src/cmake-test
-B/home/glenn/src/cmake-test/build --check-build-system
CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start
/home/glenn/src/cmake-test/build/CMakeFiles
/home/glenn/src/cmake-test/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/home/glenn/src/cmake-test/build'
make -f CMakeFiles/do-foo.dir/build.make CMakeFiles/do-foo.dir/depend
make[2]: Entering directory `/home/glenn/src/cmake-test/build'
cd /home/glenn/src/cmake-test/build && /usr/bin/cmake -E cmake_depends
"Unix Makefiles" /home/glenn/src/cmake-test /home/glenn/src/cmake-test
/home/glenn/src/cmake-test/build /home/glenn/src/cmake-test/build
/home/glenn/src/cmake-test/build/CMakeFiles/do-foo.dir/DependInfo.cmake
--color=
make[2]: Leaving directory `/home/glenn/src/cmake-test/build'
make -f CMakeFiles/do-foo.dir/build.make CMakeFiles/do-foo.dir/build
make[2]: Entering directory `/home/glenn/src/cmake-test/build'
/usr/bin/cmake -E cmake_progress_report
/home/glenn/src/cmake-test/build/CMakeFiles 1

[100%] Generating foo
generate-foo || echo \"no big deal\"

make[2]: Leaving directory `/home/glenn/src/cmake-test/build'
/usr/bin/cmake -E cmake_progress_report
/home/glenn/src/cmake-test/build/CMakeFiles  1
[100%] Built target do-foo
make[1]: Leaving directory `/home/glenn/src/cmake-test/build'
/usr/bin/cmake -E cmake_progress_start
/home/glenn/src/cmake-test/build/CMakeFiles 0

I'm seeing the || outside of the double quotes.  This is on Kubuntu 14.10
with cmake 2.8.12.2.

--
Glenn



On 29 July 2014 20:57, Bill Newcomb  wrote:

> On linux, at least, this results in there being double quotes around the
> ||, which causes it to not be interpreted by the shell.
>
> B.
>
>
> On 07/29/2014 12:25 PM, Glenn Coombs wrote:
>
>> I think this works like you want:
>>
>> cmake_minimum_required(VERSION 2.6)
>>
>> set(DO_RELAX 1)
>> if(DO_RELAX)
>>  set(OR_RELAX || echo \"no big deal\")
>> else()
>>  set(OR_RELAX)
>> endif()
>>
>> add_custom_command(OUTPUT foo COMMAND generate-foo ${OR_RELAX} VERBATIM)
>> add_custom_target(do-foo ALL DEPENDS foo)
>>
>>
>> --
>> Glenn
>>
>>
>> On 29 July 2014 19:19, J Decker > > wrote:
>>
>> can try removing the quotes and subst space for semicolon?
>>
>>
>> On Tue, Jul 29, 2014 at 11:13 AM, Bill Newcomb > > wrote:
>>
>> That doesn't work either:
>>
>> foo:
>>  $(CMAKE_COMMAND) -E cmake_progress_report
>> /home/bnewcomb/tmp/cmake-tests/custom-or/CMakeFiles
>> $(CMAKE_PROGRESS_1)
>>  @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR)
>> --blue --bold "Generating foo"
>>  generate-foo "|| echo \"no big deal\""
>>
>> The whole string gets passed as the first argument to
>> generate-foo.
>>
>> B.
>>
>> On 07/25/2014 09:43 AM, Iosif Neitzke wrote:
>>  > "If VERBATIM is given then all arguments to the commands will
>> be
>>  > escaped properly for the build tool so that the invoked command
>>  > receives each argument unchanged. Note that one level of
>> escapes is
>>  > still used by the CMake language processor before
>> add_custom_command
>>  > even sees the arguments. Use of VERBATIM is recommended as it
>> enables
>>  > correct behavior. When VERBATIM is not given the behavior is
>> platform
>>  > specific because there is no protection of tool-specific
>> special
>>  > characters."
>>  >
>>  >
>> http://www.cmake.org/cmake/help/v3.0/command/add_custom_
>> command.html
>>  >
>>  > On Fri, Jul 25, 2014 at 11:20 AM, Bill Newcomb
>> mailto:bnewc...@nvidia.com>> wrote:
>>  >> I want to add stuff to a custom command based on some
>> definition:
>>  >>
>>  >> cmake_minimum_required(VERSION 2.6)
>>  >>
>>  >> set(DO_RELAX 1)
>>  >> if(DO_RELAX)
>>  >>  set(OR_RELAX "|| echo \"no big deal\"")
>>  >> else()
>>  >>  set(OR_RELAX "")
>>  >> endif()
>>  >>
>>  >> add_custom_command(OUTPUT foo COMMAND generate-foo
>> ${OR_RELAX})
>>  >> add_custom_target(do-foo ALL DEPENDS foo)
>>  >>
>>  >>
>>  >> However, this produces the following rule in the generated
>> makefile:
>>  >>
>>  >> foo:
>>  >>  $(CMAKE_COMMAND) -E cmake_progress_report
>> /home/bnewcomb/tmp/cmake-tests/custom-or/CMakeFiles
>> $(CMAKE_PROGRESS_1)
>>  >>  @$(CMAKE_COMMAND) -E cmake_echo_color
>> --switch=$(COLOR) --blue --bold "Generating foo"
>>  >>  generate-foo ||\ echo\ "no\ big\ deal"
>>  >>
>>  >> Is there some way I can get cmake to not escape all of the
>> 

Re: [CMake] Defining a function in a macro

2014-08-03 Thread David Cole via CMake

Ouch... my brain hurts...

Another idea would be to write the "generated functions" out to a file, 
and then, after all functions are written to the file, include the file.


Might result in something you can actually look at in an editor (and 
make sense of) without your brain hurting too much, too.


;-)

D


-Original Message-
From: Walter Gray 
To: cmake 
Sent: Fri, Aug 1, 2014 8:32 pm
Subject: [CMake] Defining a function in a macro


Hey List -
Just wanted to put this out there for posterity, and in case anyone 
runs

into the same question I had.  I had a bunch of nearly identical
functions, so I wanted to write a function to define them for me to
reduce code repetition.  The problem I ran into was that if you write

macro(_define_function name)
  function(namespaced_${function_name} ...)
  message(${ARGV} from ${name})
  endfunction()
endmacro()

_define_function(foo)
namespaced_foo("Message")

you actually wind up printing "foo from foo", since all variable
references to a macro are expanded first.  I also couldn't use a
function, since there would be no way to access ${name} from inside the
function (that I'm aware of - please correct me on this if I'm wrong)

The solution I came up with was, if I wanted to reference the 
function's
argv, I would do a double-dereference of a string containing "ARGV" 
like so:


macro(_define_function name)
  function(namespaced_${function_name} ...)
  set(my_argv ARGV)
  message(${${my_argv}} from ${name})
  endfunction()
endmacro()

This produced the correct results.  If any of you know of a cleaner way
to do this, I'd love to hear about it.  If not, have fun writing
functions to write your functions!

As a relatively useless, but I thought entertaining aside:

macro(_define_function name my_argv)
  function(namespaced_${function_name} ...)
  message(${my_argv} from ${name})
  endfunction()
endmacro()
_define_function(foo "\${ARGV}")
namespaced_foo("Message")

The result is "foo Message from foo" because ${my_argv} gets expand to
${ARGV}, which then expands to "foo ${ARGV}".

Thanks!
--

Powered by www.kitware.com

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


Kitware offers various services to support the CMake community. For 
more

information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

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


Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

 
--


Powered by www.kitware.com

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

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

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

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake