Files
photon/CMakeLists.txt
2020-04-03 19:21:22 +01:00

76 lines
2.5 KiB
CMake

cmake_minimum_required(VERSION 3.5)
project(photon C ASM-ATT)
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()
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/platform.cmake)
platform_config(${TARGET})
message(STATUS "Target: ${machine}-${platform}")
set(CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} -ffreestanding -nostdlib -lgcc")
set(photon_libc_sources "")
set(generic_dirs string stdio)
foreach (dir ${generic_dirs})
file(GLOB dir_sources ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/${dir}/*.c)
set(photon_libc_sources ${photon_libc_sources} ${dir_sources})
endforeach (dir)
file(GLOB_RECURSE photon_libc_headers ${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})
file(GLOB platform_sources
${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)
foreach (crt_source ${photon_libc_crt})
list(REMOVE_ITEM platform_sources ${crt_source})
endforeach (crt_source)
file(GLOB platform_headers
${CMAKE_CURRENT_SOURCE_DIR}/photon/sys/${platform}/*.h
${CMAKE_CURRENT_SOURCE_DIR}/photon/sys/${platform}/machine/${machine}/*.h)
set(photon_libc_sources ${photon_libc_sources} ${platform_sources})
set(photon_libc_headers ${photon_libc_headers} ${platform_headers})
add_library(c SHARED ${photon_libc_sources} ${photon_libc_headers})
target_compile_options(c PRIVATE -ffreestanding -nostdlib)
target_link_libraries(c crt)
target_include_directories(c PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/include)
target_include_directories(c PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/sys/${platform}/)
target_include_directories(c PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/sysroot/usr/include)
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}
${platform} ${machine})
add_dependencies(c sysroot)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_link_libraries(c gcc)
endif ()
add_subdirectory(tests)