Re: [CMake] LINK_FLAGS directory property

2016-05-02 Thread Attila Krasznahorkay
Hi Matt,

Have you tried using the

CMAKE_EXE_LINKER_FLAGS
CMAKE_SHARED_LINKER_FLAGS
CMAKE_MODULE_LINKER_FLAGS

cache variables? These actually set these flags globally, and not just for one 
directory, but on the directory level they are easy to override. You can just 
do something like this in a subdirectory:

string( REPLACE "-Wl,--as-needed" "" CMAKE_SHARED_LINKER_FLAGS 
"${CMAKE_SHARED_LINKER_FLAGS}" )

Cheers,
Attila

> On 27 Apr 2016, at 17:57, Matthew Keeler  wrote:
> 
> Is there an equivalent directory property for the target level LINK_FLAGS 
> property. I can’t see anything according to the documentation but was hoping 
> there was an oversight and something actually existed.
> 
> What I am trying to do is pass extra flags to the linker for every target in 
> my project and I didn’t want to have to set it per target. I tried using the 
> link_libraries command but the flags I am adding are msvc specific and start 
> with ‘/‘ and cmake seems to be turning these into ‘\’ when its passed to the 
> linker. Then the linker thinks its trying to link in another file and 
> everything blows up.
> 
> Also a secondary question is what does the INTERPROCEDURAL_OPTIMIZATIONS 
> property at the directory level do. I assume on Windows it passes /GL to the 
> compiler but will this also add /LCTG to the linker flags and prevent 
> incremental linking. If I turn this property on will it also do it for debug 
> configurations or just optimized configurations?
> 
> -- 
> Matt Keeler
> 
> -- 
> 
> 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

[CMake] Override CMAKE_SHARED_LINKER_FLAGS for one particular library

2016-05-02 Thread Attila Krasznahorkay
Dear All,

I have a similar issue as Matt Keeler. In our project we have some global 
linker flags that we set for all targets using the CMAKE_EXE_LINKER_FLAGS, 
CMAKE_SHARED_LINKER_FLAGS and CMAKE_MODULE_LINKER_FLAGS cache variables.

Now it turns out that for some libraries in the project I need to modify these 
flags. I can't modify the flags on the directory level, I need to modify them 
at the target level.

I tried just setting extra flags in LINK_FLAGS for my specific targets. But the 
problem is that the placement of the flags set in this target specific property 
is not "well defined" wrt. the global properties.

In this particular case we use "-Wl,--as-needed" globally for all of our 
targets. But for some particular libraries I'd like to turn this off. When I 
add "-Wl,--no-as-needed" to the LINK_FLAGS property of this library, it is put 
before the other flag in my final build configuration. And as such, it has no 
effect.

I tried modifying CMAKE_SHARED_LINKER_FLAGS before the add_library call for 
this library, and then restoring it to its original value afterwards. (Since as 
I said, I can't modify the flag for the entire directory.) But this didn't work 
as expected. Since by the generation stage CMake doesn't remember that the 
variable was set differently in the different lines of the directory's 
CMakeLists.txt file.

So, any ideas? I'd really hate to give up on using these global variables, and 
starting to set the flags one by one for all of our targets. Since it's a lot 
less work to just remove the flag for the targets that don't need it.

Cheers,
Attila
-- 

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] Xcode generator results in a project file without optimization

2016-05-02 Thread Siyuan Ren
I have CMake 3.5.2.

I write a simple CMakeLists.txt like the below

```
project(mytest)
add_executable(mytest test.cpp)
```

Then generate the Xcode project file with `cmake -G Xcode .`. Open the
project file in Xcode, and I found the optimization level on all kinds
of build, including "Debug", "Release", "RelWithDebInfo",
"MinSizeRel", to be "None (-O0)".

Do I do something wrong? Or CMake Xcode generator cannot even handle
the simplest project right?
-- 

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] LINK_FLAGS directory property

2016-05-02 Thread Matthew Keeler
I am doing that for some things but it gets quite cumbersome as I have to 
override those for several different configurations. I guess that is the only 
way to do it currently. 

-- 
Matt Keeler


On May 2, 2016 at 03:48:59, Attila Krasznahorkay 
(attila.krasznahor...@gmail.com) wrote:

Hi Matt,  

Have you tried using the  

CMAKE_EXE_LINKER_FLAGS  
CMAKE_SHARED_LINKER_FLAGS  
CMAKE_MODULE_LINKER_FLAGS  

cache variables? These actually set these flags globally, and not just for one 
directory, but on the directory level they are easy to override. You can just 
do something like this in a subdirectory:  

string( REPLACE "-Wl,--as-needed" "" CMAKE_SHARED_LINKER_FLAGS 
"${CMAKE_SHARED_LINKER_FLAGS}" )  

Cheers,  
Attila  

