Files
photon/CMakeLists.txt
2020-11-23 19:58:07 +00:00

128 lines
4.6 KiB
CMake

if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
cmake_minimum_required(VERSION 3.5)
project(photon C ASM-ATT)
endif ()
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(Bundles)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/platform.cmake)
platform_config(${PHOTON_TARGET})
message(STATUS "Target: ${machine}-${platform}")
include(${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/sys/${platform}/config.cmake)
set(CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} -ffreestanding -nostdlib -lgcc")
set(malloc_impl dlmalloc)
set(photon_libc_sources "")
set(generic_dirs string stdio stdlib errno internal ctype wchar)
message(STATUS "Memory allocator: ${malloc_impl}")
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 malloc_sources
${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/malloc/${malloc_impl}/*.c
${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/malloc/${malloc_impl}/*.h)
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)
message(STATUS "CRT files: ${photon_libc_crt}")
add_custom_target(crt ALL
DEPENDS ${photon_libc_crt}
COMMAND mx.clang -c -ffreestanding ${photon_libc_crt}
COMMENT "Generating CRT files")
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 (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)
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} ${malloc_sources} ${platform_sources})
set(photon_libc_headers ${photon_libc_headers} ${platform_headers})
add_framework(photon SHARED
BUNDLE_ID net.doorstuck.photon
SOURCES ${photon_libc_sources} ${photon_libc_headers}
HEADERS ${CMAKE_CURRENT_BINARY_DIR}/sysroot/usr/include/*)
bundle_compile_options(photon PRIVATE -ffreestanding -nostdlib -fPIC -fPIE)
bundle_link_libraries(photon ${photon_platform_libs} -ffreestanding)
bundle_link_frameworks(photon ${photon_platform_frameworks})
bundle_include_directories(photon PRIVATE
${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})
bundle_include_directories(photon
${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/sys/${platform}/${platform_include_dir})
endforeach (platform_include_dir)
add_custom_target(local-root
DEPENDS ${photon_libc_headers}
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/create-sysroot.sh
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${platform} ${machine})
bundle_add_dependencies(photon local-root crt)
add_custom_command(TARGET photon POST_BUILD
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/add-framework-crt.sh
${BUNDLE_PROGRAM}
${CMAKE_CURRENT_BINARY_DIR}/photon.framework
${CMAKE_CURRENT_BINARY_DIR})
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
bundle_link_libraries(photon gcc)
endif ()
if (TARGET early-sysroot)
# We are being built as part of asbestOS, make sure the sysroot is there.
bundle_add_dependencies(photon early-sysroot)
endif ()
if (PHOTON_TESTS EQUAL 1)
add_subdirectory(tests)
endif ()