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

Last change on this file since 302 was 302, checked in by Sanahuja Guillaume, 3 years ago

modifs nouveau build system

File size: 7.7 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 #get ${FLAIR_INCLUDE_DIR}, ${FLAIR_LIBRARIES_RT} and ${FLAIR_LIBRARIES_NRT}
158 include($ENV{FLAIR_ROOT}/flair-src/cmake-modules/FlairUseFile.cmake)
159
160 #add flair include dirs
161 INCLUDE_DIRECTORIES(
162 ${FLAIR_INCLUDE_DIR}
163 )
164
165 #real time executable
166 ADD_EXECUTABLE(${PROJECT_NAME}
167 ${SRC_FILES}
168 )
169 TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${FLAIR_LIBRARIES_NRT})
170
171 INSTALL(
172 TARGETS ${PROJECT_NAME}
173 RUNTIME DESTINATION $ENV{FLAIR_ROOT}/flair-install/bin/tools/${ARCH_DIR}/
174 )
175endfunction()
176
177#reimplement add executable:
178#- add a custom target for delivery (only on ARM), delivery are read from ssh config file
179#- add a message to display architecture
180function(ADD_EXECUTABLE)
181 if("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "arm" AND EXISTS "$ENV{HOME}/.ssh/config")
182 file(STRINGS $ENV{HOME}/.ssh/config TEST)
183 foreach(f ${TEST})
184 string(FIND ${f} "Host " POS)#cherche ligne host
185 if(${POS} GREATER -1)
186 string(REPLACE Host "" TARGET_NAME ${f})#enleve Host
187 string(STRIP ${TARGET_NAME} TARGET_NAME)#enleve les espaces
188 endif()
189 string(FIND ${f} HostName POS)#cherche hostname
190 if(${POS} GREATER -1)
191 string(FIND ${f} "192.168." POS)#cherche addresse
192 if(${POS} GREATER 0)#garde que les adresses en 192.168.x.x
193 string(REPLACE HostName "" ADDRESS ${f})#enleve Hostname
194 string(STRIP ${ADDRESS} ADDRESS)#enleve les espaces
195 #message("adding delivery target for " ${ARGV0} " (" ${ADDRESS} ")")
196 string(REPLACE "/" "_" TARGET_PATH ${TARGET_EXECUTABLE_OUTPUT_PATH})#les / ne sont pas acceptés
197 add_custom_target(
198 delivery_root_${ADDRESS}_${TARGET_PATH}_${ARGV0}
199 COMMAND make
200 COMMAND scp ${EXECUTABLE_OUTPUT_PATH}/${ARGV0} root@${ADDRESS}:${TARGET_EXECUTABLE_OUTPUT_PATH}
201 )
202 endif()
203 endif()
204 endforeach(f)
205 endif()
206
207 #call original function
208 _ADD_EXECUTABLE(${ARGV})
209
210 #check if it is qt4 internal target
211 string(SUBSTRING ${ARGV0} 0 5 TESTNAME)
212 if(NOT ${TESTNAME} MATCHES "Qt4::")
213 #add a message to display architecture
214 add_custom_command(TARGET ${ARGV0} POST_BUILD
215 COMMENT "${ARGV0} built for ${CMAKE_SYSTEM_PROCESSOR_DEFAULTTUNE} architecture")
216 endif()
217
218 #add a dependance to FlairLibs and FlairHdsLibs if we use the top level CMakeLists.txt and we need flairlibs
219 if(TARGET FlairLibs AND DEFINED FLAIRUSEFILE_INCLUDED)
220 add_dependencies(${ARGV0} FlairLibs)
221 endif()
222 if(TARGET FlairHdsLibs AND DEFINED FLAIRUSEFILE_INCLUDED)
223 add_dependencies(${ARGV0} FlairHdsLibs)
224 endif()
225
226endfunction()
Note: See TracBrowser for help on using the repository browser.