<commit_before>#
# Copyright (c) .NET Foundation and Contributors
# See LICENSE file in the project root for full license information.
#

include(binutils.common)

function(nf_set_optimization_options target) 

    target_compile_options(${target} PRIVATE
        $<$<CONFIG:Debug>:-Og -femit-class-debug-always -g3 -ggdb>
        $<$<CONFIG:Release>:-O3 -flto -fuse-linker-plugin -fno-fat-lto-objects>
        $<$<CONFIG:MinSizeRel>:-Os -flto>
        $<$<CONFIG:RelWithDebInfo>:-Os -femit-class-debug-always -g3 -ggdb>
    )

endfunction()


function(nf_set_linker_file target linker_file_name)

    # set linker file name
    set_target_properties(${target} PROPERTIES LINK_FLAGS "-T${linker_file_name}")

endfunction()

# setting compile definitions for a target based on general build options
# TARGET parameter to set the target that's setting them for
# optional EXTRA_COMPILE_DEFINITIONS with compiler definitions to be added to the library
# optional BUILD_TARGET when target it's a library pass here the name ot the target that's building for (either nanoBooter or nanoCLR)
macro(nf_set_compile_definitions)

    # parse arguments
    cmake_parse_arguments(NFSCD "" "TARGET" "EXTRA_COMPILE_DEFINITIONS;BUILD_TARGET" ${ARGN})

    if(NOT NFSCD_TARGET OR "${NFSCD_TARGET}" STREQUAL "")
        message(FATAL_ERROR "Need to set TARGET argument when calling nf_set_compile_definitions()")
    endif()

    # definition for platform 
    # ChibiOS HAL community always include (nanoFramework overlay and official community contributions optionally)
    target_compile_definitions(${NFSCD_TARGET} PUBLIC -DHAL_USE_COMMUNITY )

    nf_common_compiler_definitions(TARGET ${NFSCD_TARGET} BUILD_TARGET ${NFSCD_BUILD_TARGET})

    # include extra compiler definitions
    target_compile_definitions(${NFSCD_TARGET} PUBLIC ${NFSCD_EXTRA_COMPILE_DEFINITIONS})

endmacro()

function(nf_set_stm32_target_series)
    # process target series, which is in the format "STM32F4xx"
    string(REPLACE "STM32" "" TARGET_SERIES_SHORT_1 "${TARGET_SERIES}")
    string(REPLACE "xx" "" TARGET_SERIES_SHORT "${TARGET_SERIES_SHORT_1}")
    
    # store the series short name for later use
    set(TARGET_SERIES_SHORT ${TARGET_SERIES_SHORT} CACHE INTERNAL "STM32 target series short name")

endfunction()

# Add platform packages specific to ChibiOS
# To be called from target CMakeList.txt
# optional TARGET argument with target name
macro(nf_add_platform_packages)

    # parse arguments
    cmake_parse_arguments(NFAPP "" "TARGET" "" ${ARGN})
   
    # packages common to all targets
    find_package(ChibiOS REQUIRED QUIET)
    find_package(ChibiOS_${TARGET_SERIES_SHORT}_HAL REQUIRED QUIET)
    find_package(ChibiOSnfOverlay REQUIRED QUIET)

    # ChibiOS contrib repo
    if(CHIBIOS_CONTRIB_REQUIRED)
        find_package(ChibiOS-Contrib REQUIRED QUIET)
    endif()

    if(USE_FILESYSTEM_OPTION)
        find_package(CHIBIOS_FATFS REQUIRED QUIET)
    endif()

    # SPIFFS
    if(NF_FEATURE_USE_SPIFFS)
        find_package(STM32F7_CubePackage REQUIRED QUIET)
        find_package(SPIFFS REQUIRED QUIET)
    endif()

    if(STM32_CUBE_PACKAGE_REQUIRED)
        find_package(${TARGET_STM32_CUBE_PACKAGE}_CubePackage REQUIRED QUIET)
    endif()
    
    # packages specific for nanoBooter
    if("${NFAPP_TARGET}" STREQUAL "${NANOBOOTER_PROJECT_NAME}")
        # no packages for booter
    endif()

    # packages specific for nanoCRL
    if("${NFAPP_TARGET}" STREQUAL "${NANOCLR_PROJECT_NAME}")

        if(USE_NETWORKING_OPTION)

            find_package(NF_Network REQUIRED QUIET)
            find_package(CHIBIOS_LWIP REQUIRED QUIET)

            # security provider is mbedTLS
            if(USE_SECURITY_MBEDTLS_OPTION)
                find_package(mbedTLS REQUIRED QUIET)
            endif()

        endif()

    endif()
 
