source: flair-src/trunk/cmake-modules/GlobalCmakeFlair.cmake@ 374

Last change on this file since 374 was 374, checked in by Sanahuja Guillaume, 4 years ago

fix error of specific path to generic

File size: 10.6 KB
Line 
1if(DEFINED GLOBALCMAKEFLAIR_INCLUDED)
2 return()
3endif()
4
5SET(GLOBALCMAKEFLAIR_INCLUDED true)
6
7if(NOT DEFINED ENV{FLAIR_ROOT})
8 message(FATAL_ERROR "variable FLAIR_ROOT not defined")
9endif()
10
11include($ENV{FLAIR_ROOT}/flair-src/cmake-modules/ColoredMessage.cmake)
12
13#check if we have a flair-hds directory
14if (IS_DIRECTORY $ENV{FLAIR_ROOT}/flair-hds )
15 info("found flair-hds directory")
16 SET(FOUND_HDS_DIR TRUE)
17endif()
18
19include($ENV{FLAIR_ROOT}/flair-src/cmake-modules/ArchDir.cmake)
20
21list(APPEND CMAKE_MODULE_PATH $ENV{FLAIR_ROOT}/flair-src/cmake-modules/)
22
23#default executable ouput paths
24if(NOT DEFINED TARGET_EXECUTABLE_OUTPUT_PATH)
25 SET(TARGET_EXECUTABLE_OUTPUT_PATH bin)
26endif()
27
28#add definitions for archs
29if("${CMAKE_SYSTEM_PROCESSOR_DEFAULTTUNE}" MATCHES "armv7a-neon")
30 ADD_DEFINITIONS(-DARMV7A)
31endif()
32
33if("${CMAKE_SYSTEM_PROCESSOR_DEFAULTTUNE}" MATCHES "armv5te")
34 ADD_DEFINITIONS(-DARMV5TE)
35endif()
36
37if("${CMAKE_SYSTEM_PROCESSOR_DEFAULTTUNE}" MATCHES "core2-64")
38 ADD_DEFINITIONS(-DCORE2_64)
39endif()
40
41
42#function FLAIR_LIB: compile a flair lib, and:
43#- add a message to display architecture
44#- add compile info in a .h (used by lib constructor)
45#- install lib and .h if INCLUDES_DEST_DIR is set
46function(FLAIR_LIB PROJECT_NAME SRC_FILES)
47 set(options "")#not used
48 set(oneValueArgs INCLUDES_DEST_DIR)
49 set(multiValueArgs "")#not used
50 cmake_parse_arguments(PARSE_ARGV 2 LIB "${options}" "${oneValueArgs}" "${multiValueArgs}")
51
52 if(DEFINED LIB_UNPARSED_ARGUMENTS)
53 warn("FLAIR_LIB function: unparsed arguments (${LIB_UNPARSED_ARGUMENTS})")
54 endif()
55
56 execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion
57 OUTPUT_VARIABLE GCC_VERSION)
58
59 if (GCC_VERSION VERSION_GREATER 4.3 OR GCC_VERSION VERSION_EQUAL 4.3)
60 if (GCC_VERSION VERSION_GREATER 4.7 OR GCC_VERSION VERSION_EQUAL 4.7)
61 ADD_DEFINITIONS("-std=c++11")
62 else()
63 ADD_DEFINITIONS("-std=c++0x")
64 endif()
65 else()
66 message(STATUS "GCC version < 4.3, c+11 is not supported!")
67 endif()
68
69 if("${CMAKE_SYSTEM_PROCESSOR_DEFAULTTUNE}" MATCHES "core2-64")
70 ADD_DEFINITIONS("-fPIE")
71 endif()
72
73 ADD_LIBRARY(${PROJECT_NAME}
74 ${SRC_FILES}
75 )
76
77 add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
78 COMMENT "${PROJECT_NAME} built for ${CMAKE_SYSTEM_PROCESSOR_DEFAULTTUNE} architecture")
79
80 add_custom_target(
81 ${PROJECT_NAME}_compile_info
82 COMMAND $ENV{FLAIR_ROOT}/flair-src/scripts/compile_info.sh ${CMAKE_C_COMPILER} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_BINARY_DIR}/generated/${PROJECT_NAME}/compile_info.h
83 )
84 add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}_compile_info)
85
86 INCLUDE_DIRECTORIES(
87 ${CMAKE_BINARY_DIR}/generated/${PROJECT_NAME}
88 )
89
90 INSTALL(TARGETS ${PROJECT_NAME}
91 LIBRARY DESTINATION $ENV{FLAIR_ROOT}/flair-install/lib/${ARCH_DIR}
92 ARCHIVE DESTINATION $ENV{FLAIR_ROOT}/flair-install/lib/${ARCH_DIR}
93 )
94
95 #install .h if needed
96 if(DEFINED LIB_INCLUDES_DEST_DIR)
97 FILE(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/src/*.h")
98 INSTALL(FILES ${files} DESTINATION $ENV{FLAIR_ROOT}/flair-install/include/${LIB_INCLUDES_DEST_DIR})
99 endif()
100
101endfunction()
102
103
104function(FLAIR_DEMO PROJECT_NAME SRC_FILES)
105 set(options COPY_RESOURCES)
106 set(oneValueArgs DEST_DIR)
107 set(multiValueArgs "")#not used
108 cmake_parse_arguments(PARSE_ARGV 2 DEMO "${options}" "${oneValueArgs}" "${multiValueArgs}")
109
110 if(DEFINED DEMO_UNPARSED_ARGUMENTS)
111 warn("FLAIR_DEMO function: unparsed arguments (${DEMO_UNPARSED_ARGUMENTS})")
112 endif()
113
114 #get ${FLAIR_INCLUDE_DIR}, ${FLAIR_LIBRARIES_RT} and ${FLAIR_LIBRARIES_NRT}
115 include($ENV{FLAIR_ROOT}/flair-src/cmake-modules/FlairUseFile.cmake)
116
117 #add flair include dirs
118 INCLUDE_DIRECTORIES(
119 ${FLAIR_INCLUDE_DIR}
120 )
121
122 #real time executable
123 ADD_EXECUTABLE(${PROJECT_NAME}_rt
124 ${SRC_FILES}
125 )
126 TARGET_LINK_LIBRARIES(${PROJECT_NAME}_rt ${FLAIR_LIBRARIES_RT})
127
128 #non real time executable
129 ADD_EXECUTABLE(${PROJECT_NAME}_nrt
130 ${SRC_FILES}
131 )
132 TARGET_LINK_LIBRARIES(${PROJECT_NAME}_nrt ${FLAIR_LIBRARIES_NRT})
133
134 #install demo if needed
135 if(DEFINED DEMO_DEST_DIR)
136 INSTALL(
137 TARGETS ${PROJECT_NAME}_rt ${PROJECT_NAME}_nrt
138 RUNTIME DESTINATION $ENV{FLAIR_ROOT}/flair-install/bin/demos/${ARCH_DIR}/${DEMO_DEST_DIR}
139 )
140 endif()
141
142 #copy resources if needed
143 if(${DEMO_COPY_RESOURCES})
144 FILE(GLOB RESOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/resources/${ARCH_DIR}/*")
145 foreach(item IN LISTS RESOURCE_FILES)
146 get_filename_component(filename ${item} NAME)
147 #do not overwrite: user can change xml or scripts
148 INSTALL(CODE "
149 if (NOT EXISTS \"$ENV{FLAIR_ROOT}/flair-install/bin/demos/${ARCH_DIR}/${DEMO_DEST_DIR}/${filename}\")
150 file(INSTALL \"${item}\" DESTINATION \"$ENV{FLAIR_ROOT}/flair-install/bin/demos/${ARCH_DIR}/${DEMO_DEST_DIR}\" USE_SOURCE_PERMISSIONS)
151 else()
152 message(\"-- Not installing \" $ENV{FLAIR_ROOT} \"/flair-install/bin/demos/\" ${ARCH_DIR} \"/\" ${DEMO_DEST_DIR} \"/\" ${filename} \" (file already exists)\")
153 endif()
154 ")
155 endforeach()
156 endif()
157
158endfunction()
159
160#create a demo using host cxx and libs
161#usefull for simulator app when there are graphical lib incompatibilities (eg log2@glibc_2.29)
162function(FLAIR_DEMO_HOST_CXX PROJECT_NAME SRC_FILES)
163 if("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "i686" OR "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "i586" OR "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "x86_64")
164
165 set(CMAKE_CXX_FLAGS "" PARENT_SCOPE)
166 set(CMAKE_CXX_COMPILER "g++" PARENT_SCOPE)
167 set(CMAKE_CXX_LINK_FLAGS "-Wl,-unresolved-symbols=ignore-in-shared-libs -Wl,-rpath=$ENV{FLAIR_ROOT}/flair-install/lib/${ARCH_DIR}/ -Wl,--disable-new-dtags" PARENT_SCOPE)
168 ADD_DEFINITIONS("-D_GLIBCXX_USE_CXX11_ABI=0")
169
170 set(LIB_LIST libudt libvrpn libFileLib libIrrlicht libquat)
171
172 foreach(LIB_NAME IN LISTS LIB_LIST) #all libs
173 FILE(GLOB LIB_FILES "${CMAKE_SYSROOT}/usr/lib/${LIB_NAME}*")
174 foreach(item IN LISTS LIB_FILES) #all files and symlinks of a lib
175 get_filename_component(filename ${item} NAME)
176 INSTALL(CODE "
177 if (NOT EXISTS \"$ENV{FLAIR_ROOT}/flair-install/lib/${ARCH_DIR}/${filename}\")
178 file(INSTALL \"${item}\" DESTINATION \"$ENV{FLAIR_ROOT}/flair-install/lib/${ARCH_DIR}\" USE_SOURCE_PERMISSIONS)
179 else()
180 message(\"-- Not installing \" $ENV{FLAIR_ROOT} \"/flair-install/lib/\" ${ARCH_DIR} \"/\" ${filename} \" (file already exists)\")
181 endif()
182 ")
183
184 endforeach()
185 endforeach()
186
187 FLAIR_DEMO(${ARGV})
188 else()
189 warn("${PROJECT_NAME} will not be built for ${CMAKE_SYSTEM_PROCESSOR} architecture")
190 endif()
191
192endfunction()
193
194function(FLAIR_NRT_TOOL PROJECT_NAME SRC_FILES)
195 set(options COPY_RESOURCES)
196 set(oneValueArgs "")#not used
197 set(multiValueArgs "")#not used
198 cmake_parse_arguments(PARSE_ARGV 2 TOOL "${options}" "${oneValueArgs}" "${multiValueArgs}")
199
200 if(DEFINED TOOL_UNPARSED_ARGUMENTS)
201 warn("FLAIR_NRT_TOOL function: unparsed arguments (${TOOL_UNPARSED_ARGUMENTS})")
202 endif()
203
204 #get ${FLAIR_INCLUDE_DIR}, ${FLAIR_LIBRARIES_RT} and ${FLAIR_LIBRARIES_NRT}
205 include($ENV{FLAIR_ROOT}/flair-src/cmake-modules/FlairUseFile.cmake)
206
207 #add flair include dirs
208 INCLUDE_DIRECTORIES(
209 ${FLAIR_INCLUDE_DIR}
210 )
211
212 #real time executable
213 ADD_EXECUTABLE(${PROJECT_NAME}
214 ${SRC_FILES}
215 )
216 TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${FLAIR_LIBRARIES_NRT})
217
218 INSTALL(
219 TARGETS ${PROJECT_NAME}
220 RUNTIME DESTINATION $ENV{FLAIR_ROOT}/flair-install/bin/tools/${ARCH_DIR}/
221 )
222
223 #copy resources if needed
224 if(${TOOL_COPY_RESOURCES})
225 FILE(GLOB RESOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/resources/${ARCH_DIR}/*")
226 foreach(item IN LISTS RESOURCE_FILES)
227 get_filename_component(filename ${item} NAME)
228 #do not overwrite: user can change xml or scripts
229 INSTALL(CODE "
230 if (NOT EXISTS \"$ENV{FLAIR_ROOT}/flair-install/bin/tools/${ARCH_DIR}/${filename}\")
231 file(INSTALL \"${item}\" DESTINATION \"$ENV{FLAIR_ROOT}/flair-install/bin/tools/${ARCH_DIR}\" USE_SOURCE_PERMISSIONS)
232 else()
233 message(\"-- Not installing \" $ENV{FLAIR_ROOT} \"/flair-install/bin/tools/\" ${ARCH_DIR} \"/\" ${filename} \" (file already exists)\")
234 endif()
235 ")
236 endforeach()
237 endif()
238
239endfunction()
240
241#reimplement add executable:
242#- add a custom target for delivery (only on ARM), delivery are read from ssh config file
243#- add a message to display architecture
244function(ADD_EXECUTABLE)
245 if("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "arm" AND EXISTS "$ENV{HOME}/.ssh/config")
246 file(STRINGS $ENV{HOME}/.ssh/config TEST)
247 foreach(f ${TEST})
248 string(FIND ${f} "Host " POS)#cherche ligne host
249 if(${POS} GREATER -1)
250 string(REPLACE Host "" TARGET_NAME ${f})#enleve Host
251 string(STRIP ${TARGET_NAME} TARGET_NAME)#enleve les espaces
252 endif()
253 string(FIND ${f} HostName POS)#cherche hostname
254 if(${POS} GREATER -1)
255 string(FIND ${f} "192.168." POS)#cherche addresse
256 if(${POS} GREATER 0)#garde que les adresses en 192.168.x.x
257 string(REPLACE HostName "" ADDRESS ${f})#enleve Hostname
258 string(STRIP ${ADDRESS} ADDRESS)#enleve les espaces
259 #message("adding delivery target for " ${ARGV0} " (" ${ADDRESS} ")")
260 string(REPLACE "/" "_" TARGET_PATH ${TARGET_EXECUTABLE_OUTPUT_PATH})#les / ne sont pas acceptés
261 add_custom_target(
262 delivery_root_${ADDRESS}_${TARGET_PATH}_${ARGV0}
263 COMMAND make
264 COMMAND scp ${EXECUTABLE_OUTPUT_PATH}/${ARGV0} root@${ADDRESS}:${TARGET_EXECUTABLE_OUTPUT_PATH}
265 )
266 endif()
267 endif()
268 endforeach(f)
269 endif()
270
271 #call original function
272 _ADD_EXECUTABLE(${ARGV})
273
274 #check if it is qt4 internal target
275 string(SUBSTRING ${ARGV0} 0 5 TESTNAME)
276 if(NOT ${TESTNAME} MATCHES "Qt4::")
277 #add a message to display architecture
278 add_custom_command(TARGET ${ARGV0} POST_BUILD
279 COMMENT "${ARGV0} built for ${CMAKE_SYSTEM_PROCESSOR_DEFAULTTUNE} architecture")
280 endif()
281
282 #add a dependance to FlairLibs and FlairHdsLibs if we use the top level CMakeLists.txt and we need flairlibs
283 if(TARGET FlairLibs AND DEFINED FLAIRUSEFILE_INCLUDED)
284 add_dependencies(${ARGV0} FlairLibs)
285 endif()
286 if(TARGET FlairHdsLibs AND DEFINED FLAIRUSEFILE_INCLUDED)
287 add_dependencies(${ARGV0} FlairHdsLibs)
288 endif()
289
290endfunction()
Note: See TracBrowser for help on using the repository browser.