source: flair-dev/trunk/cmake-modules/GlobalCmakeFlair.cmake

Last change on this file was 104, checked in by Sanahuja Guillaume, 19 months ago

m

File size: 5.0 KB
Line 
1if(DEFINED GLOBALCMAKEFLAIR_INCLUDED)
2    return()
3endif()
4
5SET(GLOBALCMAKEFLAIR_INCLUDED true)
6
7include($ENV{FLAIR_ROOT}/flair-dev/cmake-modules/ColoredMessage.cmake)
8
9#check if we have a flair-hds directory
10if (IS_DIRECTORY $ENV{FLAIR_ROOT}/flair-hds )
11        info("found flair-hds directory")
12        SET(FOUND_HDS_DIR TRUE) 
13endif()
14
15if(NOT DEFINED ENV{FLAIR_ROOT})
16        message(FATAL_ERROR  "variable FLAIR_ROOT not defined")
17endif()
18
19if(NOT DEFINED ENV{FLAIR_ROOT})
20        err("variable FLAIR_ROOT not defined")
21endif()
22
23if(NOT FLAIR_DEV)
24        IF(FLAIR_DEV_TAG)
25                warn("Configuring flair-dev and flair-bin for tag ${FLAIR_DEV_TAG}")
26                SET(FLAIR_DEV $ENV{FLAIR_ROOT}/flair-dev_svn/tags/${FLAIR_DEV_TAG})
27                SET(FLAIR_BIN $ENV{FLAIR_ROOT}/flair-bin_svn/tags/${FLAIR_DEV_TAG})
28                if(EXISTS "${FLAIR_DEV}/cmake-modules/GlobalCmakeUAV.cmake")
29                        UNSET(FLAIR_DEV_TAG)
30                        include(${FLAIR_DEV}/cmake-modules/GlobalCmakeUAV.cmake)
31                        return()
32                else()
33                        err("File not found ${FLAIR_DEV}/cmake-modules/GlobalCmakeUAV.cmake Please check that ${FLAIR_DEV} is up to date")
34                endif()
35        ELSE()
36                SET(FLAIR_DEV $ENV{FLAIR_ROOT}/flair-dev)
37                SET(FLAIR_BIN $ENV{FLAIR_ROOT}/flair-bin)
38        ENDIF()
39ENDIF()
40
41include(${FLAIR_DEV}/cmake-modules/ArchDir.cmake)
42
43list(APPEND CMAKE_MODULE_PATH ${FLAIR_DEV}/cmake-modules/)
44
45#framework
46SET(FLAIR_USE_FILE ${FLAIR_DEV}/cmake-modules/FlairUseFile.cmake)
47
48#default executable ouput paths
49if(NOT DEFINED EXECUTABLE_OUTPUT_PATH)
50        SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
51endif()
52if(NOT DEFINED TARGET_EXECUTABLE_OUTPUT_PATH)
53        SET(TARGET_EXECUTABLE_OUTPUT_PATH bin)
54endif()
55
56#add definitions for archs
57if("${CMAKE_SYSTEM_PROCESSOR_DEFAULTTUNE}" MATCHES "armv7a-neon")       
58    ADD_DEFINITIONS(-DARMV7A)
59endif()
60
61if("${CMAKE_SYSTEM_PROCESSOR_DEFAULTTUNE}" MATCHES "armv5te")   
62    ADD_DEFINITIONS(-DARMV5TE)
63endif()
64
65if("${CMAKE_SYSTEM_PROCESSOR_DEFAULTTUNE}" MATCHES "core2-64") 
66    ADD_DEFINITIONS(-DCORE2_64)
67endif()
68
69#reimplement add executable to add a custom target for delivery (only on ARM)
70#delivery are read from ssh config file
71#also add a message to display architecture
72function(ADD_EXECUTABLE)
73        if("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "arm" AND EXISTS "$ENV{HOME}/.ssh/config")
74                file(STRINGS $ENV{HOME}/.ssh/config TEST)
75                foreach(f ${TEST})
76                        string(FIND ${f} "Host " POS)#cherche ligne host
77                        if(${POS} GREATER -1)
78                                string(REPLACE Host "" TARGET_NAME ${f})#enleve Host
79                                string(STRIP ${TARGET_NAME} TARGET_NAME)#enleve les espaces
80                        endif()
81                        string(FIND ${f} HostName POS)#cherche hostname
82                        if(${POS} GREATER -1)
83                                string(FIND ${f} "192.168." POS)#cherche addresse
84                                if(${POS} GREATER 0)#garde que les adresses en 192.168.x.x
85                                        string(REPLACE HostName "" ADDRESS ${f})#enleve Hostname
86                                        string(STRIP ${ADDRESS} ADDRESS)#enleve les espaces
87                                        #message("adding delivery target for " ${ARGV0} " (" ${ADDRESS} ")")
88                                        string(REPLACE "/" "_" TARGET_PATH ${TARGET_EXECUTABLE_OUTPUT_PATH})#les / ne sont pas acceptés
89                                        add_custom_target(
90                                            delivery_root_${ADDRESS}_${TARGET_PATH}_${ARGV0}
91                                            COMMAND make
92                                            COMMAND scp ${EXECUTABLE_OUTPUT_PATH}/${ARGV0} root@${ADDRESS}:${TARGET_EXECUTABLE_OUTPUT_PATH}
93                                        )
94                                endif()
95                        endif()
96                endforeach(f) 
97        endif()
98
99    #call original function
100        _ADD_EXECUTABLE(${ARGV})
101
102    #add a message to display architecture
103    string(SUBSTRING ${ARGV0} 0 5 TESTNAME) #check if it is qt4 internal target
104    if(NOT ${TESTNAME} MATCHES "Qt4::")
105        add_custom_command(TARGET ${ARGV0} POST_BUILD
106            COMMENT "${ARGV0} built for ${CMAKE_SYSTEM_PROCESSOR_DEFAULTTUNE} architecture")
107    endif()
108
109    #add a dependance to FlairLibs and FlairHdsLibs if we use the top level CMakeLists.txt and we need flairlibs
110    if(TARGET FlairLibs AND DEFINED FLAIRUSEFILE_INCLUDED)
111        add_dependencies(${ARGV0} FlairLibs)
112    endif()
113    if(TARGET FlairHdsLibs AND DEFINED FLAIRUSEFILE_INCLUDED)
114        add_dependencies(${ARGV0} FlairHdsLibs)
115    endif()
116endfunction()
117
118
119#reimplement add library to add a message to display architecture
120function(ADD_LIBRARY)
121    #call original function
122        _ADD_LIBRARY(${ARGV})
123    string(SUBSTRING ${ARGV0} 0 5 TESTNAME) #check if it is qt4 internal target
124    if(NOT ${TESTNAME} MATCHES "Qt4::")
125        add_custom_command(TARGET ${ARGV0} POST_BUILD
126            COMMENT "${ARGV0} built for ${CMAKE_SYSTEM_PROCESSOR_DEFAULTTUNE} architecture")
127    endif()
128endfunction()
129
130#copy resources (ex: demos scripts and xml)
131function(INSTALL)
132    if(COPY_RESOURCE_FILES)
133        FILE(GLOB RESOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/resources/${ARCH_DIR}/*")
134        foreach(item IN LISTS RESOURCE_FILES)
135            get_filename_component(filename ${item} NAME)
136            #do not overwrite: user can change xml or scripts
137            _INSTALL(CODE "
138                if (NOT EXISTS \"$ENV{FLAIR_ROOT}/flair-bin/demos/${ARCH_DIR}/${PROJECT_NAME}/${filename}\")
139                    file(INSTALL \"${item}\" DESTINATION \"$ENV{FLAIR_ROOT}/flair-bin/demos/${ARCH_DIR}/${PROJECT_NAME}\" USE_SOURCE_PERMISSIONS)
140                endif()
141            ")
142        endforeach()
143
144    endif()
145    #call original function
146        _INSTALL(${ARGV})
147endfunction()
Note: See TracBrowser for help on using the repository browser.