1

I have a cmake c++ project which consists of several executables and dlls. Because the dlls get injected into another application, they have to be built with config=Release, even when the executables are built with debug info.

Is there any way to force cmake to do that? I tried set(CMAKE_BUILD_TYPE "Release") right before the call to add_library(), but that didn't work.

Any help appreciated, thanks.

Johannes Stricker
  • 1,701
  • 13
  • 23

2 Answers2

2

On windows, when you build the library, you have to additionally specify the config

For example:

cmake --build {BUILDDIR} --config Release

See also: https://stackoverflow.com/a/20423820/10248910

0xfull
  • 33
  • 6
  • 1
    Yes, I know that and I am passing that along. However I am building all the files with that single command. So if I build them with `cmake --build {BUILDDIR} --config Debug` I want the dlls to ignore the config parameter and build with `--config Release` instead. – Johannes Stricker Aug 21 '18 at 08:30
0

Not the best but,

target_compile_options(libmylib PRIVATE "-O3")

gets the job done.

vmiheer
  • 147
  • 9
  • 1
    Would you kindly explain why this is not the best approach or why does this work, and why `-O3` is needed here? – Carles Araguz Sep 16 '20 at 07:39
  • 1. why this is not the best approach? -> Might want to ideally pass CMAKE_CXX_FLAGS_RELEASE instead of just "-O3". 2. Why "O3"? -> By release I assumed "optimized" in the above question. With "O3" most compilers (clang/gcc/msvc) will do optimized codegen. – vmiheer Sep 17 '20 at 17:22