Re: [CMake] Stray backslash appearing when CMAKE_CXX_FLAGS_RELEASE used in custom command

2019-11-03 Thread Eric Doenges

Am 01.11.19 um 17:24 schrieb Stephen Morris:

On 1 November at 10:02, Stephen Morris wrote:


My approach is basically to set up a custom command thus:
set(CXX_FLAGS ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG})   .. or whatever, 
depending on the current configuration..
get_target_property(compile_options, mytarget, COMPILE_OPTIONS) 
add_custom_command(OUTPUT myheader.h.gch
  COMMAND ${CMAKE_CXX_COMPILER} 
${CXX_FLAGS} ${compile_options} -fPIC -std=gnu++17 -c myheader.h -o 
myheader.h.gch
   DEPENDS myheader.h) 
add_custom_target(BuildMyPCH
 DEPENDS myheader.h.gch) 
add_dependencies(mytarget, BuildMyPCH)

My earlier question still stands, but at the time I wrote it I had only tested 
it for Debug builds where ${CMAKE_CXX_FLAGS_DEBUG} consisted of a single item, 
'-g'.

I've since tried doing the same thing for a Release build, and this failed because 
${CMAKE_CXX_FLAGS_RELEASE} has two items, '-O3 -DNDEBUG'. When the custom command is 
executed, this somehow becomes "-O3\ -DNDEBUG" on the command line, and the 
presence of the stray backslash causes the compilation to fail with the message,

"cc1plus: error: argument to '-O' should be a non-negative integer. 'g', 's' or 
'fast'"

So why isn't the cmake variable placed properly onto the command line, and what 
can I do to prevent this behaviour?


Welcome to the wonderful world of lists and their interaction with 
quoting in CMake ! Since space is used as a list item separator outside 
of double quoted strings, CMake is escaping the space within CXX_FLAGS 
to keep it as a single element within the list of arguments passed to 
add_custom_command. To avoid this, you need to turn CXX_FLAGS into a 
list prior to using it in add_custom_command:


string(REGEX REPLACE " " ";" CXX_FLAGS "${CXX_FLAGS}")

Of course, this will not work if you want to pass a double quoted string 
as an actual command line argument ...


--

*Dr. Eric Dönges*
Senior Software Engineer

MVTec Software GmbH | Arnulfstr. 205 | 80634 Munich | Germany
doen...@mvtec.com  | Tel: +49 89 457 695-0 
| www.mvtec.com 


Find our privacy policy here .

Sign up  for our MVTec Newsletter!

Geschäftsführer: Dr. Wolfgang Eckstein, Dr. Olaf Munkelt
Amtsgericht München HRB 114695

MVTec Software GmbH Logo
-- 

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:
https://cmake.org/mailman/listinfo/cmake


Re: [CMake] Accessing -fPIC and -std settings within CMake definitions

2019-11-03 Thread Eric Doenges

Am 01.11.19 um 11:02 schrieb Stephen Morris:

I'm setting up a custom build step to build a precompiled header in gcc (yes I 
know that native support is coming with CMake 3.16, but I need to get something 
working on an older version).

My approach is basically to set up a custom command thus:

set_target_properties(mytarget PRIVATE CXX_STANDARD 17)
set_target_properties(mytarget PRIVATE  POSITION_INDEPENDENT CODE_1)
set(CMAKE_VERBOSE_MAKEFILE TRUE)
...
...
set(CXX_FLAGS ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG})   .. or whatever, 
depending on the current configuration..
get_target_property(compile_options, mytarget, COMPILE_OPTIONS)
add_custom_command(OUTPUT myheader.h.gch
COMMAND ${CMAKE_CXX_COMPILER} 
${CXX_FLAGS} ${compile_options} -fPIC -std=gnu++17 -c myheader.h -o 
myheader.h.gch
DEPENDS myheader.h)
add_custom_target(BuildMyPCH
  DEPENDS myheader.h.gch)
add_dependencies(mytarget, BuildMyPCH)

You'll note that in my custom command I've had to specify -fPIC and 
-std-gnu++17 explicitly, because they aren't included among either CXX_FLAGS or 
COMPILE_OPTIONS. I've looked for them among the  COMPILE_DEFINITIONS, 
COMPILE_FEATURES and COMPILE_FLAGS properties of my target as well, but there's 
no sign of them. And yet if I look at the verbose output when gcc builds other 
files using the CMake-generated makefile, I see that they are being included 
automatically.

So, my question: where is CMake storing these settings, and how can I apply 
them in my custom command without having to do so manually?


As far as I am aware, there is no way of querying the entirety of the 
command line arguments applied by CMake - you will need to recreate 
CMake's behavior manually. In case of -fPIC, this could look like this 
(not tested, so there may be syntax errors, but the principle should work):


