0

I have a C++ project which uses CMake as its build system in Visual Studio 2017 Enterprise. According to the documentation, I have to link using /LTCG and /GENPROFILE. In CMake, this seems to equate to setting the variable CMAKE_EXE_LINKER_FLAGS:

set(LINKER_FLAGS, "/LTCG /GENPROFILE")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LINKER_FLAGS}")

Furthermore, since my application requires command line arguments, I had to define them in the launch.vs.json as seen in this answer.

Now if I run the application's x64-Release profile, it successfully completes in a normal, non-delayed Release build fashion. No .pgd has been generated which means that my passed linker flags probably have been ignored.

Another try was adding additional CMake linker flag variables:

set(LINKER_FLAGS, "/LTCG /USEPROFILE")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LINKER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${LINKER_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LINKER_FLAGS}")
set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} ${LINKER_FLAGS}")

This also didn't work. Specifying /USEPROFILE afterwards did not generate a different binary. Also, the runtimes are roughly equivalent. There is also no indication on the command line that a profile has been generated or used.

What am I doing wrong here?

BullyWiiPlaza
  • 17,329
  • 10
  • 113
  • 185
  • 2
    When use CMake, forget about comma as a separator... I mean that `set(LINKER_FLAGS, "/LTCG /GENPROFILE")` will assign a variable named `LINKER_FLAGS,` (with comma!). – Tsyvarev Feb 24 '19 at 16:28
  • Yes, that worked now. Thanks :) But the optimized executable isn't even faster than the original even though it is fed the same input arguments for the calculation. Oh well, that wasn't useful then. – BullyWiiPlaza Feb 25 '19 at 11:51

0 Answers0