From a20306ae641f916c93e88542838af534348a3614 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Fri, 29 May 2026 20:45:46 +0100 Subject: [PATCH] cmake: update package finder module --- cmake/FindFX.cmake | 153 +++++++++++++-------------------------------- 1 file changed, 44 insertions(+), 109 deletions(-) diff --git a/cmake/FindFX.cmake b/cmake/FindFX.cmake index 735ae13..a42535e 100644 --- a/cmake/FindFX.cmake +++ b/cmake/FindFX.cmake @@ -49,43 +49,37 @@ 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) -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 () +if (NOT FX_INCLUDE_DIR) + find_path(FX_INCLUDE_DIR + NAMES fx/misc.h ${FX_FIND_ARGS} + PATH_SUFFIXES include + PATHS ${FX_SEARCH_PATHS}) +endif () - string(TOLOWER ${component} header_name) - set(lib_name ${header_name}${_lib_suffix}) +set(required_vars FX_INCLUDE_DIR) - 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 () +foreach (assembly ${assemblies}) + string(TOLOWER ${assembly} header_name) + string(REPLACE "." "_" macro_name ${assembly}) + string(TOUPPER ${macro_name} macro_name) - if (NOT FX_${component}_LIBRARY) - find_library(FX_${component}_LIBRARY - NAMES fx-${lib_name} ${FX_FIND_ARGS} + set(lib_name ${assembly}${_lib_suffix}) + + if (NOT ${macro_name}_LIBRARY) + find_library(${macro_name}_LIBRARY + NAMES ${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) + 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) unset(FX_FIND_ARGS) @@ -96,94 +90,35 @@ 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) + + set(lib_name ${assembly}${_lib_suffix}) + + if (NOT TARGET FX::${target_name}) + 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::${component} INTERFACE FX_STATIC=1) + target_compile_definitions(FX::${target_name} INTERFACE FX_STATIC=1) endif () - set_target_properties(FX::${component} PROPERTIES + set_target_properties(FX::${target_name} PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C" - IMPORTED_LOCATION "${FX_${component}_LIBRARY}") - set(created_targets ${created_targets} ${component}) + IMPORTED_LOCATION "${${macro_name}_LIBRARY}") + 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()