Files
Aethera/kernel/main.cmake
T
2026-08-26 10:55:29 +08:00

78 lines
3.8 KiB
CMake

include(${CMAKE_CURRENT_LIST_DIR}/cmake/rely.cmake)
set(Aethera_Kernel_dependencies aethera_kernel::taskflow global::magic_enum global::expected)
set(Aethera_BUILD_TESTS TRUE)
if (Aethera_BUILD_TESTS)
set(Aethera_Kernel_test_targets)
list(APPEND Aethera_Kernel_dependencies global::GTest)
endif ()
rcl_add_dependency_action_targets(Aethera_Kernel_env ${Aethera_Kernel_dependencies})
set_target_properties(Aethera_Kernel_env PROPERTIES FOLDER Aethera_Kernel)
library_get_missing_with_rely(Aethera_Kernel_dependencies_installed ${Aethera_Kernel_dependencies})
if (Aethera_Kernel_dependencies_installed)
rcl_log_append(${CMAKE_CURRENT_LIST_LINE} "[FATAL_ERROR] Aethera_Kernel dependencies are not installed. Build Aethera_Kernel_env first")
return()
endif ()
rcl_load_dependency_environment(${Aethera_Kernel_dependencies})
find_package(Threads REQUIRED)
find_package(Taskflow CONFIG REQUIRED)
find_package(magic_enum CONFIG REQUIRED)
find_package(tl-expected CONFIG REQUIRED)
if (Aethera_BUILD_TESTS)
find_package(GTest CONFIG REQUIRED)
endif ()
set(Aethera_Kernel_source_dir "${CMAKE_CURRENT_LIST_DIR}/src/kernel")
set(Aethera_concurrentqueue_dir "${CMAKE_CURRENT_LIST_DIR}/third_party/concurrentqueue-1.0.5")
add_subdirectory("${Aethera_concurrentqueue_dir}"
"${CMAKE_CURRENT_BINARY_DIR}/aethera_concurrentqueue" EXCLUDE_FROM_ALL)
append_glob_source(Aethera_Kernel_sources "${Aethera_Kernel_source_dir}")
add_library(Aethera_Kernel STATIC ${Aethera_Kernel_sources})
set_target_properties(Aethera_Kernel PROPERTIES EXPORT_NAME Kernel)
target_include_directories(Aethera_Kernel PUBLIC
"$<BUILD_INTERFACE:${Aethera_Kernel_source_dir}>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/third_party>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/third_party/ratas-master/src>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)
target_compile_features(Aethera_Kernel PUBLIC cxx_std_20)
target_link_libraries(Aethera_Kernel PUBLIC
Taskflow::Taskflow
magic_enum::magic_enum
tl::expected
"$<BUILD_INTERFACE:concurrentqueue>"
)
target_link_libraries(Aethera_Kernel PRIVATE Threads::Threads)
if (MSVC)
target_compile_options(Aethera_Kernel PUBLIC /utf-8)
endif ()
if (Aethera_BUILD_TESTS)
set(Aethera_Kernel_test_dir "${CMAKE_CURRENT_LIST_DIR}/src/test")
append_glob_source(Aethera_Kernel_test_sources "${Aethera_Kernel_test_dir}")
add_executable(Aethera_Kernel_exe ${Aethera_Kernel_test_sources})
target_link_libraries(Aethera_Kernel_exe PRIVATE Aethera_Kernel GTest::gtest)
add_test(NAME Aethera_Kernel_exe COMMAND Aethera_Kernel_exe)
set_tests_properties(Aethera_Kernel_exe PROPERTIES
LABELS "Aethera_Kernel"
ENVIRONMENT "Aethera_ERROR_MODE=exception")
list(APPEND Aethera_Kernel_test_targets Aethera_Kernel_exe)
endif ()
install(TARGETS Aethera_Kernel
EXPORT RenderiveTargets
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
install(DIRECTORY "${Aethera_Kernel_source_dir}/renderive"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp" PATTERN "*.ipp" PATTERN "*.inl")
install(FILES
"${Aethera_concurrentqueue_dir}/concurrentqueue.h"
"${Aethera_concurrentqueue_dir}/blockingconcurrentqueue.h"
"${Aethera_concurrentqueue_dir}/lightweightsemaphore.h"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/concurrentqueue-1.0.5")
if (Aethera_BUILD_TESTS)
add_custom_target(Aethera_Kernel_check
COMMAND "${CMAKE_CTEST_COMMAND}" --test-dir "${CMAKE_BINARY_DIR}"
-C "$<CONFIG>" -L "^Aethera_Kernel$" --output-on-failure
DEPENDS ${Aethera_Kernel_test_targets}
USES_TERMINAL)
endif ()