endmacro()

# Add ChibiOS platform dependencies to a specific CMake target
# To be called from target CMakeList.txt
macro(nf_add_platform_dependencies target)

    nf_add_common_dependencies(${target})

    # dependencies specific to nanoCRL
    if("${target}" STREQUAL "${NANOCLR_PROJECT_NAME}")

        nf_add_lib_coreclr(
            EXTRA_INCLUDES
                ${CHIBIOS_INCLUDE_DIRS}
                ${CHIBIOS_HAL_INCLUDE_DIRS}
                ${ChibiOSnfOverlay_INCLUDE_DIRS}
                ${CHIBIOS_CONTRIB_INCLUDE_DIRS}
                ${TARGET_CHIBIOS_COMMON_INCLUDE_DIRS}
                ${TARGET_CHIBIOS_NANOCLR_INCLUDE_DIRS}
                ${chibios_SOURCE_DIR}/os/hal/boards/${TARGET_BOARD})

        add_dependencies(${target}.elf nano::NF_CoreCLR)

        nf_add_lib_wireprotocol(
            EXTRA_INCLUDES
                ${CHIBIOS_INCLUDE_DIRS}
                ${CHIBIOS_HAL_INCLUDE_DIRS}
                ${ChibiOSnfOverlay_INCLUDE_DIRS}
                ${CHIBIOS_CONTRIB_INCLUDE_DIRS}
                ${TARGET_CHIBIOS_COMMON_INCLUDE_DIRS}
                ${TARGET_CHIBIOS_NANOCLR_INCLUDE_DIRS}
                ${chibios_SOURCE_DIR}/os/hal/boards/${TARGET_BOARD})

        add_dependencies(${target}.elf nano::WireProtocol)

        if(NF_FEATURE_DEBUGGER)

            nf_add_lib_debugger(
                EXTRA_INCLUDES
                    ${CHIBIOS_INCLUDE_DIRS}
                    ${CHIBIOS_HAL_INCLUDE_DIRS}
                    ${ChibiOSnfOverlay_INCLUDE_DIRS}
                    ${CHIBIOS_CONTRIB_INCLUDE_DIRS}
                    ${CHIBIOS_LWIP_INCLUDE_DIRS}
                    ${TARGET_CHIBIOS_COMMON_INCLUDE_DIRS}
                    ${TARGET_CHIBIOS_NANOCLR_INCLUDE_DIRS}
                    ${chibios_SOURCE_DIR}/os/hal/boards/${TARGET_BOARD})

            add_dependencies(${target}.elf nano::NF_Debugger)

        endif()

        nf_add_lib_native_assemblies(
            EXTRA_INCLUDES
                ${CHIBIOS_INCLUDE_DIRS}
                ${CHIBIOS_HAL_INCLUDE_DIRS}
                ${ChibiOSnfOverlay_INCLUDE_DIRS}
                ${CHIBIOS_CONTRIB_INCLUDE_DIRS}
                ${CHIBIOS_LWIP_INCLUDE_DIRS}
                ${SPIFFS_INCLUDE_DIRS}
                ${TARGET_CHIBIOS_COMMON_INCLUDE_DIRS}
                ${TARGET_CHIBIOS_NANOCLR_INCLUDE_DIRS}
                ${chibios_SOURCE_DIR}/os/hal/boards/${TARGET_BOARD})
        
        add_dependencies(${target}.elf nano::NF_NativeAssemblies)
        
        # nF feature: networking
        if(USE_NETWORKING_OPTION)

            nf_add_lib_network(
                BUILD_TARGET
                    ${target}
                EXTRA_SOURCES 
                    ${TARGET_LWIP_SOURCES}
                    ${CHIBIOS_LWIP_SOURCES}
                EXTRA_INCLUDES 
                    ${CHIBIOS_INCLUDE_DIRS}<commit_msg>Fix inclusion of STM32 Cube package in assemblies (#2067)<commit_after>#
# Copyright (c) .NET Foundation and Contributors
# See LICENSE file in the project root for full license information.
#

include(binutils.common)

function(nf_set_optimization_options target) 

    target_compile_options(${target} PRIVATE
        $<$<CONFIG:Debug>:-Og -femit-class-debug-always -g3 -ggdb>
        $<$<CONFIG:Release>:-O3 -flto -fuse-linker-plugin -fno-fat-lto-objects>
        $<$<CONFIG:MinSizeRel>:-Os -flto>
        $<$<CONFIG:RelWithDebInfo>:-Os -femit-class-debug-always -g3 -ggdb>
    )

endfunction()


function(nf_set_linker_file target linker_file_name)

    # set linker file name
    set_target_properties(${target} PROPERTIES LINK_FLAGS "-T${linker_file_name}")

endfunction()

# setting compile definitions for a target based on general build options
# TARGET parameter to set the target that's setting them for
# optional EXTRA_COMPILE_DEFINITIONS with compiler definitions to be added to the library
# optional BUILD_TARGET when target it's a library pass here the name ot the target that's building for (either nanoBooter or nanoCLR)
macro(nf_set_compile_definitions)

    # parse arguments
    cmake_parse_arguments(NFSCD "" "TARGET" "EXTRA_COMPILE_DEFINITIONS;BUILD_TARGET" ${ARGN})

    if(NOT NFSCD_TARGET OR "${NFSCD_TARGET}" STREQUAL "")
        message(FATAL_ERROR "Need to set TARGET argument when calling nf_set_compile_definitions()")
    endif()

    # definition for platform 
    # ChibiOS HAL community always include (nanoFramework overlay and official community contributions optionally)
    target_compile_definitions(${NFSCD_TARGET} PUBLIC -DHAL_USE_COMMUNITY )

    nf_common_compiler_definitions(TARGET ${NFSCD_TARGET} BUILD_TARGET ${NFSCD_BUILD_TARGET})

    # include extra compiler definitions
    target_compile_definitions(${NFSCD_TARGET} PUBLIC ${NFSCD_EXTRA_COMPILE_DEFINITIONS})

endmacro()

function(nf_set_stm32_target_series)
    # process target series, which is in the format "STM32F4xx"
    string(REPLACE "STM32" "" TARGET_SERIES_SHORT_1 "${TARGET_SERIES}")
    string(REPLACE "xx" "" TARGET_SERIES_SHORT "${TARGET_SERIES_SHORT_1}")
    
    # store the series short name for later use
    set(TARGET_SERIES_SHORT ${TARGET_SERIES_SHORT} CACHE INTERNAL "STM32 target series short name")

endfunction()

# Add platform packages specific to ChibiOS
# To be called from target CMakeList.txt
# optional TARGET argument with target name
macro(nf_add_platform_packages)

    # parse arguments
    cmake_parse_arguments(NFAPP "" "TARGET" "" ${ARGN})
   
    # packages common to all targets
    find_package(ChibiOS REQUIRED QUIET)
    find_package(ChibiOS_${TARGET_SERIES_SHORT}_HAL REQUIRED QUIET)
    find_package(ChibiOSnfOverlay REQUIRED QUIET)

    # ChibiOS contrib repo
    if(CHIBIOS_CONTRIB_REQUIRED)
        find_package(ChibiOS-Contrib REQUIRED QUIET)
    endif()

    if(USE_FILESYSTEM_OPTION)
        find_package(CHIBIOS_FATFS REQUIRED QUIET)
    endif()

    # SPIFFS
    if(NF_FEATURE_USE_SPIFFS)
        find_package(STM32F7_CubePackage REQUIRED QUIET)
        find_package(SPIFFS REQUIRED QUIET)
    endif()

    if(STM32_CUBE_PACKAGE_REQUIRED)
        find_package(${TARGET_STM32_CUBE_PACKAGE}_CubePackage REQUIRED QUIET)
    endif()
    
    # packages specific for nanoBooter
    if("${NFAPP_TARGET}" STREQUAL "${NANOBOOTER_PROJECT_NAME}")
        # no packages for booter
    endif()

    # packages specific for nanoCRL
    if("${NFAPP_TARGET}" STREQUAL "${NANOCLR_PROJECT_NAME}")

        if(USE_NETWORKING_OPTION)

            find_package(NF_Network REQUIRED QUIET)
            find_package(CHIBIOS_LWIP REQUIRED QUIET)

            # security provider is mbedTLS
            if(USE_SECURITY_MBEDTLS_OPTION)
                find_package(mbedTLS REQUIRED QUIET)
            endif()

        endif()

    endif()
 
endmacro()

# Add ChibiOS platform dependencies to a specific CMake target
# To be called from target CMakeList.txt
macro(nf_add_platform_dependencies target)

    nf_add_common_dependencies(${target})

    # dependencies specific to nanoCRL
    if("${target}" STREQUAL "${NANOCLR_PROJECT_NAME}")

        nf_add_lib_coreclr(
            EXTRA_INCLUDES
                ${CHIBIOS_INCLUDE_DIRS}
                ${CHIBIOS_HAL_INCLUDE_DIRS}
                ${ChibiOSnfOverlay_INCLUDE_DIRS}
                ${CHIBIOS_CONTRIB_INCLUDE_DIRS}
                ${TARGET_CHIBIOS_COMMON_INCLUDE_DIRS}
                ${TARGET_CHIBIOS_NANOCLR_INCLUDE_DIRS}
                ${chibios_SOURCE_DIR}/os/hal/boards/${TARGET_BOARD})

        add_dependencies(${target}.elf nano::NF_CoreCLR)

        nf_add_lib_wireprotocol(
            EXTRA_INCLUDES
                ${CHIBIOS_INCLUDE_DIRS}
                ${CHIBIOS_HAL_INCLUDE_DIRS}
                ${ChibiOSnfOverlay_INCLUDE_DIRS}
                ${CHIBIOS_CONTRIB_INCLUDE_DIRS}
                ${TARGET_CHIBIOS_COMMON_INCLUDE_DIRS}
                ${TARGET_CHIBIOS_NANOCLR_INCLUDE_DIRS}
                ${chibios_SOURCE_DIR}/os/hal/boards/${TARGET_BOARD})

        add_dependencies(${target}.elf nano::WireProtocol)

        if(NF_FEATURE_DEBUGGER)

            nf_add_lib_debugger(
                EXTRA_INCLUDES
                    ${CHIBIOS_INCLUDE_DIRS}
                    ${CHIBIOS_HAL_INCLUDE_DIRS}
                    ${ChibiOSnfOverlay_INCLUDE_DIRS}
                    ${CHIBIOS_CONTRIB_INCLUDE_DIRS}
                    ${CHIBIOS_LWIP_INCLUDE_DIRS}
                    ${TARGET_CHIBIOS_COMMON_INCLUDE_DIRS}
                    ${TARGET_CHIBIOS_NANOCLR_INCLUDE_DIRS}
                    ${chibios_SOURCE_DIR}/os/hal/boards/${TARGET_BOARD})

            add_dependencies(${target}.elf nano::NF_Debugger)

        endif()

        nf_add_lib_native_assemblies(
            EXTRA_INCLUDES
                ${CHIBIOS_INCLUDE_DIRS}
                ${CHIBIOS_HAL_INCLUDE_DIRS}
                ${${TARGET_STM32_CUBE_PACKAGE}_CubePackage_INCLUDE_DIRS}
                ${ChibiOSnfOverlay_INCLUDE_DIRS}
                ${CHIBIOS_CONTRIB_INCLUDE_DIRS}
                ${CHIBIOS_LWIP_INCLUDE_DIRS}
                ${SPIFFS_INCLUDE_DIRS}
                ${TARGET_CHIBIOS_COMMON_INCLUDE_DIRS}
                ${TARGET_CHIBIOS_NANOCLR_INCLUDE_DIRS}
                ${chibios_SOURCE_DIR}/os/hal/boards/${TARGET_BOARD})
        
        add_dependencies(${target}.elf nano::NF_NativeAssemblies)
        
        # nF feature: networking
        if(USE_NETWORKING_OPTION)

            nf_add_lib_network(
                BUILD_TARGET
                    ${target}
                EXTRA_SOURCES 
                    ${TARGET_LWIP_SOURCES}
                    ${CHIBIOS_LWIP_SOURCES}
                EXTRA_INCLUDES 
                    ${CHIBIOS_INCLUDE_DIRS}
{'fraction_non_alphanumeric': 0.07787650265063839, 'fraction_numerical': 0.003733293511535877, 'mean_word_length': 2.8444316877152698, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5258240', 'n_tokens_mistral': 4744, 'n_tokens_neox': 4279, 'n_words': 768}