Simplify emitter's RegEncoding
[platform/upstream/coreclr.git] / functions.cmake
index 9b77ad4..cbcc70f 100644 (file)
@@ -1,6 +1,8 @@
 function(clr_unknown_arch)
     if (WIN32)
-        message(FATAL_ERROR "Only AMD64, ARM64 and I386 are supported")
+        message(FATAL_ERROR "Only AMD64, ARM64, ARM and I386 are supported")
+    elseif(CLR_CROSS_COMPONENTS_BUILD)
+        message(FATAL_ERROR "Only AMD64, I386 host are supported for linux cross-architecture component")
     else()
         message(FATAL_ERROR "Only AMD64, ARM64 and ARM are supported")
     endif()
@@ -24,15 +26,40 @@ function(get_compile_definitions DefinitionName)
     set(${DefinitionName} ${DEFINITIONS} PARENT_SCOPE)
 endfunction(get_compile_definitions)
 
-# Build a list of include directories by putting -I in front of each include dir.
+# Build a list of include directories
 function(get_include_directories IncludeDirectories)
     get_directory_property(dirs INCLUDE_DIRECTORIES)
     foreach(dir IN LISTS dirs)
+
+      if (CLR_CMAKE_PLATFORM_ARCH_ARM AND WIN32)
+        list(APPEND INC_DIRECTORIES /I${dir})
+      else()
         list(APPEND INC_DIRECTORIES -I${dir})
+      endif(CLR_CMAKE_PLATFORM_ARCH_ARM AND WIN32)
+
     endforeach()
     set(${IncludeDirectories} ${INC_DIRECTORIES} PARENT_SCOPE)
 endfunction(get_include_directories)
 
+# Build a list of include directories for consumption by the assembler
+function(get_include_directories_asm IncludeDirectories)
+    get_directory_property(dirs INCLUDE_DIRECTORIES)
+    
+    if (CLR_CMAKE_PLATFORM_ARCH_ARM AND WIN32)
+        list(APPEND INC_DIRECTORIES "-I ")
+    endif()
+    
+    foreach(dir IN LISTS dirs)
+      if (CLR_CMAKE_PLATFORM_ARCH_ARM AND WIN32)
+        list(APPEND INC_DIRECTORIES ${dir};)
+      else()
+        list(APPEND INC_DIRECTORIES -I${dir})
+      endif()
+    endforeach()
+
+    set(${IncludeDirectories} ${INC_DIRECTORIES} PARENT_SCOPE)
+endfunction(get_include_directories_asm)
+
 # Set the passed in RetSources variable to the list of sources with added current source directory
 # to form absolute paths.
 # The parameters after the RetSources are the input files.
@@ -47,12 +74,12 @@ endfunction(convert_to_absolute_path)
 #Preprocess exports definition file
 function(preprocess_def_file inputFilename outputFilename)
   get_compile_definitions(PREPROCESS_DEFINITIONS)
-
+  get_include_directories(ASM_INCLUDE_DIRECTORIES)
   add_custom_command(
     OUTPUT ${outputFilename}
-    COMMAND ${CMAKE_CXX_COMPILER} /P /EP /TC ${PREPROCESS_DEFINITIONS}  /Fi${outputFilename}  ${inputFilename}
+    COMMAND ${CMAKE_CXX_COMPILER} ${ASM_INCLUDE_DIRECTORIES} /P /EP /TC ${PREPROCESS_DEFINITIONS}  /Fi${outputFilename}  ${inputFilename}
     DEPENDS ${inputFilename}
-    COMMENT "Preprocessing ${inputFilename}"
+    COMMENT "Preprocessing ${inputFilename} - ${CMAKE_CXX_COMPILER} ${ASM_INCLUDE_DIRECTORIES} /P /EP /TC ${PREPROCESS_DEFINITIONS}  /Fi${outputFilename}  ${inputFilename}"
   )
 
   set_source_files_properties(${outputFilename}
@@ -93,19 +120,19 @@ function(add_precompiled_header header cppFile targetSources)
 endfunction()
 
 function(strip_symbols targetName outputFilename)
-  if(CLR_CMAKE_PLATFORM_UNIX)
-    if(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE)
+  if (CLR_CMAKE_PLATFORM_UNIX)
+    if (STRIP_SYMBOLS)
 
       # On the older version of cmake (2.8.12) used on Ubuntu 14.04 the TARGET_FILE
       # generator expression doesn't work correctly returning the wrong path and on
       # the newer cmake versions the LOCATION property isn't supported anymore.
-      if(CMAKE_VERSION VERSION_EQUAL 3.0 OR CMAKE_VERSION VERSION_GREATER 3.0)
+      if (CMAKE_VERSION VERSION_EQUAL 3.0 OR CMAKE_VERSION VERSION_GREATER 3.0)
           set(strip_source_file $<TARGET_FILE:${targetName}>)
       else()
           get_property(strip_source_file TARGET ${targetName} PROPERTY LOCATION)
       endif()
 
-      if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
+      if (CMAKE_SYSTEM_NAME STREQUAL Darwin)
         set(strip_destination_file ${strip_source_file}.dwarf)
 
         add_custom_command(
@@ -116,7 +143,7 @@ function(strip_symbols targetName outputFilename)
           COMMAND ${STRIP} -S ${strip_source_file}
           COMMENT Stripping symbols from ${strip_source_file} into file ${strip_destination_file}
         )
-      elseif(CMAKE_SYSTEM_NAME STREQUAL Linux)
+      else (CMAKE_SYSTEM_NAME STREQUAL Darwin)
         set(strip_destination_file ${strip_source_file}.dbg)
 
         add_custom_command(
@@ -128,10 +155,10 @@ function(strip_symbols targetName outputFilename)
           COMMAND ${OBJCOPY} --add-gnu-debuglink=${strip_destination_file} ${strip_source_file}
           COMMENT Stripping symbols from ${strip_source_file} into file ${strip_destination_file}
         )
-      endif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
+      endif (CMAKE_SYSTEM_NAME STREQUAL Darwin)
 
       set(${outputFilename} ${strip_destination_file} PARENT_SCOPE)
-    endif(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE)
+    endif (STRIP_SYMBOLS)
   endif(CLR_CMAKE_PLATFORM_UNIX)
 endfunction()
 
@@ -154,6 +181,11 @@ function(install_clr targetName)
     else()  
         install(FILES ${strip_destination_file} DESTINATION .)  
     endif()  
+    if(CLR_CMAKE_PGO_INSTRUMENT)
+        if(WIN32)
+            install(FILES ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${targetName}.pgd DESTINATION PGD OPTIONAL)
+        endif()
+    endif()
   endif()  
 endfunction()
 
@@ -185,4 +217,20 @@ function(_install)
     if(NOT DEFINED CLR_CROSS_COMPONENTS_BUILD)
       install(${ARGV})
     endif()
-endfunction()
\ No newline at end of file
+endfunction()
+
+function(verify_dependencies targetName errorMessage)
+    # We don't need to verify dependencies on OSX, since missing dependencies
+    # result in link error over there.
+    if (NOT CLR_CMAKE_PLATFORM_DARWIN AND NOT CLR_CMAKE_PLATFORM_ANDROID)
+        add_custom_command(
+            TARGET ${targetName}
+            POST_BUILD
+            VERBATIM
+            COMMAND ${CMAKE_SOURCE_DIR}/verify-so.sh 
+                $<TARGET_FILE:${targetName}> 
+                ${errorMessage}
+            COMMENT "Verifying ${targetName} dependencies"
+        )
+    endif()
+endfunction()