a
示例
1 | target_compile_options(mylib PRIVATE -O2) # only internal |
使用cmake生成表达式
In you case you can use:
1 | target_compile_options(${TARGET} PRIVATE |
or about compilers:
1 | target_compile_options(${TARGET} PRIVATE |
相关参考
Does set_target_properties in CMake override CMAKE_CXX_FLAGS?
It is impossible to reliably use target_compile_options() on MSVC.
Change default value of CMAKE_CXX_FLAGS_DEBUG and friends in CMake
Does set_target_properties in CMake override CMAKE_CXX_FLAGS?
Compile with /MT instead of /MD using CMake
Modern way to set compiler flags in cross-platform cmake project
What is the modern method for setting general compile flags in CMake?
Difference between add_compile_options and SET(CMAKE_CXX_FLAGS…)
Blog
CMake – Properties and Options
cmake 论坛
target_compile_options de-duplicates flags but some repeats matter
cmake运行时库的方法
Changing CMAKE_CXX_FLAGS in project
CMake - remove a compile flag for a single translation unit
Does set_target_properties in CMake override CMAKE_CXX_FLAGS?
Not possible to set "/MT" or "/MTd" for Visual Studio 15 2017 generator
Compile with /MT instead of /MD using CMake
csdn