collector_create (PROJECT_LIB_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}")
collector_create (PROJECT_LIB_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}")

collect (PROJECT_LIB_DIRS "${CMAKE_CURRENT_BINARY_DIR}")
collect (PROJECT_INC_DIRS "${CMAKE_CURRENT_BINARY_DIR}/include")

collect (PROJECT_LIB_HEADERS alloc.h)
collect (PROJECT_LIB_HEADERS assert.h)
collect (PROJECT_LIB_HEADERS atomic.h)
collect (PROJECT_LIB_HEADERS cache.h)
collect (PROJECT_LIB_HEADERS compiler.h)
collect (PROJECT_LIB_HEADERS condition.h)
collect (PROJECT_LIB_HEADERS config.h)
collect (PROJECT_LIB_HEADERS cpu.h)
collect (PROJECT_LIB_HEADERS device.h)
collect (PROJECT_LIB_HEADERS errno.h)
collect (PROJECT_LIB_HEADERS dma.h)
collect (PROJECT_LIB_HEADERS io.h)
collect (PROJECT_LIB_HEADERS irq.h)
collect (PROJECT_LIB_HEADERS irq_controller.h)
collect (PROJECT_LIB_HEADERS list.h)
collect (PROJECT_LIB_HEADERS log.h)
collect (PROJECT_LIB_HEADERS mutex.h)
collect (PROJECT_LIB_HEADERS shmem.h)
collect (PROJECT_LIB_HEADERS sleep.h)
collect (PROJECT_LIB_HEADERS softirq.h)
collect (PROJECT_LIB_HEADERS spinlock.h)
collect (PROJECT_LIB_HEADERS sys.h)
collect (PROJECT_LIB_HEADERS time.h)
collect (PROJECT_LIB_HEADERS utilities.h)
collect (PROJECT_LIB_HEADERS version.h)

collect (PROJECT_LIB_SOURCES dma.c)
collect (PROJECT_LIB_SOURCES device.c)
collect (PROJECT_LIB_SOURCES init.c)
collect (PROJECT_LIB_SOURCES io.c)
collect (PROJECT_LIB_SOURCES irq.c)
collect (PROJECT_LIB_SOURCES log.c)
collect (PROJECT_LIB_SOURCES shmem.c)
collect (PROJECT_LIB_SOURCES softirq.c)
collect (PROJECT_LIB_SOURCES version.c)

add_subdirectory (compiler)
add_subdirectory (processor)
add_subdirectory (system)

collector_list (_inc_dirs PROJECT_INC_DIRS)
collector_list (_sources PROJECT_LIB_SOURCES)
collector_list (_headers PROJECT_LIB_HEADERS)
collector_list (_deps PROJECT_LIB_DEPS)

foreach (f ${_headers})
  configure_file (${f} include/${PROJECT_NAME}/${f} @ONLY)
  install (FILES ${CMAKE_CURRENT_BINARY_DIR}/include/${PROJECT_NAME}/${f}
           DESTINATION ${CMAKE_INCLUDE_PATH} RENAME ${PROJECT_NAME}/${f})
  if (${f} MATCHES "^[^/]*\\.h")
    collect (PROJECT_HDR_TESTS "metal/${f}")
  endif (${f} MATCHES "^[^/]*\\.h")
endforeach (f)

include_directories (${_inc_dirs})
add_definitions (-DMETAL_INTERNAL)

if (WITH_DEFAULT_LOGGER)
  add_definitions (-DDEFAULT_LOGGER_ON)
endif (WITH_DEFAULT_LOGGER)

get_property (_ec_flgs GLOBAL PROPERTY "PROJECT_EC_FLAGS")

set (_lib ${PROJECT_NAME})


add_library (${_lib} STATIC ${_sources})
install (TARGETS ${_lib} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
target_compile_options (${_lib} PUBLIC ${_ec_flgs})

set_target_properties (${_lib} PROPERTIES OUTPUT_NAME  "${_lib}")

set_target_properties(${_lib} PROPERTIES ADDITIONAL_CLEAN_FILES "${CMAKE_LIBRARY_PATH}/${_lib}.a;${CMAKE_INCLUDE_PATH}/metal;${clean_headers};${CMAKE_LIBRARY_PATH}/libmetal.a")
install(TARGETS ${_lib} LIBRARY DESTINATION ${CMAKE_LIBRARY_PATH} ARCHIVE DESTINATION ${CMAKE_LIBRARY_PATH})

# vim: expandtab:ts=2:sw=2:smartindent
