function(sn_normalize_os_identifier INPUT_VALUE OUTPUT_NAME OUTPUT_DEFINE) string(TOLOWER "${INPUT_VALUE}" _sn_os) if(_sn_os STREQUAL "auto") string(TOLOWER "${CMAKE_SYSTEM_NAME}" _sn_system_name) if(_sn_system_name STREQUAL "windows") set(_sn_os "windows") elseif(_sn_system_name STREQUAL "linux") set(_sn_os "linux") elseif(_sn_system_name STREQUAL "darwin" OR _sn_system_name STREQUAL "macos") set(_sn_os "macos") elseif(_sn_system_name STREQUAL "ios") set(_sn_os "ios") elseif(_sn_system_name STREQUAL "android") set(_sn_os "android") else() set(_sn_os "unknown") endif() endif() if(_sn_os STREQUAL "windows") set(_sn_define SN_OS_WINDOWS) elseif(_sn_os STREQUAL "linux") set(_sn_define SN_OS_LINUX) elseif(_sn_os STREQUAL "macos") set(_sn_define SN_OS_MACOS) elseif(_sn_os STREQUAL "ios") set(_sn_define SN_OS_IOS) elseif(_sn_os STREQUAL "android") set(_sn_define SN_OS_ANDROID) elseif(_sn_os STREQUAL "unknown") set(_sn_define SN_OS_UNKNOWN) else() message(FATAL_ERROR "Unsupported SN_TARGET_OS='${INPUT_VALUE}'.") endif() set(${OUTPUT_NAME} "${_sn_os}" PARENT_SCOPE) set(${OUTPUT_DEFINE} "${_sn_define}" PARENT_SCOPE) endfunction() function(sn_normalize_arch_identifier INPUT_VALUE OUTPUT_NAME OUTPUT_DEFINE) string(TOLOWER "${INPUT_VALUE}" _sn_arch) if(_sn_arch STREQUAL "auto") string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" _sn_processor) if(_sn_processor MATCHES "^(amd64|x86_64|x64)$") set(_sn_arch "x86_64") elseif(_sn_processor MATCHES "^(arm64|aarch64)$") set(_sn_arch "arm64") elseif(_sn_processor STREQUAL "riscv64") set(_sn_arch "riscv64") elseif(_sn_processor MATCHES "^(ppc64le|powerpc64le)$") set(_sn_arch "ppc64le") else() message(FATAL_ERROR "Unable to infer ISA from CMAKE_SYSTEM_PROCESSOR='${CMAKE_SYSTEM_PROCESSOR}'. Set SN_TARGET_ARCH explicitly.") endif() endif() if(_sn_arch STREQUAL "x86_64") set(_sn_define SN_ARCH_X86_64) elseif(_sn_arch STREQUAL "arm64") set(_sn_define SN_ARCH_ARM64) elseif(_sn_arch STREQUAL "riscv64") set(_sn_define SN_ARCH_RISCV64) elseif(_sn_arch STREQUAL "ppc64le") set(_sn_define SN_ARCH_PPC64le) else() message(FATAL_ERROR "Unsupported SN_TARGET_ARCH='${INPUT_VALUE}'.") endif() set(${OUTPUT_NAME} "${_sn_arch}" PARENT_SCOPE) set(${OUTPUT_DEFINE} "${_sn_define}" PARENT_SCOPE) endfunction() function(sn_resolve_target_identifiers INPUT_OS INPUT_ARCH OUTPUT_OS_NAME OUTPUT_OS_DEFINE OUTPUT_ARCH_NAME OUTPUT_ARCH_DEFINE) sn_normalize_os_identifier("${INPUT_OS}" _sn_os_name _sn_os_define) sn_normalize_arch_identifier("${INPUT_ARCH}" _sn_arch_name _sn_arch_define) set(${OUTPUT_OS_NAME} "${_sn_os_name}" PARENT_SCOPE) set(${OUTPUT_OS_DEFINE} "${_sn_os_define}" PARENT_SCOPE) set(${OUTPUT_ARCH_NAME} "${_sn_arch_name}" PARENT_SCOPE) set(${OUTPUT_ARCH_DEFINE} "${_sn_arch_define}" PARENT_SCOPE) endfunction() function(sn_register_external_package TARGET PACKAGE_NAME PACKAGE_DIR) if(NOT TARGET ${TARGET}) message(FATAL_ERROR "sn_register_external_package: target '${TARGET}' does not exist.") endif() if(EXISTS "${PACKAGE_DIR}") target_include_directories(${TARGET} PRIVATE "${PACKAGE_DIR}") message(STATUS "Registered external package '${PACKAGE_NAME}' include: ${PACKAGE_DIR}") else() message(FATAL_ERROR "External package directory not found: ${PACKAGE_DIR}") endif() endfunction() function(sn_link_external_binary_if_exists TARGET LIBRARY_PATH) if(EXISTS "${LIBRARY_PATH}") target_link_libraries(${TARGET} PRIVATE "${LIBRARY_PATH}") message(STATUS "Linked external binary: ${LIBRARY_PATH}") endif() endfunction()