diff --git a/toolchain/CMakeLists.txt b/toolchain/CMakeLists.txt index b64e824..46cdb49 100644 --- a/toolchain/CMakeLists.txt +++ b/toolchain/CMakeLists.txt @@ -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_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib) -set(FX_STATIC 1) -find_package(FX REQUIRED COMPONENTS Core Ds Term Cmd Io) +add_subdirectory(../lib/libfx ${CMAKE_CURRENT_BINARY_DIR}/libfx) +find_package(FX REQUIRED COMPONENTS + fx.runtime fx.collections fx.cmdline fx.serial fx.io) add_subdirectory( ../kernel/tools diff --git a/toolchain/cmake/FindFX.cmake b/toolchain/cmake/FindFX.cmake index 735ae13..3e6564d 100644 --- a/toolchain/cmake/FindFX.cmake +++ b/toolchain/cmake/FindFX.cmake @@ -49,43 +49,42 @@ if (FX_STATIC) set(_lib_suffix "-s") endif () -set(supported_components Core Ds Term Cmd Io Serial Compress) -set(components ${FX_FIND_COMPONENTS}) -string(REPLACE ";" ", " supported_components_string_list "${supported_components}") - -if (NOT components) - set(components ${supported_components}) -endif () - +set(assemblies ${FX_FIND_COMPONENTS}) set(required_vars) +set(in_tree FALSE) -foreach (component ${components}) - if (NOT "${component}" IN_LIST supported_components) - message(FATAL_ERROR "'${component}' is not a valid FX module.\nSupported modules: ${supported_components_string_list}") - endif () +foreach (assembly ${assemblies}) + string(TOLOWER ${assembly} header_name) + string(REPLACE "." "_" macro_name ${assembly}) + string(TOUPPER ${macro_name} macro_name) - string(TOLOWER ${component} header_name) - set(lib_name ${header_name}${_lib_suffix}) + set(lib_name ${assembly}${_lib_suffix}) - if (NOT FX_${component}_INCLUDE_DIR) - find_path(FX_${component}_INCLUDE_DIR - NAMES fx/${header_name}.h ${FX_FIND_ARGS} - PATH_SUFFIXES include - PATHS ${FX_SEARCH_PATHS}) - 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}) + 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 "${FX_${component}_LIBRARY}" FX_${component}_LIBRARY) + file(TO_CMAKE_PATH "${${macro_name}_LIBRARY}" ${macro_name}_LIBRARY) endif() - list(APPEND required_vars FX_${component}_INCLUDE_DIR FX_${component}_LIBRARY) -endforeach (component) + list(APPEND required_vars ${macro_name}_LIBRARY) +endforeach (assembly) + +if (NOT FX_INCLUDE_DIR AND NOT in_tree) + list(APPEND required_vars FX_INCLUDE_DIR) + find_path(FX_INCLUDE_DIR + NAMES fx/misc.h ${FX_FIND_ARGS} + PATH_SUFFIXES include + PATHS ${FX_SEARCH_PATHS}) +endif () unset(FX_FIND_ARGS) @@ -96,94 +95,38 @@ find_package_handle_standard_args(FX if (FX_FOUND) set(created_targets) - foreach (component ${components}) - string(TOLOWER ${component} header_name) - set(lib_name ${header_name}${_lib_suffix}) + foreach (assembly ${assemblies}) + set(target_name ${assembly}) + 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}) - add_library(FX::${component} UNKNOWN IMPORTED) - set_target_properties(FX::${component} PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${FX_${component}_INCLUDE_DIR}") - target_compile_definitions(FX::${component} INTERFACE _CRT_SECURE_NO_WARNINGS=1) + string(TOLOWER ${assembly} header_name) + string(REPLACE "." "_" macro_name ${assembly}) + string(REPLACE "." "_" macro_name ${assembly}) + string(TOUPPER ${macro_name} macro_name) - if (FX_STATIC) - target_compile_definitions(FX::${component} INTERFACE FX_STATIC=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) + target_compile_definitions(FX::${target_name} INTERFACE FX_STATIC=1) + endif () + set_target_properties(FX::${target_name} PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${${macro_name}_LIBRARY}") endif () - - set_target_properties(FX::${component} PROPERTIES - IMPORTED_LINK_INTERFACE_LANGUAGES "C" - IMPORTED_LOCATION "${FX_${component}_LIBRARY}") - set(created_targets ${created_targets} ${component}) + set(created_targets ${created_targets} ${assembly}) endif () - endforeach (component) - - 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 () - - 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) + endforeach (assembly) endif()