[SOLVED] CMAKE specific release linker flags

Hi there,
I’m in the middle of a windows app build using Clion/Cmake (via Mingw), and found out that in order to have a release build which is free from external dll dependencies I need to add the following to my Cmakelists release build part:

set(CMAKE_CXX_STANDARD_LIBRARIES “-static-libgcc -static-libstdc++ -lwsock32 -lws2_32 {CMAKE_CXX_STANDARD_LIBRARIES}") set(CMAKE_EXE_LINKER_FLAGS "{CMAKE_EXE_LINKER_FLAGS} -Wl,-Bstatic,–whole-archive -lwinpthread -Wl,–no-whole-archive”)

this is a basic workaround solution coming from here

My issue is that there’s no (afaik) chance of translating any projucer exporter flag (the ones Cmake exporter might import from) into these Cmake specific flags.
Since I really do not want to lose my projucer project, I see the following solutions, which are (hence the post category) feature requests :

  1. projucer post save script
  2. some cmake specific entries in the Cmake exporter

Of course I’d be also very happy to have missed a trivial way of making this happen in my CmakeLists file via some exporter data which is already in place and working… all the best in this case!!!

I’m all out of votes: +1 from me

The contents of CMAKE_CXX_STANDARD_LIBRARIES and CMAKE_EXE_LINKER_FLAGS should end-up in the command line for the linker. Have you tried putting all these flags in the “Extra Linker Flags” field of the “Code::Blocks (Windows)” exporter in Projucer?

Thanks! Will try, but I did a full text search on juce code for those flags so I’m pretty sure there’s no projucer code that does this translation

Using the example from the Stack Overflow thread that you linked to, I verified that doing:

set(CMAKE_CXX_STANDARD_LIBRARIES "-static-libgcc -static-libstdc++ -lwsock32 -lws2_32 {CMAKE_CXX_STANDARD_LIBRARIES}")
set(CMAKE_EXE_LINKER_FLAGS "{CMAKE_EXE_LINKER_FLAGS} -Wl,-Bstatic,–whole-archive -lwinpthread -Wl,–no-whole-archive")

is equivalent to doing:

target_link_libraries(<target> PRIVATE
  "-Wl,-Bstatic,--whole-archive"
  "-lwinpthread"
  "-Wl,--no-whole-archive"
  "-static-libgcc"
  "-static-libstdc++"
  "-lwsock32"
  "-lws2_32"
)

This means that putting

-Wl,-Bstatic,--whole-archive
-lwinpthread
-Wl,--no-whole-archive
-static-libgcc
-static-libstdc++

in the “Extra Linker Flags” field of the “Code::Blocks (Windows)” exporter should be all you need (-lwsock32 and -lws2_32 are already there, because they are dependencies of juce_core).

2 Likes

It worked like a charm thanks!!!

1 Like