1

My project consists of multiple targets. I want to specify compile options for all of them with
command "target_compile_options"

I get a list of targets using macros from CMake - remove a compile flag for a single translation unit:

macro(apply_global_cxx_flags_to_all_targets)
    separate_arguments(_global_cxx_flags_list UNIX_COMMAND ${CMAKE_CXX_FLAGS})
    get_property(_targets DIRECTORY PROPERTY BUILDSYSTEM_TARGETS)
    foreach(_target ${_targets})
        target_compile_options(${_target} PUBLIC ${_global_cxx_flags_list})
    endforeach()
    unset(CMAKE_CXX_FLAGS)
    set(_flag_sync_required TRUE)
endmacro()

But I receive errors:

target_compile_options called with non-compilable target type

as some of targets doesn't require compiling. Is there a way to check if project is compilable? I want to use "target_compile_options as I need to remove some options for one subproject (as in mentioned thread)

MSZ
  • 11
  • 1

1 Answers1

2

Is there a way to check if project is compilable?

Yes, get the type of the target and check if it's an executable or a library and if it's not an INTERFACE library.

I want to specify compile options for all of them

Consider using add_compile_options at root folder instead.

KamilCuk
  • 120,984
  • 8
  • 59
  • 111