0

I have found the way to configure according to Andre's comment in How to change a compiler flag for just one executable in CMake? .

For example, I add a flag for bubble.c:

set_source_files_properties( ${ProjDirPath}/../bubble.c PROPERTIES COMPILE_FLAGS "-O2")

It worked.But I can't specify the flag for debug or release. Dose anyone know how to configure it? Thank you!

2 Answers2

0
IF(CMAKE_BUILD_TYPE MATCHES DEBUG)
set_source_files_properties( ${ProjDirPath}/../bubble.c PROPERTIES COMPILE_FLAGS "-O2")
ENDIF(CMAKE_BUILD_TYPE MATCHES DEBUG)
arved
  • 4,401
  • 4
  • 30
  • 53
  • Only works for single-configuration generators per cmake documentation for the variable `CMAKE_BUILD_TYPE`. – fdk1342 Dec 07 '18 at 14:01
0

Use special syntax like this:

set_source_files_properties(myfile.cpp PROPERTIES 
    COMPILE_FLAGS $<$<CONFIG:RelDebug>:/O2>
    SKIP_PRECOMPILE_HEADERS $<$<CONFIG:RelDebug>:ON>
)

Sets specific compilation option only to specific configuration (in this case for RelDebug).

TarmoPikaro
  • 4,723
  • 2
  • 50
  • 62