cmake_minimum_required(VERSION 3.5)
project(photon)
macro(subdirlist result curdir)
file(GLOB children RELATIVE ${curdir} ${curdir}/*)
set(dirlist "")
foreach (child ${children})
if (IS_DIRECTORY ${curdir}/${child})
list(APPEND dirlist ${child})
endif()
endforeach()
set(${result} ${dirlist})
endmacro()
subdirlist(machine_dirs ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/machine)
if (NOT PLATFORM)
set(PLATFORM "linux")
endif ()
if (NOT MACHINE)
set(supported_machines "")
foreach (dir ${machine_dirs})
set(supported_machines "${supported_machines}${dir} ")
endforeach (dir)
message(FATAL_ERROR "No machine architecture specified.\n"
" Supported machines: ${supported_machines}\n"
" Ex. `cmake -DMACHINE=x86_64
`")
endif ()
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/sys/${PLATFORM})
message(FATAL_ERROR "Unsupported platform: ${PLATFORM}")
endif ()
message(STATUS "Target platform: ${PLATFORM}")
set(photon_libc_sources "")
set(generic_dirs string include)
foreach (dir ${generic_dirs})
file(GLOB_RECURSE dir_sources ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/${dir}/*.c)
set(photon_libc_sources ${photon_libc_sources} ${dir_sources})
endforeach (dir)
file(GLOB_RECURSE platform_sources ${CMAKE_CURRENT_SOURCE_DIR}/photon/sys/${PLATFORM})
set(photon_libc_sources ${photon_libc_sources} ${platform_sources})
add_library(c STATIC ${photon_libc_sources})
target_compile_options(c PRIVATE -ffreestanding -nostdlib -nostdinc)
target_include_directories(c PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/include)