set(source_dirs unistd spawn)

if (LIBC_STANDALONE)
	cmake_minimum_required(VERSION 3.31)
	project(libc-exec C ASM)
endif ()

file(GLOB sources *.c *.h)

foreach (dir ${source_dirs})
	file(GLOB dir_sources ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/*.c)
	file(GLOB dir_headers ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/*.h)

	set(sources ${sources} ${dir_sources})
	set(headers ${headers} ${dir_headers})
endforeach (dir)

file(GLOB_RECURSE sub_headers ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h)
set(headers ${headers} ${sub_headers})

if (NOT LIBC_STANDALONE)
	set(component_sources ${sources} PARENT_SCOPE)
	set(component_headers ${headers} PARENT_SCOPE)
	set(component_public_include_dirs ${CMAKE_CURRENT_SOURCE_DIR}/include PARENT_SCOPE)
endif ()

add_library(libc-exec STATIC ${sources} ${headers})
target_include_directories(libc-exec PUBLIC
	${public_include_dirs}
	${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(libc-exec libc-core libc-io libmagenta liblaunch-static)
target_compile_definitions(libc-exec PRIVATE ENABLE_GLOBAL_HEAP=1 BUILD_STATIC=1)
set_target_properties(libc-exec PROPERTIES PREFIX "")
install(TARGETS libc-exec)
