-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRageCommon.cmake
224 lines (177 loc) · 6.89 KB
/
RageCommon.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#
# Usefull MACROS
#
# This macro merges elements in sorted lists ALIST and BLIST and stored the result in OUTPUT
MACRO(MERGE ALIST BLIST OUTPUT)
SET(BTEMP ${BLIST})
FOREACH(A ${ALIST})
SET(SORTED)
SET(UNINSERTED 1)
FOREACH(B ${BTEMP})
IF(${UNINSERTED})
IF(${A} STRLESS ${B})
SET(SORTED ${SORTED} ${A})
SET(UNINSERTED 0)
ENDIF(${A} STRLESS ${B})
ENDIF(${UNINSERTED})
SET(SORTED ${SORTED} ${B})
ENDFOREACH(B ${BLIST})
IF(${UNINSERTED})
SET(SORTED ${SORTED} ${A})
ENDIF(${UNINSERTED})
SET(BTEMP ${SORTED})
ENDFOREACH(A ${ALIST})
SET(${OUTPUT} ${BTEMP})
ENDMACRO(MERGE ALIST BLIST OUTPUT)
# macro to get the SVN Revision number
find_program( SVNVERSION
svnversion
/usr/local/bin
/usr/pkg/bin
/usr/bin
)
macro( svn_repository_version DESTVAR TOPDIR )
# Only work if SVNVERSION exist (prog founded)
IF(SVNVERSION)
exec_program( ${SVNVERSION} ${TOPDIR} ARGS "." OUTPUT_VARIABLE DESTVARORI )
STRING(REGEX REPLACE "(.+):(.+)" "\\1_\\2" ${DESTVAR} ${DESTVARORI})
ENDIF(SVNVERSION)
endmacro( svn_repository_version )
#
# Configure and Build process based on well-known hierarchy
#
MACRO (RAGE_BUILD project_name project_type)
# Managing Build Types
# default build type
IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE)
ENDIF(NOT CMAKE_BUILD_TYPE)
#Verbose Makefile if not release build
IF (CMAKE_BUILD_TYPE STREQUAL Release)
#on for debugging build commands only. should be off otherwise
SET(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "Verbose build commands disabled for Release build" FORCE)
ELSE (CMAKE_BUILD_TYPE STREQUAL Release)
SET(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "Verbose build commands enabled for Non Release build" FORCE)
ENDIF (CMAKE_BUILD_TYPE STREQUAL Release)
FILE(GLOB_RECURSE HEADERS ${CMAKE_SOURCE_DIR}/include/*.hh)
#Including configured headers (binary for the configured header, source for the unmodified ones, and in source/src for internal ones)
INCLUDE_DIRECTORIES( ${CMAKE_BINARY_DIR}/include ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src)
#Defining target
FILE(GLOB_RECURSE SOURCES ${CMAKE_SOURCE_DIR}/src/*.cc)
MERGE("${HEADERS}" "${SOURCES}" SOURCES)
IF(${project_type} STREQUAL "LIBRARY")
ADD_LIBRARY(${project_name} ${SOURCES})
ENDIF(${project_type} STREQUAL "LIBRARY")
IF(${project_type} STREQUAL "EXECUTABLE")
ADD_EXECUTABLE(${project_name} ${SOURCES})
ENDIF(${project_type} STREQUAL "EXECUTABLE")
#needed in case we dont have recognised file extension
SET_TARGET_PROPERTIES(${project_name} PROPERTIES LINKER_LANGUAGE CXX)
#
#Defining where to put whats been built
#
SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib CACHE PATH "Ouput directory for libraries")
SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin CACHE PATH "Output directory for executables")
EXPORT_LIBRARY_DEPENDENCIES(${CMAKE_BINARY_DIR}/CMakeDepends.txt)
ENDMACRO (RAGE_BUILD)
#
# Defining test rules
#
MACRO(RAGE_TEST project)
SET(ENABLE_TESTS OFF CACHE BOOL "Wether or not you want the project to include the tests and enable automatic testing")
IF(ENABLE_TESTS)
ENABLE_TESTING()
ADD_SUBDIRECTORY(test)
ENDIF(ENABLE_TESTS)
ENDMACRO(RAGE_TEST)
#
# Defining installation rules
#
MACRO (RAGE_INSTALL project_name)
INSTALL ( FILES ${HEADERS} DESTINATION ${VERSION}/include )
INSTALL (
TARGETS ${project_name}
RUNTIME DESTINATION ${VERSION}/bin
LIBRARY DESTINATION ${VERSION}/lib
ARCHIVE DESTINATION ${VERSION}/lib/static
)
ENDMACRO(RAGE_INSTALL project_name)
#
# Common use of Cmake in RAGE
#
svn_repository_version( SVN_REV ${CMAKE_SOURCE_DIR})
SET (VERSION ${SVN_REV} CACHE STRING "The detected revision of the source repository" FORCE)
SET(BUILD_SHARED_LIBS OFF)
#
#Compiler Specific rules
# All modifications for Flags should be here
#
IF(MSVC)
MESSAGE( STATUS "Visual Studio Compiler detected. Adjusting C++ flags...")
IF (CMAKE_BUILD_TYPE STREQUAL Debug)
ADD_DEFINITIONS(-D_DEBUG)
SET( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /wd4100 /wd4290 /wd4512")
SET( CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:msvcrt.lib" )
SET(CMAKE_CXX_WARNING_LEVEL 4)
SET(CHECK_MEM_LEAKS OFF CACHE BOOL "On to check memory with VLD (must be installed)")
IF(CHECK_MEM_LEAKS)
ADD_DEFINITIONS(-DVLD)
ENDIF(CHECK_MEM_LEAKS)
ENDIF (CMAKE_BUILD_TYPE STREQUAL Debug)
IF (CMAKE_BUILD_TYPE STREQUAL Release)
ADD_DEFINITIONS(-DNDEBUG)
SET(CMAKE_CXX_WARNING_LEVEL 2)
ENDIF (CMAKE_BUILD_TYPE STREQUAL Release)
ENDIF(MSVC)
IF(CMAKE_COMPILER_IS_GNUCXX)
MESSAGE( STATUS "GCC Compiler detected. Adjusting C++ flags...")
SET(GENERATE_PROFILING_INFO OFF CACHE BOOL "On to generate profiling information to use with gprof.")
SET(PROFILE_FLAG)
IF(GENERATE_PROFILING_INFO)
SET(PROFILE_FLAG -pg)
ENDIF(GENERATE_PROFILING_INFO)
SET( CMAKE_C_FLAGS "${PROFILE_FLAG} -Wall -pedantic" CACHE STRING
"Flags for C compiler."
)
SET( CMAKE_C_FLAGS_DEBUG "-g -D_DEBUG" CACHE STRING
"Flags used by the C compiler during debug builds."
)
SET( CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG " CACHE STRING
"Flags used by the C compiler during release minsize builds."
)
SET( CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG " CACHE STRING
"Flags used by the C compiler during release builds."
)
SET( CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g" CACHE STRING
"Flags used by the C compiler during release with debug info builds."
)
SET( CMAKE_CXX_FLAGS "${PROFILE_FLAG} -Wall -Wabi -pedantic" CACHE STRING
"Flags for C++ compiler."
)
SET( CMAKE_CXX_FLAGS_DEBUG "-g -D_DEBUG" CACHE STRING
"Flags used by the C++ compiler during debug builds."
)
SET( CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG " CACHE STRING
"Flags used by the C++ compiler during release minsize builds."
)
SET( CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG " CACHE STRING
"Flags used by the C++ compiler during release builds."
)
SET( CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g" CACHE STRING
"Flags used by the C++ compiler during release with debug info builds."
)
SET(RAGE_COMMON_LINKER_FLAGS)
IF (MSYS)
SET(RAGE_COMMON_LINKER_FLAGS -Wl,--warn-once)
ELSE (MSYS)
SET(RAGE_COMMON_LINKER_FLAGS -Wl,--warn-unresolved-symbols,--warn-once)
ENDIF (MSYS)
SET( CMAKE_EXE_LINKER_FLAGS
"${PROFILE_FLAG} ${RAGE_COMMON_LINKER_FLAGS}" CACHE STRING
"Flags used by the linker."
)
SET( CMAKE_SHARED_LINKER_FLAGS
"${PROFILE_FLAG} ${RAGE_COMMON_LINKER_FLAGS}" CACHE STRING
"Flags used by the linker."
)
ENDIF(CMAKE_COMPILER_IS_GNUCXX)