1 function(clr_unknown_arch)
3 message(FATAL_ERROR "Only AMD64, ARM64 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 by putting -I in front of each include dir.
28 function(get_include_directories IncludeDirectories)
29 get_directory_property(dirs INCLUDE_DIRECTORIES)
30 foreach(dir IN LISTS dirs)
31 list(APPEND INC_DIRECTORIES -I${dir})
33 set(${IncludeDirectories} ${INC_DIRECTORIES} PARENT_SCOPE)
34 endfunction(get_include_directories)
36 # Set the passed in RetSources variable to the list of sources with added current source directory
37 # to form absolute paths.
38 # The parameters after the RetSources are the input files.
39 function(convert_to_absolute_path RetSources)
41 foreach(Source IN LISTS Sources)
42 list(APPEND AbsolutePathSources ${CMAKE_CURRENT_SOURCE_DIR}/${Source})
44 set(${RetSources} ${AbsolutePathSources} PARENT_SCOPE)
45 endfunction(convert_to_absolute_path)
47 #Preprocess exports definition file
48 function(preprocess_def_file inputFilename outputFilename)
49 get_compile_definitions(PREPROCESS_DEFINITIONS)
52 OUTPUT ${outputFilename}
53 COMMAND ${CMAKE_CXX_COMPILER} /P /EP /TC ${PREPROCESS_DEFINITIONS} /Fi${outputFilename} ${inputFilename}
54 DEPENDS ${inputFilename}
55 COMMENT "Preprocessing ${inputFilename}"
58 set_source_files_properties(${outputFilename}
59 PROPERTIES GENERATED TRUE)
62 function(generate_exports_file inputFilename outputFilename)
64 if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
65 set(AWK_SCRIPT generateexportedsymbols.awk)
67 set(AWK_SCRIPT generateversionscript.awk)
68 endif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
71 OUTPUT ${outputFilename}
72 COMMAND ${AWK} -f ${CMAKE_SOURCE_DIR}/${AWK_SCRIPT} ${inputFilename} >${outputFilename}
73 DEPENDS ${inputFilename} ${CMAKE_SOURCE_DIR}/${AWK_SCRIPT}
74 COMMENT "Generating exports file ${outputFilename}"
76 set_source_files_properties(${outputFilename}
77 PROPERTIES GENERATED TRUE)
80 function(add_precompiled_header header cppFile targetSources)
82 set(precompiledBinary "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/stdafx.pch")
84 set_source_files_properties(${cppFile}
85 PROPERTIES COMPILE_FLAGS "/Yc\"${header}\" /Fp\"${precompiledBinary}\""
86 OBJECT_OUTPUTS "${precompiledBinary}")
87 set_source_files_properties(${${targetSources}}
88 PROPERTIES COMPILE_FLAGS "/Yu\"${header}\" /Fp\"${precompiledBinary}\""
89 OBJECT_DEPENDS "${precompiledBinary}")
90 # Add cppFile to SourcesVar
91 set(${targetSources} ${${targetSources}} ${cppFile} PARENT_SCOPE)
95 function(strip_symbols targetName outputFilename)
96 if(CLR_CMAKE_PLATFORM_UNIX)
97 if(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE)
99 # On the older version of cmake (2.8.12) used on Ubuntu 14.04 the TARGET_FILE
100 # generator expression doesn't work correctly returning the wrong path and on
101 # the newer cmake versions the LOCATION property isn't supported anymore.
102 if(CMAKE_VERSION VERSION_EQUAL 3.0 OR CMAKE_VERSION VERSION_GREATER 3.0)
103 set(strip_source_file $<TARGET_FILE:${targetName}>)
105 get_property(strip_source_file TARGET ${targetName} PROPERTY LOCATION)
108 if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
109 set(strip_destination_file ${strip_source_file}.dwarf)
115 COMMAND ${DSYMUTIL} --flat --minimize ${strip_source_file}
116 COMMAND ${STRIP} -u -r ${strip_source_file}
117 COMMENT Stripping symbols from ${strip_source_file} into file ${strip_destination_file}
119 elseif(CMAKE_SYSTEM_NAME STREQUAL Linux)
120 set(strip_destination_file ${strip_source_file}.dbg)
126 COMMAND ${OBJCOPY} --only-keep-debug ${strip_source_file} ${strip_destination_file}
127 COMMAND ${OBJCOPY} --strip-debug ${strip_source_file}
128 COMMAND ${OBJCOPY} --add-gnu-debuglink=${strip_destination_file} ${strip_source_file}
129 COMMENT Stripping symbols from ${strip_source_file} into file ${strip_destination_file}
131 endif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
133 set(${outputFilename} ${strip_destination_file} PARENT_SCOPE)
134 endif(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE)
135 endif(CLR_CMAKE_PLATFORM_UNIX)
138 function(install_clr targetName)
139 list(FIND CLR_CROSS_COMPONENTS_LIST ${targetName} INDEX)
140 if (NOT DEFINED CLR_CROSS_COMPONENTS_LIST OR NOT ${INDEX} EQUAL -1)
141 strip_symbols(${targetName} strip_destination_file)
142 # On the older version of cmake (2.8.12) used on Ubuntu 14.04 the TARGET_FILE
143 # generator expression doesn't work correctly returning the wrong path and on
144 # the newer cmake versions the LOCATION property isn't supported anymore.
145 if(CMAKE_VERSION VERSION_EQUAL 3.0 OR CMAKE_VERSION VERSION_GREATER 3.0)
146 set(install_source_file $<TARGET_FILE:${targetName}>)
148 get_property(install_source_file TARGET ${targetName} PROPERTY LOCATION)
151 install(PROGRAMS ${install_source_file} DESTINATION .)
153 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${targetName}.pdb DESTINATION PDB)
155 install(FILES ${strip_destination_file} DESTINATION .)
160 function(_add_executable)
162 add_executable(${ARGV} ${VERSION_FILE_PATH})
164 add_executable(${ARGV})
166 list(FIND CLR_CROSS_COMPONENTS_LIST ${ARGV0} INDEX)
167 if (DEFINED CLR_CROSS_COMPONENTS_LIST AND ${INDEX} EQUAL -1)
168 set_target_properties(${ARGV0} PROPERTIES EXCLUDE_FROM_ALL 1)
172 function(_add_library)
174 add_library(${ARGV} ${VERSION_FILE_PATH})
178 list(FIND CLR_CROSS_COMPONENTS_LIST ${ARGV0} INDEX)
179 if (DEFINED CLR_CROSS_COMPONENTS_LIST AND ${INDEX} EQUAL -1)
180 set_target_properties(${ARGV0} PROPERTIES EXCLUDE_FROM_ALL 1)
185 if(NOT DEFINED CLR_CROSS_COMPONENTS_BUILD)