1 function(clr_unknown_arch)
3 message(FATAL_ERROR "Only AMD64, ARM64, ARM and I386 are supported")
4 elseif(CLR_CROSS_COMPONENTS_BUILD)
5 message(FATAL_ERROR "Only AMD64, I386 are supported for cross-architecture component")
7 message(FATAL_ERROR "Only AMD64, ARM64 and ARM are supported")
11 # Build a list of compiler definitions by putting -D in front of each define.
12 function(get_compile_definitions DefinitionName)
13 # Get the current list of definitions
14 get_directory_property(COMPILE_DEFINITIONS_LIST COMPILE_DEFINITIONS)
16 foreach(DEFINITION IN LISTS COMPILE_DEFINITIONS_LIST)
17 if (${DEFINITION} MATCHES "^\\$<\\$<CONFIG:([^>]+)>:([^>]+)>$")
18 # The entries that contain generator expressions must have the -D inside of the
19 # expression. So we transform e.g. $<$<CONFIG:Debug>:_DEBUG> to $<$<CONFIG:Debug>:-D_DEBUG>
20 set(DEFINITION "$<$<CONFIG:${CMAKE_MATCH_1}>:-D${CMAKE_MATCH_2}>")
22 set(DEFINITION -D${DEFINITION})
24 list(APPEND DEFINITIONS ${DEFINITION})
26 set(${DefinitionName} ${DEFINITIONS} PARENT_SCOPE)
27 endfunction(get_compile_definitions)
29 # Build a list of include directories
30 function(get_include_directories IncludeDirectories)
31 get_directory_property(dirs INCLUDE_DIRECTORIES)
32 foreach(dir IN LISTS dirs)
34 if (CLR_CMAKE_PLATFORM_ARCH_ARM AND WIN32)
35 list(APPEND INC_DIRECTORIES /I${dir})
37 list(APPEND INC_DIRECTORIES -I${dir})
38 endif(CLR_CMAKE_PLATFORM_ARCH_ARM AND WIN32)
41 set(${IncludeDirectories} ${INC_DIRECTORIES} PARENT_SCOPE)
42 endfunction(get_include_directories)
44 # Build a list of include directories for consumption by the assembler
45 function(get_include_directories_asm IncludeDirectories)
46 get_directory_property(dirs INCLUDE_DIRECTORIES)
48 if (CLR_CMAKE_PLATFORM_ARCH_ARM AND WIN32)
49 list(APPEND INC_DIRECTORIES "-I ")
52 foreach(dir IN LISTS dirs)
53 if (CLR_CMAKE_PLATFORM_ARCH_ARM AND WIN32)
54 list(APPEND INC_DIRECTORIES ${dir};)
56 list(APPEND INC_DIRECTORIES -I${dir})
60 set(${IncludeDirectories} ${INC_DIRECTORIES} PARENT_SCOPE)
61 endfunction(get_include_directories_asm)
63 # Set the passed in RetSources variable to the list of sources with added current source directory
64 # to form absolute paths.
65 # The parameters after the RetSources are the input files.
66 function(convert_to_absolute_path RetSources)
68 foreach(Source IN LISTS Sources)
69 list(APPEND AbsolutePathSources ${CMAKE_CURRENT_SOURCE_DIR}/${Source})
71 set(${RetSources} ${AbsolutePathSources} PARENT_SCOPE)
72 endfunction(convert_to_absolute_path)
74 #Preprocess exports definition file
75 function(preprocess_def_file inputFilename outputFilename)
76 get_compile_definitions(PREPROCESS_DEFINITIONS)
77 get_include_directories(ASM_INCLUDE_DIRECTORIES)
79 OUTPUT ${outputFilename}
80 COMMAND ${CMAKE_CXX_COMPILER} ${ASM_INCLUDE_DIRECTORIES} /P /EP /TC ${PREPROCESS_DEFINITIONS} /Fi${outputFilename} ${inputFilename}
81 DEPENDS ${inputFilename}
82 COMMENT "Preprocessing ${inputFilename} - ${CMAKE_CXX_COMPILER} ${ASM_INCLUDE_DIRECTORIES} /P /EP /TC ${PREPROCESS_DEFINITIONS} /Fi${outputFilename} ${inputFilename}"
85 set_source_files_properties(${outputFilename}
86 PROPERTIES GENERATED TRUE)
89 function(generate_exports_file inputFilename outputFilename)
91 if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
92 set(AWK_SCRIPT generateexportedsymbols.awk)
94 set(AWK_SCRIPT generateversionscript.awk)
95 endif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
98 OUTPUT ${outputFilename}
99 COMMAND ${AWK} -f ${CMAKE_SOURCE_DIR}/${AWK_SCRIPT} ${inputFilename} >${outputFilename}
100 DEPENDS ${inputFilename} ${CMAKE_SOURCE_DIR}/${AWK_SCRIPT}
101 COMMENT "Generating exports file ${outputFilename}"
103 set_source_files_properties(${outputFilename}
104 PROPERTIES GENERATED TRUE)
107 function(add_precompiled_header header cppFile targetSources)
109 set(precompiledBinary "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/stdafx.pch")
111 set_source_files_properties(${cppFile}
112 PROPERTIES COMPILE_FLAGS "/Yc\"${header}\" /Fp\"${precompiledBinary}\""
113 OBJECT_OUTPUTS "${precompiledBinary}")
114 set_source_files_properties(${${targetSources}}
115 PROPERTIES COMPILE_FLAGS "/Yu\"${header}\" /Fp\"${precompiledBinary}\""
116 OBJECT_DEPENDS "${precompiledBinary}")
117 # Add cppFile to SourcesVar
118 set(${targetSources} ${${targetSources}} ${cppFile} PARENT_SCOPE)
122 function(strip_symbols targetName outputFilename)
123 if (CLR_CMAKE_PLATFORM_UNIX)
124 if (UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE)
126 # On the older version of cmake (2.8.12) used on Ubuntu 14.04 the TARGET_FILE
127 # generator expression doesn't work correctly returning the wrong path and on
128 # the newer cmake versions the LOCATION property isn't supported anymore.
129 if (CMAKE_VERSION VERSION_EQUAL 3.0 OR CMAKE_VERSION VERSION_GREATER 3.0)
130 set(strip_source_file $<TARGET_FILE:${targetName}>)
132 get_property(strip_source_file TARGET ${targetName} PROPERTY LOCATION)
135 if (CMAKE_SYSTEM_NAME STREQUAL Darwin)
136 set(strip_destination_file ${strip_source_file}.dwarf)
142 COMMAND ${DSYMUTIL} --flat --minimize ${strip_source_file}
143 COMMAND ${STRIP} -S ${strip_source_file}
144 COMMENT Stripping symbols from ${strip_source_file} into file ${strip_destination_file}
146 else (CMAKE_SYSTEM_NAME STREQUAL Darwin)
147 set(strip_destination_file ${strip_source_file}.dbg)
153 COMMAND ${OBJCOPY} --only-keep-debug ${strip_source_file} ${strip_destination_file}
154 COMMAND ${OBJCOPY} --strip-debug ${strip_source_file}
155 COMMAND ${OBJCOPY} --add-gnu-debuglink=${strip_destination_file} ${strip_source_file}
156 COMMENT Stripping symbols from ${strip_source_file} into file ${strip_destination_file}
158 endif (CMAKE_SYSTEM_NAME STREQUAL Darwin)
160 set(${outputFilename} ${strip_destination_file} PARENT_SCOPE)
161 endif(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE)
162 endif(CLR_CMAKE_PLATFORM_UNIX)
165 function(install_clr targetName)
166 list(FIND CLR_CROSS_COMPONENTS_LIST ${targetName} INDEX)
167 if (NOT DEFINED CLR_CROSS_COMPONENTS_LIST OR NOT ${INDEX} EQUAL -1)
168 strip_symbols(${targetName} strip_destination_file)
169 # On the older version of cmake (2.8.12) used on Ubuntu 14.04 the TARGET_FILE
170 # generator expression doesn't work correctly returning the wrong path and on
171 # the newer cmake versions the LOCATION property isn't supported anymore.
172 if(CMAKE_VERSION VERSION_EQUAL 3.0 OR CMAKE_VERSION VERSION_GREATER 3.0)
173 set(install_source_file $<TARGET_FILE:${targetName}>)
175 get_property(install_source_file TARGET ${targetName} PROPERTY LOCATION)
178 install(PROGRAMS ${install_source_file} DESTINATION .)
180 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${targetName}.pdb DESTINATION PDB)
182 install(FILES ${strip_destination_file} DESTINATION .)
184 if(CLR_CMAKE_PGO_INSTRUMENT)
186 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${targetName}.pgd DESTINATION PGD OPTIONAL)
192 function(_add_executable)
194 add_executable(${ARGV} ${VERSION_FILE_PATH})
196 add_executable(${ARGV})
198 list(FIND CLR_CROSS_COMPONENTS_LIST ${ARGV0} INDEX)
199 if (DEFINED CLR_CROSS_COMPONENTS_LIST AND ${INDEX} EQUAL -1)
200 set_target_properties(${ARGV0} PROPERTIES EXCLUDE_FROM_ALL 1)
204 function(_add_library)
206 add_library(${ARGV} ${VERSION_FILE_PATH})
210 list(FIND CLR_CROSS_COMPONENTS_LIST ${ARGV0} INDEX)
211 if (DEFINED CLR_CROSS_COMPONENTS_LIST AND ${INDEX} EQUAL -1)
212 set_target_properties(${ARGV0} PROPERTIES EXCLUDE_FROM_ALL 1)
217 if(NOT DEFINED CLR_CROSS_COMPONENTS_BUILD)
222 function(verify_dependencies targetName errorMessage)
223 # We don't need to verify dependencies on OSX, since missing dependencies
224 # result in link error over there.
225 if (NOT CLR_CMAKE_PLATFORM_DARWIN)
230 COMMAND ${CMAKE_SOURCE_DIR}/verify-so.sh
231 $<TARGET_FILE:${targetName}>
233 COMMENT "Verifying ${targetName} dependencies"