...
get_target_property(_tmp mytarget POSITION_INDEPENDENT_CODE)
if(_tmp AND CMAKE_CXX_COMPILE_OPTIONS_PIC)
  string(APPEND CXX_FLAGS " ${CMAKE_CXX_COMPILE_OPTIONS_PIC}")
endif()
...

If you have multiple targets that may have different compile options you 
will probably want to put this in a function that takes a target as 
input and returns the compiler flags as output.


To figure out the names of the variables CMake uses to hold flags to 
pass to the compiler, search the <...>/share/cmake-3.xx/Modules/Compiler 
directory.


--

*Dr. Eric Dönges*
Senior Software Engineer

MVTec Software GmbH | Arnulfstr. 205 | 80634 Munich | Germany
doen...@mvtec.com  | Tel: +49 89 457 695-0 
| www.mvtec.com 


Find our privacy policy here .

Sign up  for our MVTec Newsletter!

Geschäftsführer: Dr. Wolfgang Eckstein, Dr. Olaf Munkelt
Amtsgericht München HRB 114695

MVTec Software GmbH Logo
-- 

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:
https://cmake.org/mailman/listinfo/cmake


[Cmake-commits] CMake branch, master, updated. v3.16.0-rc3-184-ge3afdef8c5

2019-11-03 Thread Kitware Robot via Cmake-commits
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, master has been updated
   via  e3afdef8c567880d7c83ca5980e4c5f5d289880c (commit)
  from  402c06974648ac215945e0e9bf55e7d04f8e60a5 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -
https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=e3afdef8c567880d7c83ca5980e4c5f5d289880c
commit e3afdef8c567880d7c83ca5980e4c5f5d289880c
Author: Kitware Robot 
AuthorDate: Mon Nov 4 00:01:09 2019 -0500
Commit: Kitware Robot 
CommitDate: Mon Nov 4 00:01:09 2019 -0500

CMake Nightly Date Stamp

diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake
index 3c4a4642de..ad42756770 100644
--- a/Source/CMakeVersion.cmake
+++ b/Source/CMakeVersion.cmake
@@ -1,7 +1,7 @@
 # CMake version number components.
 set(CMake_VERSION_MAJOR 3)
 set(CMake_VERSION_MINOR 16)
-set(CMake_VERSION_PATCH 20191103)
+set(CMake_VERSION_PATCH 20191104)
 #set(CMake_VERSION_RC 0)
 set(CMake_VERSION_IS_DIRTY 0)
 

---

Summary of changes:
 Source/CMakeVersion.cmake | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


hooks/post-receive
-- 
CMake
___
Cmake-commits mailing list
Cmake-commits@cmake.org
https://cmake.org/mailman/listinfo/cmake-commits


[Cmake-commits] CMake branch, release, updated. v3.16.0-rc3-6-gd0681fda11

