function(target_add_reflect_file target file_to_add source_root)
    if (TARGET reflect)
        set(REFLECT_EXE $<TARGET_FILE:reflect>)
    else()
        find_program(REFLECT_EXE reflect)
    endif()
    get_filename_component(file_with_path ${file_to_add} ABSOLUTE)
    get_filename_component(file_name ${file_to_add} NAME)
    message("target ${file_with_path} : ${file_name}")
    set(OUTPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/reflect_json_${file_name}")
    message(OUT FILE ${OUTPUT_FILE})
    message("command: OUTPUT ${OUTPUT_FILE}
                       COMMAND ${REFLECT_EXE} \"${file_with_path}\" -o ${OUTPUT_FILE}
                       DEPENDS \"${file_with_path}\"")
    get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
    foreach(dir ${dirs})
        if (dir)
            set(INCLUDE_DIRS ${INCLUDE_DIRS} -I${dir})
        endif()
    endforeach()
    get_cmake_property(_variableNames VARIABLES)
    foreach (_variableName ${_variableNames})
        message(STATUS "${_variableName}=${${_variableName}}")
    endforeach()
    foreach(cDir ${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES})
        set(INCLUDE_DIRS ${INCLUDE_DIRS} -I${cDir} -I${CMAKE_CURRENT_BINARY_DIR})
    endforeach()
    set(INCLUDE_DIRS ${INCLUDE_DIRS} -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/8.0.0/include)
    add_custom_command(OUTPUT ${OUTPUT_FILE}
                       COMMAND ${REFLECT_EXE} "${file_with_path}" ${INCLUDE_DIRS} -o ${OUTPUT_FILE} --sysroot /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain --srcroot ${source_root}
                       DEPENDS "${file_with_path}"
                               ${REFLECT_EXE})
    target_sources(${target} PRIVATE "${OUTPUT_FILE}")
endfunction()
