New platform selection system in build system

This commit is contained in:
Max Wash
2020-04-01 12:41:26 +01:00
parent 1e237adbc0
commit bee0a8ff9f
3 changed files with 55 additions and 29 deletions

View File

@@ -12,28 +12,10 @@ macro(subdirlist result curdir)
set(${result} ${dirlist})
endmacro()
subdirlist(machine_dirs ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/machine)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/platform.cmake)
platform_config(${TARGET})
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 <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}")
message(STATUS "Target: ${machine}-${platform}")
set(CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} -ffreestanding -nostdlib -lgcc")
@@ -49,22 +31,22 @@ 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)
${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)
${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)
${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})
@@ -74,14 +56,14 @@ target_compile_options(c PRIVATE -ffreestanding -nostdlib -nostdinc)
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_SOURCE_DIR}/photon/libc/sys/${platform}/)
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})
${platform} ${machine})
add_dependencies(c sysroot)