From ab2b85b587d427304f31beb1c003de34828f63be Mon Sep 17 00:00:00 2001 From: Devin Nakamura Date: Thu, 25 Oct 2018 11:26:46 -0400 Subject: [PATCH] CMake: rework compiler component ASM defines Rework handling of defines for compiler so that it can handle GNU assembler and NASM Signed-off-by: Devin Nakamura --- cmake/modules/OmrCompilerSupport.cmake | 48 +++++++++++++++++++++++++- cmake/modules/platform/arch/x86.cmake | 4 --- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/cmake/modules/OmrCompilerSupport.cmake b/cmake/modules/OmrCompilerSupport.cmake index 9ba36184797..2b85ccb6b82 100644 --- a/cmake/modules/OmrCompilerSupport.cmake +++ b/cmake/modules/OmrCompilerSupport.cmake @@ -245,6 +245,34 @@ function(omr_inject_object_modification_targets result compiler_name) set(${result} ${arg} PARENT_SCOPE) endfunction(omr_inject_object_modification_targets) +# make_gnu_asm_defines(output_var ...) +# Make output_var a string which will define each +# as an assembler define (rather than a c pre-processor define) +function(make_gnu_asm_defines output) + + foreach(arg IN LISTS ARGN) + set(clean_arg) + string(REGEX REPLACE "^-D" "" clean_arg "${arg}") + # if clean_arg already is of form FOO=BAR, append it as is + # otherwise we change it to FOO=1 + if(clean_arg MATCHES "=") + set(arg_str "${arg_str},--defsym,${clean_arg}") + else() + set(arg_str "${arg_str},--defsym,${clean_arg}=1") + endif() + endforeach() + + if(OMR_ENV_DATA64) + set(arg_str ",--64${arg_str}") + endif() + + # if we actually generated any string + # ie we were passed in any values + if(arg_str) + set(${output} "-Wa${arg_str}" PARENT_SCOPE) + endif() +endfunction(make_gnu_asm_defines) + # Setup the current scope for compiling the Testarossa compiler technology. Used in # conjunction with make_compiler_target -- Only can infect add_directory scope. macro(set_tr_compile_options) @@ -254,7 +282,25 @@ macro(set_tr_compile_options) set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} PARENT_SCOPE) # message("[set_tr_compile_options] Set CMAKE_CXX_FLAGS to ${CMAKE_CXX_FLAGS}") # message("[set_tr_compile_options] Set CMAKE_C_FLAGS to ${CMAKE_C_FLAGS}") - set(CMAKE_ASM_FLAGS ${TR_ASM_FLAGS} PARENT_SCOPE) + + set(TR_ASM_FLAGS "") + foreach(def IN LISTS TR_COMPILE_DEFINITIONS) + # Prepend leading '-D' only if required + if(def MATCHES "^-D") + set(TR_ASM_FLAGS "${TR_ASM_FLAGS} ${def}") + else() + set(TR_ASM_FLAGS "${TR_ASM_FLAGS} -D${def}") + endif() + endforeach() + + # We need special handling on x86 because we could be gnu or NASM assembler + if(OMR_ARCH_X86) + make_gnu_asm_defines(gnu_defines ${TR_COMPILE_DEFINITIONS}) + set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} ${gnu_defines}" PARENT_SCOPE) + set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} ${TR_ASM_FLAGS}" PARENT_SCOPE) + else() + set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} ${TR_ASM_FLAGS}" PARENT_SCOPE) + endif() endmacro(set_tr_compile_options) # Create an OMR Compiler component diff --git a/cmake/modules/platform/arch/x86.cmake b/cmake/modules/platform/arch/x86.cmake index 1c723e7d3d2..d4ecbf53457 100644 --- a/cmake/modules/platform/arch/x86.cmake +++ b/cmake/modules/platform/arch/x86.cmake @@ -44,10 +44,6 @@ if(OMR_ENV_DATA64) set(TR_HOST_SUBARCH amd64) set(TR_HOST_BITS 64) - #TODO the asm flags only work for GNU right now. - if(CMAKE_ASM_COMPILER_ID STREQUAL "GNU") - set(TR_ASM_FLAGS "-Wa,--64,--defsym,TR_HOST_X86=1,--defsym,TR_HOST_64BIT=1,--defsym,BITVECTOR_64BIT=1,--defsym,LINUX=1,--defsym,TR_TARGET_X86=1,--defsym,TR_TARGET_64BIT=1") - endif() else() list(APPEND TR_COMPILE_DEFINITIONS -DTR_HOST_32BIT -DTR_TARGET_32BIT)