[Tizen] Unify dnetmemoryenumlib terms to match the codebase (#291)
[platform/upstream/coreclr.git] / configurecompiler.cmake
index a5e44bb..0f45944 100644 (file)
@@ -6,6 +6,9 @@ set(CMAKE_C_STANDARD_REQUIRED ON)
 set(CMAKE_CXX_STANDARD 11)
 set(CMAKE_CXX_STANDARD_REQUIRED ON)
 
+# All code we build should be compiled as position independent
+set(CMAKE_POSITION_INDEPENDENT_CODE ON)
+
 set(CLR_DEFINES_DEBUG_INIT              DEBUG _DEBUG _DBG URTBLDENV_FRIENDLY=Checked BUILDENV_CHECKED=1)
 set(CLR_DEFINES_CHECKED_INIT            DEBUG _DEBUG _DBG URTBLDENV_FRIENDLY=Checked BUILDENV_CHECKED=1)
 set(CLR_DEFINES_RELEASE_INIT            NDEBUG URTBLDENV_FRIENDLY=Retail)
@@ -300,6 +303,17 @@ elseif (CLR_CMAKE_PLATFORM_UNIX)
     message(FATAL_ERROR "Unknown build type! Set CMAKE_BUILD_TYPE to DEBUG, CHECKED, RELEASE, or RELWITHDEBINFO!")
   endif ()
 
+  if(DEFINED ENV{TIZEN_ASAN_ENVIRONMENT})
+    if (CLR_CMAKE_PLATFORM_UNIX_ARM OR CLR_CMAKE_PLATFORM_UNIX_AMD64)
+      message(STATUS "TIZEN_ASAN_ENVIRONMENT is enabled.")
+      # add definitions to enable ASan support for only external libraries (supported only Tizen)
+      add_definitions(-DTIZEN_ASAN_ENVIRONMENT -DHAS_ADDRESS_SANITIZER)
+      set(TIZEN_ASAN_ENVIRONMENT 1)
+    else()
+      message(STATUS "TIZEN_ASAN_ENVIRONMENT cannot be enabled. Current arch is not supported.")
+    endif()
+  endif()
+
   # set the CLANG sanitizer flags for debug build
   if(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL DEBUG OR UPPERCASE_CMAKE_BUILD_TYPE STREQUAL CHECKED)
     # obtain settings from running enablesanitizers.sh
@@ -322,10 +336,9 @@ elseif (CLR_CMAKE_PLATFORM_UNIX)
       endif ()
 
       # -fdata-sections -ffunction-sections: each function has own section instead of one per .o file (needed for --gc-sections)
-      # -fPIC: enable Position Independent Code normally just for shared libraries but required when linking with address sanitizer
       # -O1: optimization level used instead of -O0 to avoid compile error "invalid operand for inline asm constraint"
-      set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${CLR_SANITIZE_CXX_FLAGS} -fdata-sections -ffunction-sections -fPIC -O1")
-      set(CMAKE_CXX_FLAGS_CHECKED "${CMAKE_CXX_FLAGS_CHECKED} ${CLR_SANITIZE_CXX_FLAGS} -fdata-sections -ffunction-sections -fPIC -O1")
+      set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${CLR_SANITIZE_CXX_FLAGS} -fdata-sections -ffunction-sections  -O1")
+      set(CMAKE_CXX_FLAGS_CHECKED "${CMAKE_CXX_FLAGS_CHECKED} ${CLR_SANITIZE_CXX_FLAGS} -fdata-sections -ffunction-sections  -O1")
 
       set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${CLR_SANITIZE_LINK_FLAGS}")
       set(CMAKE_EXE_LINKER_FLAGS_CHECKED "${CMAKE_EXE_LINKER_FLAGS_CHECKED} ${CLR_SANITIZE_LINK_FLAGS}")
@@ -335,6 +348,11 @@ elseif (CLR_CMAKE_PLATFORM_UNIX)
       set(CMAKE_SHARED_LINKER_FLAGS_CHECKED "${CMAKE_SHARED_LINKER_FLAGS_CHECKED} ${CLR_SANITIZE_LINK_FLAGS} -Wl,--gc-sections")
     endif ()
   endif(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL DEBUG OR UPPERCASE_CMAKE_BUILD_TYPE STREQUAL CHECKED)
+
+  # This linker option causes executables we build to be marked as containing position independent code.
+  # It is necessary to make ASLR work for executables.
+  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie" )
+
 endif(WIN32)
 
 # CLR_ADDITIONAL_LINKER_FLAGS - used for passing additional arguments to linker
@@ -366,7 +384,7 @@ if (CLR_CMAKE_PLATFORM_ARCH_AMD64)
   add_definitions(-D_AMD64_)
   add_definitions(-D_WIN64)
   add_definitions(-DAMD64)
-  add_definitions(-DBIT64=1)
+  add_definitions(-DBIT64)
 elseif (CLR_CMAKE_PLATFORM_ARCH_I386)
   add_definitions(-D_X86_)
 elseif (CLR_CMAKE_PLATFORM_ARCH_ARM)
@@ -376,7 +394,7 @@ elseif (CLR_CMAKE_PLATFORM_ARCH_ARM64)
   add_definitions(-D_ARM64_)
   add_definitions(-DARM64)
   add_definitions(-D_WIN64)
-  add_definitions(-DBIT64=1)
+  add_definitions(-DBIT64)
 else ()
   clr_unknown_arch()
 endif ()
@@ -402,7 +420,7 @@ if (CLR_CMAKE_PLATFORM_UNIX)
 endif(CLR_CMAKE_PLATFORM_UNIX)
 
 if (CLR_CMAKE_PLATFORM_UNIX)
-  add_definitions(-DPLATFORM_UNIX=1)
+  add_definitions(-DPLATFORM_UNIX)
 
   if(CLR_CMAKE_PLATFORM_DARWIN)
     message("Detected OSX x86_64")
@@ -418,7 +436,7 @@ if (CLR_CMAKE_PLATFORM_UNIX)
 endif(CLR_CMAKE_PLATFORM_UNIX)
 
 if (WIN32)
-  add_definitions(-DPLATFORM_WINDOWS=1)
+  add_definitions(-DPLATFORM_WINDOWS)
 
   # Define the CRT lib references that link into Desktop imports
   set(STATIC_MT_CRT_LIB  "libcmt$<$<OR:$<CONFIG:Debug>,$<CONFIG:Checked>>:d>.lib")
@@ -503,11 +521,15 @@ if (CLR_CMAKE_PLATFORM_UNIX)
     # to a struct or a class that has virtual members or a base class. In that case, clang
     # may not generate the same object layout as MSVC.
     add_compile_options(-Wno-incompatible-ms-struct)
+    # Do not convert a #warning into an #error
+    add_compile_options("-Wno-error=#warnings")
   else()
     add_compile_options(-Wno-unused-variable)
     add_compile_options(-Wno-unused-but-set-variable)
     add_compile_options(-fms-extensions)
     add_compile_options(-Wno-unknown-pragmas)
+    # Do not convert a #warning into an #error
+    add_compile_options(-Wno-error=cpp)
     if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)
       add_compile_options(-Wno-nonnull-compare)
     endif()
