# Module function
function(px_module name build builtin)
  if(IS_ABSOLUTE "${LIBEXEC_INSTALL_DIR}")
    set(LIBEXECDIR "${LIBEXEC_INSTALL_DIR}")
  else ()
    set(LIBEXECDIR "${CMAKE_INSTALL_PREFIX}/${LIBEXEC_INSTALL_DIR}")
  endif()
  if(build)
    if(builtin)
      set(built "*")
      set_property(SOURCE modules/${name}.cpp PROPERTY COMPILE_DEFINITIONS LIBEXECDIR="${LIBEXECDIR}";MM_MODULE_BUILTIN=${name})
      set(LIBPROXY_SOURCES ${LIBPROXY_SOURCES} modules/${name}.cpp PARENT_SCOPE)
      set(BUILTIN_MODULES "${BUILTIN_MODULES} X\(${name}\)" PARENT_SCOPE)
      if(${ARGC} GREATER 3)
        set(LIBPROXY_LIBRARIES ${LIBPROXY_LIBRARIES} ${ARGN} PARENT_SCOPE)
      endif()
    else()
      set(built "m")
      set_property(SOURCE modules/${name}.cpp PROPERTY COMPILE_DEFINITIONS LIBEXECDIR="${LIBEXECDIR}")
      add_library(${name} MODULE modules/${name}.cpp)
      target_link_libraries(${name} libproxy)
      set_target_properties(${name} PROPERTIES PREFIX "")
      install(TARGETS ${name} LIBRARY DESTINATION ${MODULE_INSTALL_DIR})
      if(${ARGC} GREATER 3)
        target_link_libraries(${name} ${ARGN})
      endif()
    endif()
  endif()
  message("\t${built}\t${name}")
endfunction(px_module)
