toolchain: use lib/libfx to build toolchain rather than finding libfx externally

This commit is contained in:
2026-05-30 10:12:05 +01:00
parent 86d12edd19
commit c87e094d7d
2 changed files with 61 additions and 117 deletions
+3 -2
View File
@@ -8,8 +8,9 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
set(FX_STATIC 1) add_subdirectory(../lib/libfx ${CMAKE_CURRENT_BINARY_DIR}/libfx)
find_package(FX REQUIRED COMPONENTS Core Ds Term Cmd Io) find_package(FX REQUIRED COMPONENTS
fx.runtime fx.collections fx.cmdline fx.serial fx.io)
add_subdirectory( add_subdirectory(
../kernel/tools ../kernel/tools
+55 -112
View File
@@ -49,44 +49,43 @@ if (FX_STATIC)
set(_lib_suffix "-s") set(_lib_suffix "-s")
endif () endif ()
set(supported_components Core Ds Term Cmd Io Serial Compress) set(assemblies ${FX_FIND_COMPONENTS})
set(components ${FX_FIND_COMPONENTS})
string(REPLACE ";" ", " supported_components_string_list "${supported_components}")
if (NOT components)
set(components ${supported_components})
endif ()
set(required_vars) set(required_vars)
set(in_tree FALSE)
foreach (component ${components}) foreach (assembly ${assemblies})
if (NOT "${component}" IN_LIST supported_components) string(TOLOWER ${assembly} header_name)
message(FATAL_ERROR "'${component}' is not a valid FX module.\nSupported modules: ${supported_components_string_list}") string(REPLACE "." "_" macro_name ${assembly})
string(TOUPPER ${macro_name} macro_name)
set(lib_name ${assembly}${_lib_suffix})
if (NOT ${macro_name}_LIBRARY)
if (TARGET ${assembly})
set (${macro_name}_LIBRARY ${assembly})
set(in_tree TRUE)
else ()
find_library(${macro_name}_LIBRARY
NAMES ${lib_name} ${FX_FIND_ARGS}
PATH_SUFFIXES lib
PATHS ${FX_SEARCH_PATHS})
endif ()
else ()
# on Windows, ensure paths are in canonical format (forward slahes):
file(TO_CMAKE_PATH "${${macro_name}_LIBRARY}" ${macro_name}_LIBRARY)
endif() endif()
string(TOLOWER ${component} header_name) list(APPEND required_vars ${macro_name}_LIBRARY)
set(lib_name ${header_name}${_lib_suffix}) endforeach (assembly)
if (NOT FX_${component}_INCLUDE_DIR) if (NOT FX_INCLUDE_DIR AND NOT in_tree)
find_path(FX_${component}_INCLUDE_DIR list(APPEND required_vars FX_INCLUDE_DIR)
NAMES fx/${header_name}.h ${FX_FIND_ARGS} find_path(FX_INCLUDE_DIR
NAMES fx/misc.h ${FX_FIND_ARGS}
PATH_SUFFIXES include PATH_SUFFIXES include
PATHS ${FX_SEARCH_PATHS}) PATHS ${FX_SEARCH_PATHS})
endif () endif ()
if (NOT FX_${component}_LIBRARY)
find_library(FX_${component}_LIBRARY
NAMES fx-${lib_name} ${FX_FIND_ARGS}
PATH_SUFFIXES lib
PATHS ${FX_SEARCH_PATHS})
else ()
# on Windows, ensure paths are in canonical format (forward slahes):
file(TO_CMAKE_PATH "${FX_${component}_LIBRARY}" FX_${component}_LIBRARY)
endif()
list(APPEND required_vars FX_${component}_INCLUDE_DIR FX_${component}_LIBRARY)
endforeach (component)
unset(FX_FIND_ARGS) unset(FX_FIND_ARGS)
include(FindPackageHandleStandardArgs) include(FindPackageHandleStandardArgs)
@@ -96,94 +95,38 @@ find_package_handle_standard_args(FX
if (FX_FOUND) if (FX_FOUND)
set(created_targets) set(created_targets)
foreach (component ${components}) foreach (assembly ${assemblies})
string(TOLOWER ${component} header_name) set(target_name ${assembly})
set(lib_name ${header_name}${_lib_suffix}) string(REPLACE "fx." "" target_name ${target_name})
string(SUBSTRING ${target_name} 0 1 target_name_prefix)
string(TOUPPER ${target_name_prefix} target_name_prefix)
string(SUBSTRING ${target_name} 1 -1 target_name_suffix)
set(target_name ${target_name_prefix}${target_name_suffix})
if(NOT TARGET FX::${component}) string(TOLOWER ${assembly} header_name)
add_library(FX::${component} UNKNOWN IMPORTED) string(REPLACE "." "_" macro_name ${assembly})
set_target_properties(FX::${component} PROPERTIES string(REPLACE "." "_" macro_name ${assembly})
INTERFACE_INCLUDE_DIRECTORIES "${FX_${component}_INCLUDE_DIR}") string(TOUPPER ${macro_name} macro_name)
target_compile_definitions(FX::${component} INTERFACE _CRT_SECURE_NO_WARNINGS=1)
set(lib_name ${assembly}${_lib_suffix})
if (NOT TARGET FX::${target_name})
if (TARGET ${assembly})
add_library(FX::${target_name} ALIAS ${assembly})
else ()
add_library(FX::${target_name} UNKNOWN IMPORTED)
set_target_properties(FX::${target_name} PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${FX_INCLUDE_DIR}")
target_compile_definitions(FX::${target_name} INTERFACE _CRT_SECURE_NO_WARNINGS=1)
if (FX_STATIC) if (FX_STATIC)
target_compile_definitions(FX::${component} INTERFACE FX_STATIC=1) target_compile_definitions(FX::${target_name} INTERFACE FX_STATIC=1)
endif () endif ()
set_target_properties(FX::${target_name} PROPERTIES
set_target_properties(FX::${component} PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "C" IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${FX_${component}_LIBRARY}") IMPORTED_LOCATION "${${macro_name}_LIBRARY}")
set(created_targets ${created_targets} ${component})
endif () endif ()
endforeach (component) set(created_targets ${created_targets} ${assembly})
foreach (component ${created_targets})
if ("${component}" STREQUAL "Ds")
if (NOT TARGET FX::Core)
message(FATAL_ERROR "FX: Module 'Ds' depends on 'Core', which was not specified in find_package()")
endif () endif ()
endforeach (assembly)
target_link_libraries(FX::Ds INTERFACE FX::Core)
endif ()
if ("${component}" STREQUAL "Term")
if (NOT TARGET FX::Core)
message(FATAL_ERROR "FX: Module 'Term' depends on 'Core', which was not specified in find_package()")
endif ()
if (NOT TARGET FX::Ds)
message(FATAL_ERROR "FX: Module 'Term' depends on 'Ds', which was not specified in find_package()")
endif ()
target_link_libraries(FX::Term INTERFACE FX::Core FX::Ds)
endif ()
if ("${component}" STREQUAL "Serial")
if (NOT TARGET FX::Core)
message(FATAL_ERROR "FX: Module 'Serial' depends on 'Core', which was not specified in find_package()")
endif ()
if (NOT TARGET FX::Ds)
message(FATAL_ERROR "FX: Module 'Serial' depends on 'Ds', which was not specified in find_package()")
endif ()
target_link_libraries(FX::Serial INTERFACE FX::Core FX::Ds)
endif ()
if ("${component}" STREQUAL "Cmd")
if (NOT TARGET FX::Core)
message(FATAL_ERROR "FX: Module 'Cmd' depends on 'Core', which was not specified in find_package()")
endif ()
if (NOT TARGET FX::Ds)
message(FATAL_ERROR "FX: Module 'Cmd' depends on 'Ds', which was not specified in find_package()")
endif ()
if (NOT TARGET FX::Term)
message(FATAL_ERROR "FX: Module 'Cmd' depends on 'Term', which was not specified in find_package()")
endif ()
target_link_libraries(FX::Cmd INTERFACE FX::Core FX::Ds FX::Term)
endif ()
if ("${component}" STREQUAL "Io")
if (NOT TARGET FX::Core)
message(FATAL_ERROR "FX: Module 'Io' depends on 'Core', which was not specified in find_package()")
endif ()
if (NOT TARGET FX::Ds)
message(FATAL_ERROR "FX: Module 'Io' depends on 'Ds', which was not specified in find_package()")
endif ()
target_link_libraries(FX::Io INTERFACE FX::Core FX::Ds)
endif ()
if ("${component}" STREQUAL "Compress")
if (NOT TARGET FX::Core)
message(FATAL_ERROR "FX: Module 'Compress' depends on 'Core', which was not specified in find_package()")
endif ()
target_link_libraries(FX::Compress INTERFACE FX::Core FX::Ds)
endif ()
endforeach (component)
endif() endif()