@@ -537,13 +559,25 @@ if(CLR_CMAKE_PLATFORM_UNIX_ARM)
    # we have to set the triple by adding a compiler argument
    add_compile_options(-mthumb)
    add_compile_options(-mfpu=vfpv3)
-   add_compile_options(-march=armv7-a)
    if(ARM_SOFTFP)
      add_definitions(-DARM_SOFTFP)
      add_compile_options(-mfloat-abi=softfp)
+     if("$ENV{__DistroRid}" MATCHES "tizen.*")
+      add_compile_options(-target armv7l-tizen-linux-gnueabi)
+     else()
+      add_compile_options(-march=armv7-a)
+     endif()
+   else()
+    add_compile_options(-march=armv7-a)
    endif(ARM_SOFTFP)
 endif(CLR_CMAKE_PLATFORM_UNIX_ARM)
 
+if(CLR_CMAKE_PLATFORM_UNIX_ARM64)
+  if("$ENV{__DistroRid}" MATCHES "tizen.*")
+    add_compile_options(-target aarch64-tizen-linux-gnu)
+  endif()
+endif(CLR_CMAKE_PLATFORM_UNIX_ARM64)
+
 if(CLR_CMAKE_PLATFORM_UNIX)
   add_compile_options(${CLR_ADDITIONAL_COMPILER_OPTIONS})
 endif(CLR_CMAKE_PLATFORM_UNIX)