1 function(clr_unknown_arch)
3 message(FATAL_ERROR "Only AMD64, ARM64, ARM and I386 are supported")
5 message(FATAL_ERROR "Only AMD64, ARM64 and ARM are supported")
9 # Build a list of compiler definitions by putting -D in front of each define.
10 function(get_compile_definitions DefinitionName)
11 # Get the current list of definitions
12 get_directory_property(COMPILE_DEFINITIONS_LIST COMPILE_DEFINITIONS)
14 foreach(DEFINITION IN LISTS COMPILE_DEFINITIONS_LIST)
15 if (${DEFINITION} MATCHES "^\\$<\\$<CONFIG:([^>]+)>:([^>]+)>$")
16 # The entries that contain generator expressions must have the -D inside of the
17 # expression. So we transform e.g. $<$<CONFIG:Debug>:_DEBUG> to $<$<CONFIG:Debug>:-D_DEBUG>
18 set(DEFINITION "$<$<CONFIG:${CMAKE_MATCH_1}>:-D${CMAKE_MATCH_2}>")
20 set(DEFINITION -D${DEFINITION})
22 list(APPEND DEFINITIONS ${DEFINITION})
24 set(${DefinitionName} ${DEFINITIONS} PARENT_SCOPE)
25 endfunction(get_compile_definitions)
27 # Build a list of include directories
28 function(get_include_directories IncludeDirectories)
29 get_directory_property(dirs INCLUDE_DIRECTORIES)
30 foreach(dir IN LISTS dirs)
32 if (CLR_CMAKE_PLATFORM_ARCH_ARM AND WIN32)
33 list(APPEND INC_DIRECTORIES /I${dir})
35 list(APPEND INC_DIRECTORIES -I${dir})
36 endif(CLR_CMAKE_PLATFORM_ARCH_ARM AND WIN32)
39 set(${IncludeDirectories} ${INC_DIRECTORIES} PARENT_SCOPE)
40 endfunction(get_include_directories)
42 # Build a list of include directories for consumption by the assembler
43 function(get_include_directories_asm IncludeDirectories)
44 get_directory_property(dirs INCLUDE_DIRECTORIES)
46 if (CLR_CMAKE_PLATFORM_ARCH_ARM AND WIN32)
47 list(APPEND INC_DIRECTORIES "-I ")
50 foreach(dir IN LISTS dirs)
51 if (CLR_CMAKE_PLATFORM_ARCH_ARM AND WIN32)
52 list(APPEND INC_DIRECTORIES ${dir};)
54 list(APPEND INC_DIRECTORIES -I${dir})
58 set(${IncludeDirectories} ${INC_DIRECTORIES} PARENT_SCOPE)
59 endfunction(get_include_directories_asm)
61 # Set the passed in RetSources variable to the list of sources with added current source directory
62 # to form absolute paths.
63 # The parameters after the RetSources are the input files.
64 function(convert_to_absolute_path RetSources)
66 foreach(Source IN LISTS Sources)
67 list(APPEND AbsolutePathSources ${CMAKE_CURRENT_SOURCE_DIR}/${Source})
69 set(${RetSources} ${AbsolutePathSources} PARENT_SCOPE)
70 endfunction(convert_to_absolute_path)
72 #Preprocess exports definition file
73 function(preprocess_def_file inputFilename outputFilename)
74 get_compile_definitions(PREPROCESS_DEFINITIONS)
75 get_include_directories(ASM_INCLUDE_DIRECTORIES)
77 OUTPUT ${outputFilename}
78 COMMAND ${CMAKE_CXX_COMPILER} ${ASM_INCLUDE_DIRECTORIES} /P /EP /TC ${PREPROCESS_DEFINITIONS} /Fi${outputFilename} ${inputFilename}
79 DEPENDS ${inputFilename}
80 COMMENT "Preprocessing ${inputFilename} - ${CMAKE_CXX_COMPILER} ${ASM_INCLUDE_DIRECTORIES} /P /EP /TC ${PREPROCESS_DEFINITIONS} /Fi${outputFilename} ${inputFilename}"
83 set_source_files_properties(${outputFilename}
84 PROPERTIES GENERATED TRUE)
87 function(generate_exports_file inputFilename outputFilename)
89 if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
90 set(AWK_SCRIPT generateexportedsymbols.awk)
92 set(AWK_SCRIPT generateversionscript.awk)
93 endif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
96 OUTPUT ${outputFilename}
97 COMMAND ${AWK} -f ${CMAKE_SOURCE_DIR}/${AWK_SCRIPT} ${inputFilename} >${outputFilename}
98 DEPENDS ${inputFilename} ${CMAKE_SOURCE_DIR}/${AWK_SCRIPT}
99 COMMENT "Generating exports file ${outputFilename}"
101 set_source_files_properties(${outputFilename}
102 PROPERTIES GENERATED TRUE)
105 function(add_precompiled_header header cppFile targetSources)
107 set(precompiledBinary "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/stdafx.pch")
109 set_source_files_properties(${cppFile}
110 PROPERTIES COMPILE_FLAGS "/Yc\"${header}\" /Fp\"${precompiledBinary}\""
111 OBJECT_OUTPUTS "${precompiledBinary}")
112 set_source_files_properties(${${targetSources}}
113 PROPERTIES COMPILE_FLAGS "/Yu\"${header}\" /Fp\"${precompiledBinary}\""
114 OBJECT_DEPENDS "${precompiledBinary}")
115 # Add cppFile to SourcesVar
116 set(${targetSources} ${${targetSources}} ${cppFile} PARENT_SCOPE)
120 function(strip_symbols targetName outputFilename)
121 if (CLR_CMAKE_PLATFORM_UNIX)
122 if (UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE)
124 # On the older version of cmake (2.8.12) used on Ubuntu 14.04 the TARGET_FILE
125 # generator expression doesn't work correctly returning the wrong path and on
126 # the newer cmake versions the LOCATION property isn't supported anymore.
127 if (CMAKE_VERSION VERSION_EQUAL 3.0 OR CMAKE_VERSION VERSION_GREATER 3.0)
128 set(strip_source_file $<TARGET_FILE:${targetName}>)
130 get_property(strip_source_file TARGET ${targetName} PROPERTY LOCATION)
133 if (CMAKE_SYSTEM_NAME STREQUAL Darwin)
134 set(strip_destination_file ${strip_source_file}.dwarf)
140 COMMAND ${DSYMUTIL} --flat --minimize ${strip_source_file}
141 COMMAND ${STRIP} -S ${strip_source_file}
142 COMMENT Stripping symbols from ${strip_source_file} into file ${strip_destination_file}
144 else (CMAKE_SYSTEM_NAME STREQUAL Darwin)
145 set(strip_destination_file ${strip_source_file}.dbg)
151 COMMAND ${OBJCOPY} --only-keep-debug ${strip_source_file} ${strip_destination_file}
152 COMMAND ${OBJCOPY} --strip-debug ${strip_source_file}
153 COMMAND ${OBJCOPY} --add-gnu-debuglink=${strip_destination_file} ${strip_source_file}
154 COMMENT Stripping symbols from ${strip_source_file} into file ${strip_destination_file}
156 endif (CMAKE_SYSTEM_NAME STREQUAL Darwin)
158 set(${outputFilename} ${strip_destination_file} PARENT_SCOPE)
159 endif(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE)
160 endif(CLR_CMAKE_PLATFORM_UNIX)
163 function(install_clr targetName)
164 list(FIND CLR_CROSS_COMPONENTS_LIST ${targetName} INDEX)
165 if (NOT DEFINED CLR_CROSS_COMPONENTS_LIST OR NOT ${INDEX} EQUAL -1)
166 strip_symbols(${targetName} strip_destination_file)
167 # On the older version of cmake (2.8.12) used on Ubuntu 14.04 the TARGET_FILE
168 # generator expression doesn't work correctly returning the wrong path and on
169 # the newer cmake versions the LOCATION property isn't supported anymore.
170 if(CMAKE_VERSION VERSION_EQUAL 3.0 OR CMAKE_VERSION VERSION_GREATER 3.0)
171 set(install_source_file $<TARGET_FILE:${targetName}>)
173 get_property(install_source_file TARGET ${targetName} PROPERTY LOCATION)
176 install(PROGRAMS ${install_source_file} DESTINATION .)
178 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${targetName}.pdb DESTINATION PDB)
180 install(FILES ${strip_destination_file} DESTINATION .)
185 function(_add_executable)
187 add_executable(${ARGV} ${VERSION_FILE_PATH})
189 add_executable(${ARGV})
191 list(FIND CLR_CROSS_COMPONENTS_LIST ${ARGV0} INDEX)
192 if (DEFINED CLR_CROSS_COMPONENTS_LIST AND ${INDEX} EQUAL -1)
193 set_target_properties(${ARGV0} PROPERTIES EXCLUDE_FROM_ALL 1)
197 function(_add_library)
199 add_library(${ARGV} ${VERSION_FILE_PATH})
203 list(FIND CLR_CROSS_COMPONENTS_LIST ${ARGV0} INDEX)
204 if (DEFINED CLR_CROSS_COMPONENTS_LIST AND ${INDEX} EQUAL -1)
205 set_target_properties(${ARGV0} PROPERTIES EXCLUDE_FROM_ALL 1)
210 if(NOT DEFINED CLR_CROSS_COMPONENTS_BUILD)