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

Last change on this file since 310 was 305, checked in by Sanahuja Guillaume, 6 years ago

gcs resources

File size: 8.8 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
156function(FLAIR_NRT_TOOL PROJECT_NAME SRC_FILES)
157 set(options COPY_RESOURCES)
158 set(oneValueArgs "")#not used
159 set(multiValueArgs "")#not used
160 cmake_parse_arguments(PARSE_ARGV 2 TOOL "${options}" "${oneValueArgs}" "${multiValueArgs}")
161
162 if(DEFINED TOOL_UNPARSED_ARGUMENTS)
163 warn("FLAIR_NRT_TOOL function: unparsed arguments (${TOOL_UNPARSED_ARGUMENTS})")
164 endif()
165
166 #get ${FLAIR_INCLUDE_DIR}, ${FLAIR_LIBRARIES_RT} and ${FLAIR_LIBRARIES_NRT}
167 include($ENV{FLAIR_ROOT}/flair-src/cmake-modules/FlairUseFile.cmake)
168
169 #add flair include dirs
170 INCLUDE_DIRECTORIES(
171 ${FLAIR_INCLUDE_DIR}
172 )
173
174 #real time executable
175 ADD_EXECUTABLE(${PROJECT_NAME}
176 ${SRC_FILES}
177 )
178 TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${FLAIR_LIBRARIES_NRT})
179
180 INSTALL(
181 TARGETS ${PROJECT_NAME}
182 RUNTIME DESTINATION $ENV{FLAIR_ROOT}/flair-install/bin/tools/${ARCH_DIR}/
183 )
184
185 #copy resources if needed
186 if(${TOOL_COPY_RESOURCES})
187 FILE(GLOB RESOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/resources/${ARCH_DIR}/*")
188 foreach(item IN LISTS RESOURCE_FILES)
189 get_filename_component(filename ${item} NAME)
190 #do not overwrite: user can change xml or scripts
191 INSTALL(CODE "
192 if (NOT EXISTS \"$ENV{FLAIR_ROOT}/flair-install/bin/tools/${ARCH_DIR}/${filename}\")
193 file(INSTALL \"${item}\" DESTINATION \"$ENV{FLAIR_ROOT}/flair-install/bin/tools/${ARCH_DIR}\" USE_SOURCE_PERMISSIONS)
194 else()
195 message(\"-- Not installing \" $ENV{FLAIR_ROOT} \"/flair-install/bin/tools/\" ${ARCH_DIR} \"/\" ${filename} \" (file already exists)\")
196 endif()
197 ")
198 endforeach()
199 endif()
200
201endfunction()
202
203#reimplement add executable:
204#- add a custom target for delivery (only on ARM), delivery are read from ssh config file
205#- add a message to display architecture
206function(ADD_EXECUTABLE)
207 if("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "arm" AND EXISTS "$ENV{HOME}/.ssh/config")
208 file(STRINGS $ENV{HOME}/.ssh/config TEST)
209 foreach(f ${TEST})
210 string(FIND ${f} "Host " POS)#cherche ligne host
211 if(${POS} GREATER -1)
212 string(REPLACE Host "" TARGET_NAME ${f})#enleve Host
213 string(STRIP ${TARGET_NAME} TARGET_NAME)#enleve les espaces
214 endif()
215 string(FIND ${f} HostName POS)#cherche hostname
216 if(${POS} GREATER -1)
217 string(FIND ${f} "192.168." POS)#cherche addresse
218 if(${POS} GREATER 0)#garde que les adresses en 192.168.x.x
219 string(REPLACE HostName "" ADDRESS ${f})#enleve Hostname
220 string(STRIP ${ADDRESS} ADDRESS)#enleve les espaces
221 #message("adding delivery target for " ${ARGV0} " (" ${ADDRESS} ")")
222 string(REPLACE "/" "_" TARGET_PATH ${TARGET_EXECUTABLE_OUTPUT_PATH})#les / ne sont pas acceptés
223 add_custom_target(
224 delivery_root_${ADDRESS}_${TARGET_PATH}_${ARGV0}
225 COMMAND make
226 COMMAND scp ${EXECUTABLE_OUTPUT_PATH}/${ARGV0} root@${ADDRESS}:${TARGET_EXECUTABLE_OUTPUT_PATH}
227 )
228 endif()
229 endif()
230 endforeach(f)
231 endif()
232
233 #call original function
234 _ADD_EXECUTABLE(${ARGV})
235
236 #check if it is qt4 internal target
237 string(SUBSTRING ${ARGV0} 0 5 TESTNAME)
238 if(NOT ${TESTNAME} MATCHES "Qt4::")
239 #add a message to display architecture
240 add_custom_command(TARGET ${ARGV0} POST_BUILD
241 COMMENT "${ARGV0} built for ${CMAKE_SYSTEM_PROCESSOR_DEFAULTTUNE} architecture")
242 endif()
243
244 #add a dependance to FlairLibs and FlairHdsLibs if we use the top level CMakeLists.txt and we need flairlibs
245 if(TARGET FlairLibs AND DEFINED FLAIRUSEFILE_INCLUDED)
246 add_dependencies(${ARGV0} FlairLibs)
247 endif()
248 if(TARGET FlairHdsLibs AND DEFINED FLAIRUSEFILE_INCLUDED)
249 add_dependencies(${ARGV0} FlairHdsLibs)
250 endif()
251
252endfunction()
Note: See TracBrowser for help on using the repository browser.