> On 27 Apr 2016, at 17:57, Matthew Keeler  wrote:  
>  
> Is there an equivalent directory property for the target level LINK_FLAGS 
> property. I can’t see anything according to the documentation but was hoping 
> there was an oversight and something actually existed.  
>  
> What I am trying to do is pass extra flags to the linker for every target in 
> my project and I didn’t want to have to set it per target. I tried using the 
> link_libraries command but the flags I am adding are msvc specific and start 
> with ‘/‘ and cmake seems to be turning these into ‘\’ when its passed to the 
> linker. Then the linker thinks its trying to link in another file and 
> everything blows up.  
>  
> Also a secondary question is what does the INTERPROCEDURAL_OPTIMIZATIONS 
> property at the directory level do. I assume on Windows it passes /GL to the 
> compiler but will this also add /LCTG to the linker flags and prevent 
> incremental linking. If I turn this property on will it also do it for debug 
> configurations or just optimized configurations?  
>  
> --  
> Matt Keeler  
>  
> --  
>  
> 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

[CMake] Emulating --whole-archive with MSVC

2016-05-02 Thread Guillaume Dumont
Hi,

I have been playing with the WINDOWS_EXPORT_ALL_SYMBOLS recently and found
the feature very useful. I reused part of the this functionality to emulate
the --whole-archive link flag with MSVC. Here is the process I used:

1. Use a POST_BUILD custom command to list the object files linked in the
static library (dumpbin /ARCHIVEMEMBERS mylib.lib and write this to a file.
2. Use a cmake script to call cmake -E __create_def and create a header
file with #pragma comment(linker, /include:" for every symbol in
the generated .def file.
3. Consuming projects including this header file when linking to mylib.lib

It seems that it would not be too hard to add this feature to cmake to that
it can be done via a target property similar to the
WINDOWS_EXPORT_ALL_SYMBOLS. For example:

1. WINDOWS_LINK_WHOLE_ARCHIVE is set on the library
2. CMake catches this and list all the object files into a file and calls
itself via cmake -E __create_whole_archive_rsp_file which creates a
response file containing a list of /INCLUDE:""
3. CMake adds this response file to the INTERFACE_LINK_LIBRARIES of the
target so that consuming projects automatically link in all the symbols
defined in the library.
4. Then cmake would have the handle the installation of this response file,
etc.

See this for documentation of rsp files:
https://msdn.microsoft.com/en-us/library/9xch38h8.aspx

This would probably have the side effect of solving
https://cmake.org/Bug/view.php?id=13032 which is nice.

Most of this is already possible via cmake code but could be made much
easier if it was just a property to set on a target.

Would it be possible to implement such a feature in CMake?

Do you see any problem with the process mentionned above?

Is it currently possible to add a response file to the link line via
target_link_libraries or via target properties?

Thank you

-- 
Guillaume Dumont
=
dumont.guilla...@gmail.com
-- 

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] Emulating --whole-archive with MSVC

2016-05-02 Thread Brad King
On 05/02/2016 11:03 AM, Guillaume Dumont wrote:
> emulate the --whole-archive link flag with MSVC

FYI, this is the purpose of OBJECT libraries in CMake.  However,
currently OBJECT libraries cannot be installed or used externally.
This limitation is primarily due to difficulty in defining semantics,
particularly in the case of transitive linking.

> 1. WINDOWS_LINK_WHOLE_ARCHIVE is set on the library
> 2. CMake catches this and list all the object files into a file and
> calls itself via cmake -E __create_whole_archive_rsp_file which creates
> a response file containing a list of /INCLUDE:""
> 3. CMake adds this response file to the INTERFACE_LINK_LIBRARIES of
> the target so that consuming projects automatically link in all the
> symbols defined in the library.
> 4. Then cmake would have the handle the installation of this response file, 
> etc.

Currently adding --whole-archive to INTERFACE_LINK_LIBRARIES is not well
defined.  It is only safe to add such flags in the target_link_libraries
call of the final binary.  This would be done on the client side.  Therefore
all of the above steps to simulate it should be done on the client side too
and there is no need to do anything ahead of time or install anything.

The way we express this on the client side with OBJECT libraries is
to specify $ as sources of the consuming target
in its add_library or add_executable call.  This eliminates any sense
of "linking" to the library in CMake's model of the project and therefore
avoids having to define semantics for usage requirements and transitive
linking of object libraries.

> Is it currently possible to add a response file to the link line via
> target_link_libraries or via target properties?

Yes, but it is safe only to do this on the final binary and cannot
currently be expressed as usage requirements on the library itself.

For upstream support of the relevant use cases I'd prefer to see if
OBJECT libraries can be made to handle them.  This will be more portable
than the platform-specific solution proposed here.

Discussion of this work would be better held on the dev list:

  https://cmake.org/mailman/listinfo/cmake-developers

-Brad

-- 

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