enable_language(C CXX) get_property(enabled_languages GLOBAL PROPERTY ENABLED_LANGUAGES) list(REMOVE_ITEM enabled_languages NONE) list(JOIN enabled_languages "," enabled_languages_genex) file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/enabled-languages.txt" "${enabled_languages}") add_library(concrete STATIC empty.c) add_library(headers INTERFACE) add_library(imported INTERFACE IMPORTED) set_property(TARGET imported PROPERTY SYSTEM FALSE) target_link_libraries(concrete PRIVATE headers imported) set(include_root "${CMAKE_CURRENT_BINARY_DIR}/include") foreach(dir IN ITEMS common c-only cxx-only cxx-id system-C system-CXX system-cxx-id all-languages mixed system-common) file(MAKE_DIRECTORY "${include_root}/${dir}") endforeach() foreach(language IN LISTS enabled_languages) file(MAKE_DIRECTORY "${include_root}/lang-${language}") endforeach() foreach(target IN ITEMS concrete headers imported) target_include_directories(${target} INTERFACE "${include_root}/common" # Visual Studio also evaluates includes for MIDL, exclude from include_directories. "$<$:${include_root}/lang-$>" "$<$:${include_root}/c-only>" "$<$:${include_root}/cxx-only>" "$<$:${include_root}/cxx-id>" "$<$:${include_root}/wrong-id>" "$<$:${include_root}/all-languages>" # Repeating a path must not duplicate entries or their language lists. "$<$:${include_root}/cxx-only>" "${include_root}/mixed" "$") target_include_directories(${target} SYSTEM INTERFACE "${include_root}/system-common" "$<$:${include_root}/system-C>" "$<$:${include_root}/system-CXX>" "$<$:${include_root}/system-cxx-id>" "$<$:${include_root}/system-wrong-id>" # This path is a regular include for C and a system include for C++. "$<$:${include_root}/mixed>") endforeach()