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

Last change on this file since 365 was 365, checked in by Sanahuja Guillaume, 16 months ago

change simu apps compilation to avoid problem with mixing host and toolchain libs
(log2@glibc_2.29 error when compiling on ubuntu 20.05 or mint 20)
now compile with host g++ and libs (except filelib, irrlicht, quat, udt and vrpn) for simu apps using the macro: FLAIR_DEMO_HOST_CXX

File size: 10.2 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 ADD_LIBRARY(${PROJECT_NAME}
70 ${SRC_FILES}
71 )
72
73 add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
74 COMMENT "${PROJECT_NAME} built for ${CMAKE_SYSTEM_PROCESSOR_DEFAULTTUNE} architecture")
75
76 add_custom_target(
77 ${PROJECT_NAME}_compile_info
78 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
79 )
80 add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}_compile_info)
81
82 INCLUDE_DIRECTORIES(
83 ${CMAKE_BINARY_DIR}/generated/${PROJECT_NAME}
84 )
85
86 INSTALL(TARGETS ${PROJECT_NAME}
87 LIBRARY DESTINATION $ENV{FLAIR_ROOT}/flair-install/lib/${ARCH_DIR}
88 ARCHIVE DESTINATION $ENV{FLAIR_ROOT}/flair-install/lib/${ARCH_DIR}
89 )
90
91 #install .h if needed
92 if(DEFINED LIB_INCLUDES_DEST_DIR)
93 FILE(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/src/*.h")
94 INSTALL(FILES ${files} DESTINATION $ENV{FLAIR_ROOT}/flair-install/include/${LIB_INCLUDES_DEST_DIR})
95 endif()
96
97endfunction()
98
99
100function(FLAIR_DEMO PROJECT_NAME SRC_FILES)
101 set(options COPY_RESOURCES)
102 set(oneValueArgs DEST_DIR)
103 set(multiValueArgs "")#not used
104 cmake_parse_arguments(PARSE_ARGV 2 DEMO "${options}" "${oneValueArgs}" "${multiValueArgs}")
105
106 if(DEFINED DEMO_UNPARSED_ARGUMENTS)
107 warn("FLAIR_DEMO function: unparsed arguments (${DEMO_UNPARSED_ARGUMENTS})")
108 endif()
109
110 #get ${FLAIR_INCLUDE_DIR}, ${FLAIR_LIBRARIES_RT} and ${FLAIR_LIBRARIES_NRT}
111 include($ENV{FLAIR_ROOT}/flair-src/cmake-modules/FlairUseFile.cmake)
112
113 #add flair include dirs
114 INCLUDE_DIRECTORIES(
115 ${FLAIR_INCLUDE_DIR}
116 )
117
118 #real time executable
119 ADD_EXECUTABLE(${PROJECT_NAME}_rt
120 ${SRC_FILES}
121 )
122 TARGET_LINK_LIBRARIES(${PROJECT_NAME}_rt ${FLAIR_LIBRARIES_RT})
123
124 #non real time executable
125 ADD_EXECUTABLE(${PROJECT_NAME}_nrt
126 ${SRC_FILES}
127 )
128 TARGET_LINK_LIBRARIES(${PROJECT_NAME}_nrt ${FLAIR_LIBRARIES_NRT})
129
130 #install demo if needed
131 if(DEFINED DEMO_DEST_DIR)
132 INSTALL(
133 TARGETS ${PROJECT_NAME}_rt ${PROJECT_NAME}_nrt
134 RUNTIME DESTINATION $ENV{FLAIR_ROOT}/flair-install/bin/demos/${ARCH_DIR}/${DEMO_DEST_DIR}
135 )
136 endif()
137
138 #copy resources if needed
139 if(${DEMO_COPY_RESOURCES})
140 FILE(GLOB RESOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/resources/${ARCH_DIR}/*")
141 foreach(item IN LISTS RESOURCE_FILES)
142 get_filename_component(filename ${item} NAME)
143 #do not overwrite: user can change xml or scripts
144 INSTALL(CODE "
145 if (NOT EXISTS \"$ENV{FLAIR_ROOT}/flair-install/bin/demos/${ARCH_DIR}/${DEMO_DEST_DIR}/${filename}\")
146 file(INSTALL \"${item}\" DESTINATION \"$ENV{FLAIR_ROOT}/flair-install/bin/demos/${ARCH_DIR}/${DEMO_DEST_DIR}\" USE_SOURCE_PERMISSIONS)
147 else()
148 message(\"-- Not installing \" $ENV{FLAIR_ROOT} \"/flair-install/bin/demos/\" ${ARCH_DIR} \"/\" ${DEMO_DEST_DIR} \"/\" ${filename} \" (file already exists)\")
149 endif()
150 ")
151 endforeach()
152 endif()
153
154endfunction()
155
156#create a demo using host cxx and libs
157#usefull for simulator app when there are graphical lib incompatibilities (eg log2@glibc_2.29)
158function(FLAIR_DEMO_HOST_CXX PROJECT_NAME SRC_FILES)
159
160 set(CMAKE_CXX_FLAGS "" PARENT_SCOPE)
161 set(CMAKE_CXX_COMPILER "g++" PARENT_SCOPE)
162 set(CMAKE_CXX_LINK_FLAGS "-Wl,-unresolved-symbols=ignore-in-shared-libs -Wl,-rpath=/home/gsanahuj/flair/flair-install/lib/${ARCH_DIR}/ -Wl,--disable-new-dtags" PARENT_SCOPE)
163 ADD_DEFINITIONS("-D_GLIBCXX_USE_CXX11_ABI=0")
164
165 set(LIB_LIST libudt libvrpn libFileLib libIrrlicht libquat)
166
167 foreach(LIB_NAME IN LISTS LIB_LIST) #all libs
168 FILE(GLOB LIB_FILES "${CMAKE_SYSROOT}/usr/lib/${LIB_NAME}*")
169 foreach(item IN LISTS LIB_FILES) #all files and symlinks of a lib
170 get_filename_component(filename ${item} NAME)
171 INSTALL(CODE "
172 if (NOT EXISTS \"$ENV{FLAIR_ROOT}/flair-install/lib/${ARCH_DIR}/${filename}\")
173 file(INSTALL \"${item}\" DESTINATION \"$ENV{FLAIR_ROOT}/flair-install/lib/${ARCH_DIR}\" USE_SOURCE_PERMISSIONS)
174 else()
175 message(\"-- Not installing \" $ENV{FLAIR_ROOT} \"/flair-install/lib/\" ${ARCH_DIR} \"/\" ${filename} \" (file already exists)\")
176 endif()
177 ")
178
179 endforeach()
180 endforeach()
181
182 FLAIR_DEMO(${ARGV})
183
184endfunction()
185
186function(FLAIR_NRT_TOOL PROJECT_NAME SRC_FILES)
187 set(options COPY_RESOURCES)
188 set(oneValueArgs "")#not used
189 set(multiValueArgs "")#not used
190 cmake_parse_arguments(PARSE_ARGV 2 TOOL "${options}" "${oneValueArgs}" "${multiValueArgs}")
191
192 if(DEFINED TOOL_UNPARSED_ARGUMENTS)
193 warn("FLAIR_NRT_TOOL function: unparsed arguments (${TOOL_UNPARSED_ARGUMENTS})")
194 endif()
195
196 #get ${FLAIR_INCLUDE_DIR}, ${FLAIR_LIBRARIES_RT} and ${FLAIR_LIBRARIES_NRT}
197 include($ENV{FLAIR_ROOT}/flair-src/cmake-modules/FlairUseFile.cmake)
198
199 #add flair include dirs
200 INCLUDE_DIRECTORIES(
201 ${FLAIR_INCLUDE_DIR}
202 )
203
204 #real time executable
205 ADD_EXECUTABLE(${PROJECT_NAME}
206 ${SRC_FILES}
207 )
208 TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${FLAIR_LIBRARIES_NRT})
209
210 INSTALL(
211 TARGETS ${PROJECT_NAME}
212 RUNTIME DESTINATION $ENV{FLAIR_ROOT}/flair-install/bin/tools/${ARCH_DIR}/
213 )
214
215 #copy resources if needed
216 if(${TOOL_COPY_RESOURCES})
217 FILE(GLOB RESOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/resources/${ARCH_DIR}/*")
218 foreach(item IN LISTS RESOURCE_FILES)
219 get_filename_component(filename ${item} NAME)
220 #do not overwrite: user can change xml or scripts
221 INSTALL(CODE "
222 if (NOT EXISTS \"$ENV{FLAIR_ROOT}/flair-install/bin/tools/${ARCH_DIR}/${filename}\")
223 file(INSTALL \"${item}\" DESTINATION \"$ENV{FLAIR_ROOT}/flair-install/bin/tools/${ARCH_DIR}\" USE_SOURCE_PERMISSIONS)
224 else()
225 message(\"-- Not installing \" $ENV{FLAIR_ROOT} \"/flair-install/bin/tools/\" ${ARCH_DIR} \"/\" ${filename} \" (file already exists)\")
226 endif()
227 ")
228 endforeach()
229 endif()
230
231endfunction()
232
233#reimplement add executable:
234#- add a custom target for delivery (only on ARM), delivery are read from ssh config file
235#- add a message to display architecture
236function(ADD_EXECUTABLE)
237 if("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "arm" AND EXISTS "$ENV{HOME}/.ssh/config")
238 file(STRINGS $ENV{HOME}/.ssh/config TEST)
239 foreach(f ${TEST})
240 string(FIND ${f} "Host " POS)#cherche ligne host
241 if(${POS} GREATER -1)
242 string(REPLACE Host "" TARGET_NAME ${f})#enleve Host
243 string(STRIP ${TARGET_NAME} TARGET_NAME)#enleve les espaces
244 endif()
245 string(FIND ${f} HostName POS)#cherche hostname
246 if(${POS} GREATER -1)
247 string(FIND ${f} "192.168." POS)#cherche addresse
248 if(${POS} GREATER 0)#garde que les adresses en 192.168.x.x
249 string(REPLACE HostName "" ADDRESS ${f})#enleve Hostname
250 string(STRIP ${ADDRESS} ADDRESS)#enleve les espaces
251 #message("adding delivery target for " ${ARGV0} " (" ${ADDRESS} ")")
252 string(REPLACE "/" "_" TARGET_PATH ${TARGET_EXECUTABLE_OUTPUT_PATH})#les / ne sont pas acceptés
253 add_custom_target(
254 delivery_root_${ADDRESS}_${TARGET_PATH}_${ARGV0}
255 COMMAND make
256 COMMAND scp ${EXECUTABLE_OUTPUT_PATH}/${ARGV0} root@${ADDRESS}:${TARGET_EXECUTABLE_OUTPUT_PATH}
257 )
258 endif()
259 endif()
260 endforeach(f)
261 endif()
262
263 #call original function
264 _ADD_EXECUTABLE(${ARGV})
265
266 #check if it is qt4 internal target
267 string(SUBSTRING ${ARGV0} 0 5 TESTNAME)
268 if(NOT ${TESTNAME} MATCHES "Qt4::")
269 #add a message to display architecture
270 add_custom_command(TARGET ${ARGV0} POST_BUILD
271 COMMENT "${ARGV0} built for ${CMAKE_SYSTEM_PROCESSOR_DEFAULTTUNE} architecture")
272 endif()
273
274 #add a dependance to FlairLibs and FlairHdsLibs if we use the top level CMakeLists.txt and we need flairlibs
275 if(TARGET FlairLibs AND DEFINED FLAIRUSEFILE_INCLUDED)
276 add_dependencies(${ARGV0} FlairLibs)
277 endif()
278 if(TARGET FlairHdsLibs AND DEFINED FLAIRUSEFILE_INCLUDED)
279 add_dependencies(${ARGV0} FlairHdsLibs)
280 endif()
281
282endfunction()
Note: See TracBrowser for help on using the repository browser.