In modern CMake, the following works well:
if(MSVC) target_compile_options(${TARGET_NAME} PRIVATE /W4 /WX) else() target_compile_options(${TARGET_NAME} PRIVATE -Wall -Wextra -pedantic -Werror) endif()
Replace ${TARGET_NAME} with the actual target name. -Werror is optional; it turns all warnings into errors.
Or use add_compile_options(...) if you want to apply it to all goals, as suggested by @aldo in the comments.
mrts Jun 15 '18 at 20:23 2018-06-15 20:23
source share