Files
photon/CMakeLists.txt

121 lines
4.4 KiB
CMake
Raw Normal View History

2020-03-30 20:04:17 +01:00
cmake_minimum_required(VERSION 3.5)
2020-07-07 18:53:54 +01:00
# project(photon C ASM-ATT)
2020-03-30 20:04:17 +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
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/platform.cmake)
2020-07-07 18:53:54 +01:00
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Bundles.cmake)
2020-04-30 17:44:54 +01:00
platform_config(${PHOTON_TARGET})
2020-03-30 20:04:17 +01:00
message(STATUS "Target: ${machine}-${platform}")
include(${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/sys/${platform}/config.cmake)
2020-03-31 12:55:52 +01:00
set(CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} -ffreestanding -nostdlib -lgcc")
2020-04-17 11:24:05 +01:00
set(malloc_impl dlmalloc)
set(photon_libc_sources "")
2020-05-15 19:29:02 +01:00
set(generic_dirs string stdio stdlib errno internal)
2020-04-17 11:24:05 +01:00
message(STATUS "Memory allocator: ${malloc_impl}")
foreach (dir ${generic_dirs})
2020-03-31 12:55:52 +01:00
file(GLOB dir_sources ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/${dir}/*.c)
set(photon_libc_sources ${photon_libc_sources} ${dir_sources})
endforeach (dir)
2020-04-17 11:24:05 +01:00
file(GLOB malloc_sources
2020-05-15 19:29:02 +01:00
${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/malloc/${malloc_impl}/*.c
${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/malloc/${malloc_impl}/*.h)
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
${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})
2020-04-30 17:44:54 +01:00
target_compile_options(crt PRIVATE -c)
2020-03-31 12:55:52 +01:00
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)
2020-03-31 16:21:07 +01:00
foreach (platform_source_dir ${photon_platform_extra_source_dirs})
file(GLOB dir_sources
${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/sys/${platform}/${platform_source_dir}/*.c
${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/sys/${platform}/${platform_source_dir}/*.h)
set(platform_sources ${platform_sources} ${dir_sources})
endforeach (platform_source_dir)
foreach (platform_include_dir ${photon_platform_extra_include_dirs})
file(GLOB dir_sources
${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/sys/${platform}/${platform_include_dir}/*.h)
set(platform_sources ${platform_sources} ${dir_sources})
endforeach (platform_include_dir)
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
${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-04-17 11:24:05 +01:00
set(photon_libc_sources ${photon_libc_sources} ${malloc_sources} ${platform_sources})
2020-03-31 16:21:07 +01:00
set(photon_libc_headers ${photon_libc_headers} ${platform_headers})
2020-07-07 18:53:54 +01:00
add_framework(Photon STATIC
BUNDLE_ID net.doorstuck.photon
SOURCES ${photon_libc_sources} ${photon_libc_headers}
HEADERS ${CMAKE_CURRENT_BINARY_DIR}/sysroot/usr/include/*)
2020-04-30 17:44:54 +01:00
2020-07-07 18:53:54 +01:00
framework_compile_options(Photon -ffreestanding -nostdlib)
framework_link_libraries(Photon ${photon_platform_libs})
framework_link_frameworks(Photon ${photon_platform_frameworks})
2020-07-07 18:53:54 +01:00
framework_include_directories(Photon ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/include
${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/sys/${platform}/
${CMAKE_CURRENT_BINARY_DIR}/sysroot/usr/include)
foreach (platform_include_dir ${photon_platform_extra_include_dirs})
2020-07-07 18:53:54 +01:00
framework_include_directories(Photon
${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/sys/${platform}/${platform_include_dir})
endforeach (platform_include_dir)
2020-04-30 17:44:54 +01:00
add_custom_target(local-root
2020-03-31 16:21:07 +01:00
DEPENDS ${photon_libc_headers}
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/create-sysroot.sh
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${platform} ${machine})
2020-03-31 16:21:07 +01:00
2020-07-14 19:02:29 +01:00
framework_add_dependencies(Photon local-root crt)
2020-07-07 18:53:54 +01:00
add_custom_command(TARGET Photon POST_BUILD
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/add-framework-crt.sh
${CMAKE_CURRENT_BINARY_DIR}/Photon.framework
${CMAKE_CURRENT_BINARY_DIR})
2020-03-31 16:21:07 +01:00
2020-04-03 19:21:22 +01:00
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
2020-07-07 18:53:54 +01:00
framework_link_libraries(Photon gcc)
endif ()
if (TARGET early-sysroot)
# We are being built as part of asbestOS, make sure the sysroot is there.
framework_add_dependencies(Photon early-sysroot)
2020-04-03 19:21:22 +01:00
endif ()
2020-04-30 17:44:54 +01:00
if (PHOTON_TESTS EQUAL 1)
add_subdirectory(tests)
endif ()