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-04-01 12:41:26 +01:00
|
|
|
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/platform.cmake)
|
|
|
|
|
platform_config(${TARGET})
|
2020-03-30 20:04:17 +01:00
|
|
|
|
2020-04-01 12:41:26 +01:00
|
|
|
message(STATUS "Target: ${machine}-${platform}")
|
2020-03-31 12:04:53 +01:00
|
|
|
|
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 18:36:58 +01:00
|
|
|
set(generic_dirs string stdio)
|
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 16:21:07 +01:00
|
|
|
file(GLOB_RECURSE photon_libc_headers ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/include/*.h)
|
2020-03-31 12:55:52 +01:00
|
|
|
|
|
|
|
|
file(GLOB photon_libc_crt
|
2020-04-01 12:41:26 +01:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/sys/${platform}/machine/${machine}/crt*.s)
|
2020-03-31 12:55:52 +01:00
|
|
|
|
|
|
|
|
add_library(crt OBJECT ${photon_libc_crt})
|
|
|
|
|
|
|
|
|
|
file(GLOB platform_sources
|
2020-04-01 12:41:26 +01:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/sys/${platform}/*.c
|
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/sys/${platform}/machine/${machine}/*.c
|
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/sys/${platform}/machine/${machine}/*.s)
|
2020-03-31 16:21:07 +01:00
|
|
|
|
|
|
|
|
foreach (crt_source ${photon_libc_crt})
|
|
|
|
|
list(REMOVE_ITEM platform_sources ${crt_source})
|
|
|
|
|
endforeach (crt_source)
|
|
|
|
|
|
|
|
|
|
file(GLOB platform_headers
|
2020-04-01 12:41:26 +01:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/photon/sys/${platform}/*.h
|
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/photon/sys/${platform}/machine/${machine}/*.h)
|
2020-03-31 16:21:07 +01:00
|
|
|
|
2020-03-31 12:04:53 +01:00
|
|
|
set(photon_libc_sources ${photon_libc_sources} ${platform_sources})
|
2020-03-31 16:21:07 +01:00
|
|
|
set(photon_libc_headers ${photon_libc_headers} ${platform_headers})
|
2020-03-31 12:04:53 +01:00
|
|
|
|
2020-03-31 18:41:31 +01:00
|
|
|
add_library(c SHARED ${photon_libc_sources} ${photon_libc_headers})
|
2020-04-03 19:21:22 +01:00
|
|
|
target_compile_options(c PRIVATE -ffreestanding -nostdlib)
|
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-04-01 12:41:26 +01:00
|
|
|
target_include_directories(c PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/sys/${platform}/)
|
2020-04-03 19:21:22 +01:00
|
|
|
target_include_directories(c PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/sysroot/usr/include)
|
2020-03-31 12:55:52 +01:00
|
|
|
|
2020-03-31 16:21:07 +01:00
|
|
|
add_custom_target(sysroot
|
|
|
|
|
DEPENDS ${photon_libc_headers}
|
|
|
|
|
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/create-sysroot.sh
|
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}
|
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}
|
2020-04-01 12:41:26 +01:00
|
|
|
${platform} ${machine})
|
2020-03-31 16:21:07 +01:00
|
|
|
|
|
|
|
|
add_dependencies(c sysroot)
|
|
|
|
|
|
2020-04-03 19:21:22 +01:00
|
|
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
|
|
|
|
target_link_libraries(c gcc)
|
|
|
|
|
endif ()
|
|
|
|
|
|
2020-03-31 12:55:52 +01:00
|
|
|
add_subdirectory(tests)
|