function(meshfem_single_app name)
    add_executable(${name} ${name}.cc)
    target_link_libraries(${name} ${ARGN})
    target_link_libraries(${name} warnings::all)
endfunction()

function(meshfem_target_hide_warnings)
    foreach(name IN ITEMS ${ARGN})
        message(STATUS "Hiding warnings for target ${name}")
        get_target_property(target_type ${name} TYPE)

        # Hide warnings from interface headers
        get_target_property(TARGET_INCLUDE_DIR ${name} INTERFACE_INCLUDE_DIRECTORIES)
        if(TARGET_INCLUDE_DIR)
            set_target_properties(${name} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "")
            target_include_directories(${name} SYSTEM INTERFACE ${TARGET_INCLUDE_DIR})
        endif()

        if(NOT ${target_type} STREQUAL "INTERFACE_LIBRARY")
            # Hide warnings from private headers
            get_target_property(TARGET_INCLUDE_DIR ${name} INCLUDE_DIRECTORIES)
            if(TARGET_INCLUDE_DIR)
                set_target_properties(${name} PROPERTIES INCLUDE_DIRECTORIES "")
                target_include_directories(${name} SYSTEM PRIVATE ${TARGET_INCLUDE_DIR})
            endif()

            # Hide warnings generated by the files themselves
            if(NOT DEFINED MESHFEM_IS_SUPPORTED_NO_WARNING)
                include(CheckCXXCompilerFlag)
                check_cxx_compiler_flag("-w" MESHFEM_IS_SUPPORTED_NO_WARNING)
            endif()
            if(MESHFEM_IS_SUPPORTED_NO_WARNING)
                target_compile_options(${name} PRIVATE "-w")
            endif()
        endif()
    endforeach()
endfunction()
