# ============================================================================== # Compiler and Linker Flags # ============================================================================== # This module sets platform-specific and compiler-specific flags, libraries, # and definitions used throughout the build system. # # Variables set: # BASE_LIBRARIES - Libraries to link based on target platform # BASE_DEFINITIONS - Preprocessor definitions based on target platform # BASE_OPTIONS - Compiler warning flags (C/C++ only, not applied to Swift) # # Requires: Platform.cmake must be included first (for IS_* variables) # ============================================================================== # ------------------------------------------------------------------------------ # Framework Detection Helper # ------------------------------------------------------------------------------ # find_and_link_framework( ) # # Searches for an Apple framework and, if found, appends -framework to # the output list. # # Parameters: # - OUT_VAR Name of the list variable to append the flag to # - FRAMEWORK_NAME The framework name to search for (e.g. "IOKit") # - DISPLAY_NAME Human-readable name for status messages function(find_and_link_framework OUT_VAR FRAMEWORK_NAME DISPLAY_NAME) find_library(_FOUND_LIB ${FRAMEWORK_NAME}) if (_FOUND_LIB) message(STATUS " [x] ${DISPLAY_NAME} (-framework ${FRAMEWORK_NAME})") list(APPEND ${OUT_VAR} "-framework ${FRAMEWORK_NAME}") set(${OUT_VAR} "${${OUT_VAR}}" PARENT_SCOPE) else() message(STATUS " [ ] ${DISPLAY_NAME} (-framework ${FRAMEWORK_NAME})") endif() unset(_FOUND_LIB CACHE) endfunction() # ------------------------------------------------------------------------------ # Platform-Specific Link Libraries # ------------------------------------------------------------------------------ # These frameworks are required for USB access, crypto and (later) audio. # They are linked into the final executable; static libraries reference the # symbols and resolution happens at final link time. set(BASE_LIBRARIES "") if (IS_MACOS) message(STATUS "macOS link libraries:") find_and_link_framework(BASE_LIBRARIES "IOKit" "IOKit (USB transport)") find_and_link_framework(BASE_LIBRARIES "CoreFoundation" "Core Foundation") find_and_link_framework(BASE_LIBRARIES "Security" "Security (crypto/ECDH)") elseif (IS_IOS) message(FATAL_ERROR "iOS is not supported yet!") endif() # ------------------------------------------------------------------------------ # Platform-Specific Definitions # ------------------------------------------------------------------------------ set(BASE_DEFINITIONS "") # ------------------------------------------------------------------------------ # Compiler Warning Flags # ------------------------------------------------------------------------------ # These are stored in BASE_OPTIONS and applied per-target via # target_compile_options() to avoid polluting external dependencies. # NOTE: Applied to C/C++ targets only; swiftc does not share these flags. set(BASE_OPTIONS "") if (IS_CLANG_OR_GCC) set(BASE_OPTIONS "-Wall" # Enable all common warnings "-Wextra" # Enable extra warnings "-Werror" # Treat warnings as errors ) elseif (IS_MSVC) set(BASE_OPTIONS "/W4" # Warning level 4 (high) "/WX" # Treat warnings as errors "/utf-8" # Set source and execution character set to UTF-8 "/Zc:__cplusplus" # Report correct C++ standard version in __cplusplus ) endif()