Select variable depending on build variant

Hi,

I have a CMake file which has the following 3 lines, among many others:

set(LIBS_TYPE "_dbg")
set(CMAKE_CONFIGURATION_TYPES "Debug" "Release")
target_link_libraries(${APP_NAME} PUBLIC ${STATIC_libs}/my_lib${LIBS_TYPE}.a)

The idea is to have Cmake invoke the debug or release libs depending on the build variant from my IDE (VSCode);

For example, in debug mode, we should call the library my_lib_dbg.a, whereas the release mode will call my_lib.a.

It is a manual process right now, I have to modify LIBS_TYPE by hand.

Is there a way to make it automatically?

Thanks

Try something like this:
set(LIBS_TYPE “MyLibTypePrefixIfAny$<$<CONFIG:Debug>:_dbg>”)
Also note that you may not even need a LIB_TYPE variable now and just name your lib with the $<$CONFIG:Debug:_dbg> addition directly.
EDIT: missed the double $<> wrapping in my original answer, fixed.

Thanks Fab :+1: