2026-07-19 13:34:32 +01:00
|
|
|
cmake_minimum_required(VERSION 3.31)
|
|
|
|
|
project(libc-pthread C ASM)
|
|
|
|
|
|
|
|
|
|
set(pthread_source_dirs thread mutex)
|
2026-03-18 21:08:49 +00:00
|
|
|
|
2026-03-22 13:11:10 +00:00
|
|
|
foreach (dir ${pthread_source_dirs})
|
2026-03-18 21:08:49 +00:00
|
|
|
file(GLOB dir_sources ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/*.c)
|
|
|
|
|
file(GLOB dir_headers ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/*.h)
|
|
|
|
|
|
2026-03-22 13:11:10 +00:00
|
|
|
set(pthread_sources ${pthread_sources} ${dir_sources})
|
|
|
|
|
set(pthread_headers ${pthread_headers} ${dir_headers})
|
2026-03-18 21:08:49 +00:00
|
|
|
endforeach (dir)
|
|
|
|
|
|
2026-03-22 13:11:10 +00:00
|
|
|
file(GLOB pthread_sys_sources
|
2026-03-18 21:08:49 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/sys/${CMAKE_SYSTEM_PROCESSOR}/*.c
|
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/sys/${CMAKE_SYSTEM_PROCESSOR}/*.S)
|
|
|
|
|
|
2026-03-22 13:11:10 +00:00
|
|
|
set(pthread_sources ${pthread_sources} ${pthread_sys_sources})
|
2026-03-18 21:08:49 +00:00
|
|
|
|
2026-03-22 13:11:10 +00:00
|
|
|
set(pthread_headers ${pthread_headers} ${CMAKE_CURRENT_SOURCE_DIR}/include/pthread.h)
|
|
|
|
|
set(pthread_public_include_dir ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
2026-03-18 21:08:49 +00:00
|
|
|
|
2026-07-19 13:34:32 +01:00
|
|
|
if (PTHREAD_STATIC)
|
|
|
|
|
add_library(libc-pthread STATIC ${pthread_sources} ${pthread_headers})
|
|
|
|
|
target_link_libraries(libc-pthread PRIVATE libc-io libmagenta)
|
|
|
|
|
target_include_directories(libc-pthread PUBLIC
|
|
|
|
|
${public_include_dirs}
|
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include)
|
|
|
|
|
set_target_properties(libc-pthread PROPERTIES PREFIX "")
|
|
|
|
|
target_compile_definitions(libc-pthread PRIVATE ENABLE_GLOBAL_HEAP=1 BUILD_STATIC=1)
|
|
|
|
|
install(TARGETS libc-pthread)
|
|
|
|
|
else ()
|
|
|
|
|
add_library(libpthread SHARED ${pthread_sources} ${pthread_headers})
|
|
|
|
|
target_link_libraries(libpthread PRIVATE magenta)
|
|
|
|
|
target_link_libraries(libpthread PUBLIC c)
|
|
|
|
|
target_include_directories(libpthread PUBLIC
|
|
|
|
|
${public_include_dirs}
|
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include)
|
|
|
|
|
set_target_properties(libpthread PROPERTIES PREFIX "")
|
|
|
|
|
target_compile_options(libpthread PRIVATE -ffreestanding -nostdlib)
|
|
|
|
|
target_link_options(libpthread PRIVATE -ffreestanding -nostdlib)
|
|
|
|
|
target_compile_definitions(libpthread PRIVATE ENABLE_GLOBAL_HEAP=1 BUILD_SHARED=1)
|
|
|
|
|
install(TARGETS libpthread)
|
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
|
|
install(FILES include/pthread.h DESTINATION include)
|