How to add compile options to an external library in C++?

Viewed 93

Overview

Context

  • I'm using Clion, and I try to use the C++ google's benchmark library in my project.

My problem

  • My project has a build type Debug, when I compile it, the benchmark library is also compiled as Debug. BUT I need the library to be build as Release for it to work properly.

The (not good enough) solution

  • I have to add '-DCMAKE_BUILD_TYPE=Release' to Clion's Cmake options, however it's now the whole project witch is in Release

How do I impose to one library to compile with different options ?

My code (cmake)

#My target (I wnat it to run in debug)
add_executable(benchmark_test
        thread/benchmark_test.cpp
        thread/benchmark_test.h)

# prevent lib to run tests
set(BENCHMARK_ENABLE_TESTING NO)

# Importing the lib (source code at the root of the project)
# I want it to run in release
add_subdirectory(benchmark)

# Linking the target and the lib
target_link_libraries(benchmark_test benchmark)

What didn't work so far


# I would have thought this one to put everything in release but no (maybe because of Clion)
add_compile_options(-DCMAKE_BUILD_TYPE=Release)

#===================================================================

# This was my most advanced try so far 
set(GCC_COMPILE_OPTIONS "-DCMAKE_BUILD_TYPE=Release")
target_compile_options(benchmark_main PUBLIC "$<$<CONFIG:Debug>:${GCC_COMPILE_DEBUG_OPTIONS}>")
target_compile_options(benchmark PUBLIC "$<$<CONFIG:Debug>:${GCC_COMPILE_DEBUG_OPTIONS}>")


I'm kinda new here, just tell me if there is any lack of information ^^

0 Answers
Related