2020-03-30 20:04:17 +01:00
|
|
|
cmake_minimum_required(VERSION 3.5)
|
2020-03-31 12:55:52 +01:00
|
|
|
project(photon C ASM-ATT)
|
2020-03-30 20:04:17 +01:00
|
|
|
|
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}")
|
|
|
|
|
|
2020-03-31 12:55:52 +01:00
|
|
|
set(CMAKE_EXE_LINKER_FLAGS
|
|
|
|
|
"${CMAKE_EXE_LINKER_FLAGS} -ffreestanding -nostdlib -lgcc")
|
|
|
|
|
|
2020-03-31 12:04:53 +01:00
|
|
|
set(photon_libc_sources "")
|
2020-03-31 12:55:52 +01:00
|
|
|
set(generic_dirs string)
|
2020-03-31 12:04:53 +01:00
|
|
|
|
|
|
|
|
foreach (dir ${generic_dirs})
|
2020-03-31 12:55:52 +01:00
|
|
|
file(GLOB dir_sources ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/${dir}/*.c)
|
2020-03-31 12:04:53 +01:00
|
|
|
set(photon_libc_sources ${photon_libc_sources} ${dir_sources})
|
|
|
|
|
endforeach (dir)
|
|
|
|
|
|
2020-03-31 12:55:52 +01:00
|
|
|
file(GLOB_RECURSE photon_libc_includes ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/include/*.h)
|
|
|
|
|
|
|
|
|
|
file(GLOB photon_libc_crt
|
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/sys/${PLATFORM}/machine/${MACHINE}/crt*.s)
|
|
|
|
|
|
|
|
|
|
add_library(crt OBJECT ${photon_libc_crt})
|
|
|
|
|
message(STATUS "CRT sources: ${photon_libc_crt}")
|
|
|
|
|
|
|
|
|
|
file(GLOB platform_sources
|
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/photon/sys/${PLATFORM}/*.c
|
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/photon/sys/${PLATFORM}/*.h
|
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/photon/sys/${PLATFORM}/machine/${MACHINE}/*.c
|
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/photon/sys/${PLATFORM}/machine/${MACHINE}/*.h
|
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/photon/sys/${PLATFORM}/machine/${MACHINE}/*.s)
|
2020-03-31 12:04:53 +01:00
|
|
|
set(photon_libc_sources ${photon_libc_sources} ${platform_sources})
|
|
|
|
|
|
2020-03-31 12:55:52 +01:00
|
|
|
add_library(c STATIC ${photon_libc_sources} ${photon_libc_includes})
|
2020-03-31 12:04:53 +01:00
|
|
|
target_compile_options(c PRIVATE -ffreestanding -nostdlib -nostdinc)
|
2020-03-31 12:55:52 +01:00
|
|
|
target_link_libraries(c crt)
|
2020-03-31 12:04:53 +01:00
|
|
|
|
|
|
|
|
target_include_directories(c PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/include)
|
2020-03-31 12:55:52 +01:00
|
|
|
|
|
|
|
|
add_subdirectory(tests)
|