2019-11-03 Thread Kitware Robot via Cmake-commits
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, release has been updated
   via  d0681fda117505b6508fa2c6e291237bbf7a0a83 (commit)
   via  2490c1df74000c340afeab55159aa362f268b10b (commit)
   via  23752d5bad631e7948796281f3c7548bbec80fd4 (commit)
   via  ad024439f50f79f76b10b31f1c1a3e5f73f09462 (commit)
  from  91c26b3d387ffd4948ecde38ab2c5f894b7dbe8c (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -
---

Summary of changes:
 Help/command/file.rst | 20 ++--
 Help/command/list.rst |  2 +-
 2 files changed, 11 insertions(+), 11 deletions(-)


hooks/post-receive
-- 
CMake
___
Cmake-commits mailing list
Cmake-commits@cmake.org
https://cmake.org/mailman/listinfo/cmake-commits


[Cmake-commits] CMake branch, master, updated. v3.16.0-rc3-183-g402c069746

2019-11-03 Thread Kitware Robot via Cmake-commits
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, master has been updated
   via  402c06974648ac215945e0e9bf55e7d04f8e60a5 (commit)
   via  d0681fda117505b6508fa2c6e291237bbf7a0a83 (commit)
   via  2490c1df74000c340afeab55159aa362f268b10b (commit)
  from  83badd91bff023b60c40a09a6761957ab50cfc90 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -
https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=402c06974648ac215945e0e9bf55e7d04f8e60a5
commit 402c06974648ac215945e0e9bf55e7d04f8e60a5
Merge: 83badd91bf d0681fda11
Author: Craig Scott 
AuthorDate: Mon Nov 4 09:43:22 2019 +1100
Commit: Craig Scott 
CommitDate: Mon Nov 4 09:43:22 2019 +1100

Merge branch 'release-3.16'


---

Summary of changes:


hooks/post-receive
-- 
CMake
___
Cmake-commits mailing list
Cmake-commits@cmake.org
https://cmake.org/mailman/listinfo/cmake-commits


[Cmake-commits] CMake branch, master, updated. v3.16.0-rc3-180-g83badd91bf

2019-11-03 Thread Kitware Robot via Cmake-commits
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, master has been updated
   via  83badd91bff023b60c40a09a6761957ab50cfc90 (commit)
   via  3c8dab73cb01285da589b033b31b76623a74520c (commit)
   via  23752d5bad631e7948796281f3c7548bbec80fd4 (commit)
   via  ad024439f50f79f76b10b31f1c1a3e5f73f09462 (commit)
  from  0fb4e0ad15540e782b4baa7117e8db30c8afe640 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -
https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=83badd91bff023b60c40a09a6761957ab50cfc90
commit 83badd91bff023b60c40a09a6761957ab50cfc90
Merge: 3c8dab73cb 23752d5bad
Author: Craig Scott 
AuthorDate: Sun Nov 3 22:40:23 2019 +
Commit: Kitware Robot 
CommitDate: Sun Nov 3 17:40:32 2019 -0500

Merge topic 'docs-file-GET_RUNTIME_DEPENDENCIES'

23752d5bad Help: Typo and grammar fixes for file(GET_RUNTIME_DEPENDENCIES)

Acked-by: Kitware Robot 
Merge-request: !3982


https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=3c8dab73cb01285da589b033b31b76623a74520c
commit 3c8dab73cb01285da589b033b31b76623a74520c
Merge: 0fb4e0ad15 ad024439f5
Author: Craig Scott 
AuthorDate: Sun Nov 3 22:35:07 2019 +
Commit: Kitware Robot 
CommitDate: Sun Nov 3 17:35:16 2019 -0500

Merge topic 'docs-list-remove_item'

ad024439f5 Help: list(REMOVE_ITEM) removes all instances, not just the 
first found

Acked-by: Kitware Robot 
Merge-request: !3977


https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=23752d5bad631e7948796281f3c7548bbec80fd4
commit 23752d5bad631e7948796281f3c7548bbec80fd4
Author: Craig Scott 
AuthorDate: Sun Nov 3 22:44:36 2019 +1100
Commit: Craig Scott 
CommitDate: Sun Nov 3 22:44:36 2019 +1100

Help: Typo and grammar fixes for file(GET_RUNTIME_DEPENDENCIES)

Note that ``MODULE`` s was rendering strangely, so the wording
has been tweaked to avoid needing to specify ``MODULE`` as a
plural word. Modules are still libraries, so it is okay to call them as
such where it doesn't cause any ambiguity.

diff --git a/Help/command/file.rst b/Help/command/file.rst
index 83e451636f..b186177eb6 100644
--- a/Help/command/file.rst
+++ b/Help/command/file.rst
@@ -187,14 +187,14 @@ The arguments are as follows:
   are typically created with :command:`add_executable`, but they do not have to
   be created by CMake. On Apple platforms, the paths to these files determine
   the value of ``@executable_path`` when recursively resolving the libraries.
-  Specifying ``STATIC`` libraries, ``MODULE`` s, or ``SHARED`` libraries here
+  Specifying any kind of library (``STATIC``, ``MODULE``, or ``SHARED``) here
   will result in undefined behavior.
 
 ``LIBRARIES ``
   List of library files to read for dependencies. These are libraries that are
   typically created with :command:`add_library(SHARED)`, but they do not have
-  to be created by CMake. Specifying ``STATIC`` libraries, ``MODULE`` s, or
-  executables here will result in undefined behavior.
+  to be created by CMake. Specifying ``STATIC`` libraries, ``MODULE``
+  libraries, or executables here will result in undefined behavior.
 
 ``MODULES ``
   List of loadable module files to read for dependencies. These are modules
@@ -209,13 +209,13 @@ The arguments are as follows:
   platforms, these directories are searched if the dependency is not found in
   any of the other usual paths. If it is found in such a directory, a warning
   is issued, because it means that the file is incomplete (it does not list all
-  of the directories that contain its dependencies.) On Windows platforms,
+  of the directories that contain its dependencies). On Windows platforms,
   these directories are searched if the dependency is not found in any of the
   other search paths, but no warning is issued, because searching other paths
   is a normal part of Windows dependency resolution. On Apple platforms, this
   argument has no effect.
 
-``BUNDLE_EXECTUBLE ``
+``BUNDLE_EXECUTABLE ``
   Executable to treat as the "bundle executable" when resolving libraries. On
   Apple platforms, this argument determines the value of ``@executable_path``
   when recursively resolving libraries for ``LIBRARIES`` and ``MODULES`` files.
@@ -284,7 +284,7 @@ On Linux platforms, library resolution works as follows:
dependency is resolved to that file. In this case, a warning is issued,
because finding a file in one of the ``DIRECTORIES`` means that the
depending file is not complete (it does not list all the directories from
-   which it pulls dependencies.)
+   which it pulls dependencies).
 5. Otherwise, the dependency is unresolved.
 
 On Windows platforms, library resolution works as