-2

I'd like to have my program link time optimized. Where do I have to enter it to enable it?

If it matters (I hope it doesn't): I'm using MinGW-w64 5.0 on Windows.

edit: I really don't see why it wouldn't matter that I'm using CLion. I'm aware that - for now - it uses CMake as underlying build system.

But a) In the future CMake won't be the only build system that CLion will support (See here), so refering to CMake wouldn't solve the problem itself.

And b) adjusting the CMakeLists.txt would still require, that I configure each project individually. I asked for a way to configure the IDE, so it would do it for me.

I also don't this that it's an unsolvable problem per se. There could be a configuration or a PlugIn that does the trick. I failed to find it.. yet that doesn't mean that my question is unanswerable.

Jack Sabbath
  • 1,398
  • 2
  • 9
  • 12

1 Answers1

3

In general, this has nothing to do with CLion, but is a matter of CMake.

The problem, however, is that the appropriate flags differ among the compilers and linkers.

As you are using MinGW and, as far as I know that implies GCC, you can try the following as a rough starting point:

if(${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
    set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -flto")
    set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} -flto")
    set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} -flto")
endif()

However, I'd recommend using target properties (assuming you have a target MyTarget as an executable or shared library defined):

if(${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
  set_property(TARGET MyTarget
               APPEND PROPERTY LINK_FLAGS -lto)
endif()
Torbjörn
  • 5,512
  • 7
  • 46
  • 73
  • This works as a CMake solution. Unfortunately CMake isn't the only build system that CLion will support in the future. So breaking it down to CMake doesn't fully solve the problem. – Jack Sabbath Aug 10 '16 at 19:42