2020-03-30 20:04:17 +01:00
|
|
|
cmake_minimum_required(VERSION 3.5)
|
|
|
|
|
project(photon)
|
|
|
|
|
|
2020-03-31 12:04:53 +01:00
|
|
|
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()
|
2020-03-30 20:04:17 +01:00
|
|
|
|
2020-03-31 12:04:53 +01:00
|
|
|
subdirlist(machine_dirs ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/machine)
|
2020-03-30 20:04:17 +01:00
|
|
|
|
2020-03-31 12:04:53 +01:00
|
|
|
if (NOT PLATFORM)
|
|
|
|
|
set(PLATFORM "linux")
|
|
|
|
|
endif ()
|
2020-03-30 20:04:17 +01:00
|
|
|
|
2020-03-31 12:04:53 +01:00
|
|
|
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 <dir>`")
|
|
|
|
|
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)
|