1 | if(DEFINED GLOBALCMAKEFLAIR_INCLUDED)
|
---|
2 | return()
|
---|
3 | endif()
|
---|
4 |
|
---|
5 | SET(GLOBALCMAKEFLAIR_INCLUDED true)
|
---|
6 |
|
---|
7 | if(NOT DEFINED ENV{FLAIR_ROOT})
|
---|
8 | message(FATAL_ERROR "variable FLAIR_ROOT not defined")
|
---|
9 | endif()
|
---|
10 |
|
---|
11 | include($ENV{FLAIR_ROOT}/flair-src/cmake-modules/ColoredMessage.cmake)
|
---|
12 |
|
---|
13 | #check if we have a flair-hds directory
|
---|
14 | if (IS_DIRECTORY $ENV{FLAIR_ROOT}/flair-hds )
|
---|
15 | info("found flair-hds directory")
|
---|
16 | SET(FOUND_HDS_DIR TRUE)
|
---|
17 | endif()
|
---|
18 |
|
---|
19 | include($ENV{FLAIR_ROOT}/flair-src/cmake-modules/ArchDir.cmake)
|
---|
20 |
|
---|
21 | list(APPEND CMAKE_MODULE_PATH $ENV{FLAIR_ROOT}/flair-src/cmake-modules/)
|
---|
22 |
|
---|
23 | #default executable ouput paths
|
---|
24 | if(NOT DEFINED TARGET_EXECUTABLE_OUTPUT_PATH)
|
---|
25 | SET(TARGET_EXECUTABLE_OUTPUT_PATH bin)
|
---|
26 | endif()
|
---|
27 |
|
---|
28 | #add definitions for archs
|
---|
29 | if("${CMAKE_SYSTEM_PROCESSOR_DEFAULTTUNE}" MATCHES "armv7a-neon")
|
---|
30 | ADD_DEFINITIONS(-DARMV7A)
|
---|
31 | endif()
|
---|
32 |
|
---|
33 | if("${CMAKE_SYSTEM_PROCESSOR_DEFAULTTUNE}" MATCHES "armv5te")
|
---|
34 | ADD_DEFINITIONS(-DARMV5TE)
|
---|
35 | endif()
|
---|
36 |
|
---|
37 | if("${CMAKE_SYSTEM_PROCESSOR_DEFAULTTUNE}" MATCHES "core2-64")
|
---|
38 | ADD_DEFINITIONS(-DCORE2_64)
|
---|
39 | endif()
|
---|
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
|
---|
46 | function(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 |
|
---|
101 | endfunction()
|
---|
102 |
|
---|
103 |
|
---|
104 | function(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 |
|
---|
158 | endfunction()
|
---|
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)
|
---|
162 | function(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 | #reconstruct arguments because src_files is a list
|
---|
187 | #todo, use multiValueArgs for src_file; but it will brake all demos cmakelists...
|
---|
188 | FLAIR_DEMO(${ARGV0} "${ARGV1}" ${ARGV2} ${ARGV3} ${ARGV4})
|
---|
189 | else()
|
---|
190 | warn("${PROJECT_NAME} will not be built for ${CMAKE_SYSTEM_PROCESSOR} architecture")
|
---|
191 | endif()
|
---|
192 |
|
---|
193 | endfunction()
|
---|
194 |
|
---|
195 | function(FLAIR_NRT_TOOL PROJECT_NAME SRC_FILES)
|
---|
196 | set(options COPY_RESOURCES)
|
---|
197 | set(oneValueArgs "")#not used
|
---|
198 | set(multiValueArgs "")#not used
|
---|
199 | cmake_parse_arguments(PARSE_ARGV 2 TOOL "${options}" "${oneValueArgs}" "${multiValueArgs}")
|
---|
200 |
|
---|
201 | if(DEFINED TOOL_UNPARSED_ARGUMENTS)
|
---|
202 | warn("FLAIR_NRT_TOOL function: unparsed arguments (${TOOL_UNPARSED_ARGUMENTS})")
|
---|
203 | endif()
|
---|
204 |
|
---|
205 | #get ${FLAIR_INCLUDE_DIR}, ${FLAIR_LIBRARIES_RT} and ${FLAIR_LIBRARIES_NRT}
|
---|
206 | include($ENV{FLAIR_ROOT}/flair-src/cmake-modules/FlairUseFile.cmake)
|
---|
207 |
|
---|
208 | #add flair include dirs
|
---|
209 | INCLUDE_DIRECTORIES(
|
---|
210 | ${FLAIR_INCLUDE_DIR}
|
---|
211 | )
|
---|
212 |
|
---|
213 | #real time executable
|
---|
214 | ADD_EXECUTABLE(${PROJECT_NAME}
|
---|
215 | ${SRC_FILES}
|
---|
216 | )
|
---|
217 | TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${FLAIR_LIBRARIES_NRT})
|
---|
218 |
|
---|
219 | INSTALL(
|
---|
220 | TARGETS ${PROJECT_NAME}
|
---|
221 | RUNTIME DESTINATION $ENV{FLAIR_ROOT}/flair-install/bin/tools/${ARCH_DIR}/
|
---|
222 | )
|
---|
223 |
|
---|
224 | #copy resources if needed
|
---|
225 | if(${TOOL_COPY_RESOURCES})
|
---|
226 | FILE(GLOB RESOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/resources/${ARCH_DIR}/*")
|
---|
227 | foreach(item IN LISTS RESOURCE_FILES)
|
---|
228 | get_filename_component(filename ${item} NAME)
|
---|
229 | #do not overwrite: user can change xml or scripts
|
---|
230 | INSTALL(CODE "
|
---|
231 | if (NOT EXISTS \"$ENV{FLAIR_ROOT}/flair-install/bin/tools/${ARCH_DIR}/${filename}\")
|
---|
232 | file(INSTALL \"${item}\" DESTINATION \"$ENV{FLAIR_ROOT}/flair-install/bin/tools/${ARCH_DIR}\" USE_SOURCE_PERMISSIONS)
|
---|
233 | else()
|
---|
234 | message(\"-- Not installing \" $ENV{FLAIR_ROOT} \"/flair-install/bin/tools/\" ${ARCH_DIR} \"/\" ${filename} \" (file already exists)\")
|
---|
235 | endif()
|
---|
236 | ")
|
---|
237 | endforeach()
|
---|
238 | endif()
|
---|
239 |
|
---|
240 | endfunction()
|
---|
241 |
|
---|
242 | #reimplement add executable:
|
---|
243 | #- add a custom target for delivery (only on ARM), delivery are read from ssh config file
|
---|
244 | #- add a message to display architecture
|
---|
245 | function(ADD_EXECUTABLE)
|
---|
246 | if("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "arm" AND EXISTS "$ENV{HOME}/.ssh/config")
|
---|
247 | file(STRINGS $ENV{HOME}/.ssh/config TEST)
|
---|
248 | foreach(f ${TEST})
|
---|
249 | string(FIND ${f} "Host " POS)#cherche ligne host
|
---|
250 | if(${POS} GREATER -1)
|
---|
251 | string(REPLACE Host "" TARGET_NAME ${f})#enleve Host
|
---|
252 | string(STRIP ${TARGET_NAME} TARGET_NAME)#enleve les espaces
|
---|
253 | endif()
|
---|
254 | string(FIND ${f} HostName POS)#cherche hostname
|
---|
255 | if(${POS} GREATER -1)
|
---|
256 | string(FIND ${f} "192.168." POS)#cherche addresse
|
---|
257 | if(${POS} GREATER 0)#garde que les adresses en 192.168.x.x
|
---|
258 | string(REPLACE HostName "" ADDRESS ${f})#enleve Hostname
|
---|
259 | string(STRIP ${ADDRESS} ADDRESS)#enleve les espaces
|
---|
260 | #message("adding delivery target for " ${ARGV0} " (" ${ADDRESS} ")")
|
---|
261 | string(REPLACE "/" "_" TARGET_PATH ${TARGET_EXECUTABLE_OUTPUT_PATH})#les / ne sont pas acceptés
|
---|
262 | add_custom_target(
|
---|
263 | delivery_root_${ADDRESS}_${TARGET_PATH}_${ARGV0}
|
---|
264 | COMMAND make
|
---|
265 | COMMAND scp ${EXECUTABLE_OUTPUT_PATH}/${ARGV0} root@${ADDRESS}:${TARGET_EXECUTABLE_OUTPUT_PATH}
|
---|
266 | )
|
---|
267 | endif()
|
---|
268 | endif()
|
---|
269 | endforeach(f)
|
---|
270 | endif()
|
---|
271 |
|
---|
272 | #call original function
|
---|
273 | _ADD_EXECUTABLE(${ARGV})
|
---|
274 |
|
---|
275 | #check if it is qt4 internal target
|
---|
276 | string(SUBSTRING ${ARGV0} 0 5 TESTNAME)
|
---|
277 | if(NOT ${TESTNAME} MATCHES "Qt4::")
|
---|
278 | #add a message to display architecture
|
---|
279 | add_custom_command(TARGET ${ARGV0} POST_BUILD
|
---|
280 | COMMENT "${ARGV0} built for ${CMAKE_SYSTEM_PROCESSOR_DEFAULTTUNE} architecture")
|
---|
281 | endif()
|
---|
282 |
|
---|
283 | #add a dependance to FlairLibs and FlairHdsLibs if we use the top level CMakeLists.txt and we need flairlibs
|
---|
284 | if(TARGET FlairLibs AND DEFINED FLAIRUSEFILE_INCLUDED)
|
---|
285 | add_dependencies(${ARGV0} FlairLibs)
|
---|
286 | endif()
|
---|
287 | if(TARGET FlairHdsLibs AND DEFINED FLAIRUSEFILE_INCLUDED)
|
---|
288 | add_dependencies(${ARGV0} FlairHdsLibs)
|
---|
289 | endif()
|
---|
290 |
|
---|
291 | endfunction()
|
---|