用 SET_TARGET_PROPERTIES 来设置 COMPILE_FLAGS
使用范例:SET_TARGET_PROPERTIES(exeName PROPERTIES COMPILE_FLAGS "-O2 -Wall")
如:父CMakeLists中设置:
set(CMAKE_CXX_FLAGS "-pipe -O2 -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -Wno-strict-aliasing -Wno-unused-parameter -no-pie -fsigned-char -D_TEST")
子CMakeLists中设置:
if(${this_demod} STREQUAL "demodMavic")
SET_TARGET_PROPERTIES(${this_demod} PROPERTIES COMPILE_FLAGS "-D_MAVIC")
elseif(${this_demod} STREQUAL "demodGfsk")
SET_TARGET_PROPERTIES(${this_demod} PROPERTIES COMPILE_FLAGS "-D_GFSK")
elseif(${this_demod} STREQUAL "demodWifi")
SET_TARGET_PROPERTIES(${this_demod} PROPERTIES COMPILE_FLAGS "-D_WIFI")
代码中添加如下片段:
#ifdef _TEST
cout<<" _TEST "<<endl;
#endif
#ifdef _MAVIC
cout<<" _MAVIC "<<endl;
#endif
#ifdef _GFSK
cout<<" _GFSK "<<endl;
#endif
#ifdef _WIFI
cout<<" _WIFI "<<endl;
#endif
最后生成的三个可执行程序会分别打印: