cmake: iar/msvc: Set base compile and link options target by target

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
This commit is contained in:
Ronald Cron 2024-10-09 14:54:43 +02:00
parent d9e1109d23
commit 6f9d508714
2 changed files with 32 additions and 24 deletions

View File

@ -217,6 +217,10 @@ function(set_base_compile_options target)
set_gnu_base_compile_options(${target})
elseif(CMAKE_COMPILER_IS_CLANG)
set_clang_base_compile_options(${target})
elseif(CMAKE_COMPILER_IS_IAR)
set_iar_base_compile_options(${target})
elseif(CMAKE_COMPILER_IS_MSVC)
set_msvc_base_compile_options(${target})
endif()
endfunction(set_base_compile_options)
@ -305,24 +309,24 @@ function(set_clang_base_compile_options target)
endif(MBEDTLS_FATAL_WARNINGS)
endfunction(set_clang_base_compile_options)
if(CMAKE_COMPILER_IS_IAR)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --warn_about_c_style_casts")
set(CMAKE_C_FLAGS_RELEASE "-Ohz")
set(CMAKE_C_FLAGS_DEBUG "--debug -On")
function(set_iar_base_compile_options target)
target_compile_options(${target} PRIVATE --warn_about_c_style_casts)
target_compile_options(${target} PRIVATE $<$<CONFIG:Release>:-Ohz>)
target_compile_options(${target} PRIVATE $<$<CONFIG:Debug>:--debug -On>)
if(MBEDTLS_FATAL_WARNINGS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --warnings_are_errors")
target_compile_options(${target} PRIVATE --warnings_are_errors)
endif(MBEDTLS_FATAL_WARNINGS)
endif(CMAKE_COMPILER_IS_IAR)
endfunction(set_iar_base_compile_options)
if(CMAKE_COMPILER_IS_MSVC)
function(set_msvc_base_compile_options target)
# Strictest warnings, UTF-8 source and execution charset
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3 /utf-8")
target_compile_options(${target} PRIVATE /W3 /utf-8)
if(MBEDTLS_FATAL_WARNINGS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
target_compile_options(${target} PRIVATE /WX)
endif(MBEDTLS_FATAL_WARNINGS)
endif(CMAKE_COMPILER_IS_MSVC)
endfunction(set_msvc_base_compile_options)
if(CMAKE_BUILD_TYPE STREQUAL "Check" AND TEST_CPP)
set(CMAKE_CXX_STANDARD 11)

View File

@ -182,6 +182,10 @@ function(set_base_compile_options target)
set_gnu_base_compile_options(${target})
elseif(CMAKE_COMPILER_IS_CLANG)
set_clang_base_compile_options(${target})
elseif(CMAKE_COMPILER_IS_IAR)
set_iar_base_compile_options(${target})
elseif(CMAKE_COMPILER_IS_MSVC)
set_msvc_base_compile_options(${target})
endif()
endfunction(set_base_compile_options)
@ -270,24 +274,24 @@ function(set_clang_base_compile_options target)
endif(MBEDTLS_FATAL_WARNINGS)
endfunction(set_clang_base_compile_options)
if(CMAKE_COMPILER_IS_IAR)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --warn_about_c_style_casts")
set(CMAKE_C_FLAGS_RELEASE "-Ohz")
set(CMAKE_C_FLAGS_DEBUG "--debug -On")
function(set_iar_base_compile_options target)
target_compile_options(${target} PRIVATE --warn_about_c_style_casts)
target_compile_options(${target} PRIVATE $<$<CONFIG:Release>:-Ohz>)
target_compile_options(${target} PRIVATE $<$<CONFIG:Debug>:--debug -On>)
if(TF_PSA_CRYPTO_FATAL_WARNINGS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --warnings_are_errors")
endif(TF_PSA_CRYPTO_FATAL_WARNINGS)
endif(CMAKE_COMPILER_IS_IAR)
if(MBEDTLS_FATAL_WARNINGS)
target_compile_options(${target} PRIVATE --warnings_are_errors)
endif(MBEDTLS_FATAL_WARNINGS)
endfunction(set_iar_base_compile_options)
if(CMAKE_COMPILER_IS_MSVC)
function(set_msvc_base_compile_options target)
# Strictest warnings, UTF-8 source and execution charset
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3 /utf-8")
target_compile_options(${target} PRIVATE /W3 /utf-8)
if(TF_PSA_CRYPTO_FATAL_WARNINGS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
endif(TF_PSA_CRYPTO_FATAL_WARNINGS)
endif(CMAKE_COMPILER_IS_MSVC)
if(MBEDTLS_FATAL_WARNINGS)
target_compile_options(${target} PRIVATE /WX)
endif(MBEDTLS_FATAL_WARNINGS)
endfunction(set_msvc_base_compile_options)
if(CMAKE_BUILD_TYPE STREQUAL "Check" AND TEST_CPP)
set(CMAKE_CXX_STANDARD 11)