root/simulator/trunk/Modules/directories.cmake

Revision 1464, 13.5 kB (checked in by sehenley, 7 months ago)

Fix problem with cmake-2.8.1-rc3 - removed -fPIC from CXX and C Shared library flags.

Line 
1 #    OSRail -- a network enabled railroad operations simulator and utilities
2 #    Copyright (C) 2007,2008,2009,2010 Samuel E. Henley sehenley@comcast.net
3 #
4 #    This program is free software; you can redistribute it and/or modify
5 #    it under the terms of the GNU General Public License as published by
6 #    the Free Software Foundation; either version 2 of the License, or
7 #    (at your option) any later version.
8 #
9 #    This program is distributed in the hope that it will be useful,
10 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 #    GNU General Public License for more details.
13 #
14 #    You should have received a copy of the GNU General Public License along
15 #    with this program; if not, write to the Free Software Foundation, Inc.,
16 #    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 #
18 #
19 CMAKE_MINIMUM_REQUIRED( VERSION 2.6.3 )
20 #----------------------------------------------------------------------
21 ## \file
22 ## Checks directories for OSRail Build.
23 ## \page checkdirectoriescmake Checks directories for OSRail Build.
24 ## Checks directories sdk for OSRail build
25 ## \par
26 ## Uses
27 ## SIMULATOR_WORKING_DIRECTORY
28 ##
29 ## \par Includes
30 ## ${SIMULATOR_WORKING_DIRECTORY}/Modules/versions
31 ##
32 ## \par Sets
33 ## CMAKE_CONFIGURATION_TYPES
34 ## CMAKE_DEBUG_POSTFIX
35 ## SIMULATOR_WORKING_SOURCE_DIRECTORY
36 ## TRUNK_BRANCH_TAG
37 ## SIMULATOR_THIRD_PARTY_ROOT_DIRECTORY
38 ## SIMULATOR_WORKING_BINARY_DIRECTORY
39 ## CMAKE_BUILD_TYPE
40 ## CMAKE_RUNTIME_OUTPUT_DIRECTORY
41 ## CMAKE_STATIC_LIBRARY_PREFIX
42 ## CMAKE_STATIC_LIBRARY_SUFFIX
43 ## CMAKE_SHARED_LIBRARY_PREFIX
44 ## CMAKE_SHARED_LIBRARY_SUFFIX
45 ## CMAKE_EXECUTABLE_SUFFIX
46 ## COMPILER_PART
47 ## VENDOR
48 ## SIMULATOR_WORKING_ARCHIVE_DIRECTORY
49 ## CMAKE_ARCHIVE_OUTPUT_DIRECTORY
50 ## CMAKE_LIBRARY_OUTPUT_DIRECTORY
51 ## SIMULATOR_WORKING_INCLUDE_DIRECTORY
52 ## SIMULATOR_VENDOR_ROOT_DIRECTORY
53 ##
54 ## \par
55 ## Properties
56 ## PACKAGECONFIGURE_PC_FILES
57 ## PACKAGECONFIGURE_XXX-CONFIG_FILES
58 ##
59 ## \par
60 ##  Creates Directories
61 ## SIMULATOR_WORKING_SOURCE_DIRECTORY
62 ## SIMULATOR_WORKING_BINARY_DIRECTORY
63 ## SIMULATOR_WORKING_INCLUDE_DIRECTORY
64 ## SIMULATOR_WORKING_ARCHIVE_DIRECTORY
65 ## SIMULATOR_WORKING_BINARY_DIRECTORY/${CMAKE_CONFIGURATION_TYPES}
66 ## CMAKE_RUNTIME_OUTPUT_DIRECTORY
67 ##
68 ##
69 ##
70 #----------------------------------------------------------------------
71 MARK_AS_ADVANCED(
72
73     SIMULATOR_WORKING_SOURCE_DIRECTORY
74     TRUNK_BRANCH_TAG
75     SIMULATOR_THIRD_PARTY_ROOT_DIRECTORY
76     SIMULATOR_WORKING_BINARY_DIRECTORY
77     COMPILER_PART
78     VENDOR
79     SIMULATOR_WORKING_ARCHIVE_DIRECTORY
80     SIMULATOR_WORKING_INCLUDE_DIRECTORY
81     SIMULATOR_VENDOR_ROOT_DIRECTORY
82
83 )
84
85 ## \note Supported CMake Generators
86 ## - "MinGW Makefiles"
87 ## - "Unix Makefiles"
88 ## - "CodeBlocks"
89
90 #----------------------------------------------------------------------
91 # The working directory must be defined - can't get here without it.
92 #----------------------------------------------------------------------
93
94 IF( NOT SIMULATOR_WORKING_DIRECTORY )
95
96     MESSAGE( FATAL_ERROR "This script is intended to called from another script." )
97
98 ENDIF( NOT SIMULATOR_WORKING_DIRECTORY )
99
100 IF( NOT SIMULATOR_WORKING_BINARY_DIRECTORY )
101
102     MESSAGE( FATAL_ERROR "This script is intended to called from another script." )
103
104 ENDIF( NOT SIMULATOR_WORKING_BINARY_DIRECTORY )
105
106 ## \note Only Release and Debug build under Windows
107 IF( WIN32 )
108
109     SET( CMAKE_CONFIGURATION_TYPES Release )
110     LIST( APPEND CMAKE_CONFIGURATION_TYPES Debug )
111
112 ELSE( WIN32 )
113
114     SET( CMAKE_CONFIGURATION_TYPES RelWithDebInfo )
115     LIST( APPEND CMAKE_CONFIGURATION_TYPES Debug Release MinSizeRel )
116
117 ENDIF( WIN32 )
118
119 #Set a debug post fix
120 SET( CMAKE_DEBUG_POSTFIX "_d" )
121
122 # Version Strings used in messages
123 INCLUDE( versions )
124
125
126 # Project source files
127 SET( SIMULATOR_WORKING_SOURCE_DIRECTORY ${SIMULATOR_WORKING_DIRECTORY}/src
128     CACHE PATH
129     "Working source tree of the trunk or tag and branch name"  )
130
131 #----------------------------------------------------------------------
132
133
134 #----------------------------------------------------------------------
135 # The working directory is defined so get binary directory and the branch tag
136 #----------------------------------------------------------------------
137
138 STRING( REGEX MATCH "(tags/[^/]*$)|(branches/[^/]*$)|(trunk$)"
139                     TRUNK_BRANCH_TAG
140                     ${SIMULATOR_WORKING_DIRECTORY}
141 )
142
143 #Must use last directory of SIMULATOR_WORKING_DIRECTORY
144 IF( NOT TRUNK_BRANCH_TAG )
145
146     STRING( REGEX MATCH "([^/]*$)"
147                         TRUNK_BRANCH_TAG
148                         ${SIMULATOR_WORKING_DIRECTORY}
149     )
150
151 ENDIF( NOT TRUNK_BRANCH_TAG )
152
153 #----------------------------------------------------------------------
154 # The working directory and tag-branch are defined so get the root for 3rd party
155 # libraries.
156 #----------------------------------------------------------------------
157 IF( NOT SIMULATOR_THIRD_PARTY_ROOT_DIRECTORY )
158
159      IF( NOT SIMULATOR_THIRD_PARTY_ROOT_DIRECTORY )
160
161         # Third Party sdk
162         STRING( REGEX REPLACE "(/${TRUNK_BRANCH_TAG}[.]*$)" ""
163                               ONE
164                               ${SIMULATOR_WORKING_DIRECTORY}
165         )
166
167         # Third Party may be above simulator
168         STRING( REGEX REPLACE "(/simulator[.]*$)" ""
169                               SIMULATOR_THIRD_PARTY_ROOT_DIRECTORY
170                               ${ONE}
171         )
172
173     ENDIF( NOT SIMULATOR_THIRD_PARTY_ROOT_DIRECTORY )
174
175
176     IF( NOT SIMULATOR_THIRD_PARTY_ROOT_DIRECTORY )
177
178         MESSAGE( FATAL_ERROR "Can't find the third party sdk directory, it should\n"
179                              "be above your the branch/tag directory (${TRUNK_BRANCH_TAG})\n"
180                              "It can be set with -DSIMULATOR_THIRD_PARTY_ROOT_DIRECTORY=<<path>>\n"
181                              "on the cmake command line.\n"
182                              "example: \"cmake -DSIMULATOR_THIRD_PARTY_ROOT_DIRECTORY=${TRUNK_BRANCH_TAG} ..\"\n"
183                              "At this time in Linux, angelscript and boost must be in this directory."
184         )
185
186     ENDIF( NOT SIMULATOR_THIRD_PARTY_ROOT_DIRECTORY )
187
188 ENDIF( NOT SIMULATOR_THIRD_PARTY_ROOT_DIRECTORY )
189 # ////////////////////////////////////////////////////////////////////////////////////////////
190
191
192 MESSAGE( STATUS "Binary directory                ${SIMULATOR_WORKING_BINARY_DIRECTORY}" )
193
194 MESSAGE( STATUS "The branch/tag directory is     ${TRUNK_BRANCH_TAG}" )
195
196 MESSAGE( STATUS "Working directory               ${SIMULATOR_BINARY_DIRECTORY_NAME}" )
197
198 MESSAGE( STATUS "Third Party SDK directory       ${SIMULATOR_THIRD_PARTY_ROOT_DIRECTORY}" )
199
200
201 # ///////////////////////////////// MinGW  /////////////////////////////////
202
203 IF( CMAKE_GENERATOR MATCHES "MinGW Makefiles" )
204
205     IF( NOT CMAKE_BUILD_TYPE )
206
207         SET( CMAKE_BUILD_TYPE "Release" )
208
209     ENDIF( NOT CMAKE_BUILD_TYPE )
210
211     SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${SIMULATOR_WORKING_BINARY_DIRECTORY}/${CMAKE_BUILD_TYPE}
212           CACHE PATH
213          "Common Executable path for OSRail"
214     )
215
216     SET( CMAKE_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE} )
217
218
219 ENDIF( CMAKE_GENERATOR MATCHES "MinGW Makefiles" )
220
221 # ///////////////////////////////// Make  /////////////////////////////////
222
223 IF( CMAKE_GENERATOR MATCHES "Unix Makefiles" )
224
225     IF( NOT CMAKE_BUILD_TYPE )
226
227         SET( CMAKE_BUILD_TYPE "RelWithDebInfo" )
228
229     ENDIF( NOT CMAKE_BUILD_TYPE )
230
231     SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${SIMULATOR_WORKING_BINARY_DIRECTORY}/${CMAKE_BUILD_TYPE}
232           CACHE PATH
233          "Common Executable path for OSRail"
234     )
235
236
237 ENDIF( CMAKE_GENERATOR MATCHES "Unix Makefiles" )
238
239
240 # ///////////////////////////////// CodeBlocks  /////////////////////////////////
241
242 IF( CMAKE_GENERATOR MATCHES "CodeBlocks" )
243
244     SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${SIMULATOR_WORKING_BINARY_DIRECTORY}
245          CACHE PATH
246          "Common Executable path for OSRail"
247     )
248
249
250 ENDIF( CMAKE_GENERATOR MATCHES "CodeBlocks" )
251
252 SET( EXECUTABLE_OUTPUT_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
253      CACHE PATH
254      "Common Executable path for OSRail"
255 )
256
257 MESSAGE( STATUS "Runtime directory               ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" )
258
259 # ////////////////////////////////////////////////////////////////////////////////////////////
260 #----------------------------------------------------------------------
261 # Common path for all builds
262 #----------------------------------------------------------------------
263
264 IF( WIN32 )
265
266     IF(    CMAKE_GENERATOR MATCHES "MinGW Makefiles"
267         OR CMAKE_GENERATOR MATCHES "CodeBlocks"
268         OR CMAKE_GENERATOR MATCHES "CodeBlocks - MinGW Makefiles" )
269
270         SET( CMAKE_STATIC_LIBRARY_PREFIX "lib" )
271         SET( CMAKE_STATIC_LIBRARY_SUFFIX ".a" )
272         SET( CMAKE_SHARED_LIBRARY_PREFIX "" )
273         SET( CMAKE_SHARED_LIBRARY_SUFFIX ".dll" )
274         SET( CMAKE_EXECUTABLE_SUFFIX ".exe" )
275         SET( COMPILER_PART "gcc" )
276         SET( VENDOR "custom" )
277
278     ELSE(    CMAKE_GENERATOR MATCHES "MinGW Makefiles"
279           OR CMAKE_GENERATOR MATCHES "CodeBlocks"
280           OR CMAKE_GENERATOR MATCHES "CodeBlocks - MinGW Makefiles" )
281
282         SET( CMAKE_STATIC_LIBRARY_PREFIX "" )
283         SET( CMAKE_STATIC_LIBRARY_SUFFIX ".lib" )
284         SET( CMAKE_SHARED_LIBRARY_PREFIX "" )
285         SET( CMAKE_SHARED_LIBRARY_SUFFIX ".dll" )
286         SET( CMAKE_EXECUTABLE_SUFFIX ".exe" )
287         SET( COMPILER_PART "vc" )
288         SET( VENDOR "custom" )
289
290     ENDIF(    CMAKE_GENERATOR MATCHES "MinGW Makefiles"
291            OR CMAKE_GENERATOR MATCHES "CodeBlocks"
292            OR CMAKE_GENERATOR MATCHES "CodeBlocks - MinGW Makefiles" )
293
294     # -fPIC
295     SET (CMAKE_SHARED_LIBRARY_C_FLAGS "")
296     SET (CMAKE_SHARED_LIBRARY_CXX_FLAGS "")
297
298 ENDIF( WIN32 )
299
300
301 IF( UNIX )
302
303     SET( CMAKE_STATIC_LIBRARY_PREFIX "lib" )
304     SET( CMAKE_STATIC_LIBRARY_SUFFIX ".a" )
305
306     SET( CMAKE_SHARED_LIBRARY_PREFIX "lib" )
307
308     SET( CMAKE_SHARED_LIBRARY_SUFFIX ".so" )
309
310     SET( CMAKE_EXECUTABLE_SUFFIX "" )
311
312     SET( COMPILER_PART "gcc" )
313
314     SET( VENDOR "custom" )
315
316 ENDIF( UNIX )
317
318 #MESSAGE( FATAL_ERROR "exex post=${CMAKE_EXECUTABLE_SUFFIX}\n"
319 #                     "static pre=${CMAKE_STATIC_LIBRARY_PREFIX}\n"
320 #                     "static post=${CMAKE_STATIC_LIBRARY_SUFFIX}\n"
321 #                     "static post lk=${CMAKE_LINK_LIBRARY_SUFFIX}\n"
322 #                     "shared pre=${CMAKE_SHARED_LIBRARY_PREFIX}\n"
323 #                     "shared post=${CMAKE_SHARED_LIBRARY_SUFFIX}\n"
324 #                     "shared pre=${CMAKE_SHARED_MODULE_PREFIX}\n"
325 #                     "shared post=${CMAKE_SHARED_MODULE_SUFFIX}\n"
326 #)
327
328
329 # //////////////////////////////////////// Directories ////////////////////////////////////////
330 #----------------------------------------------------------------------
331 # The working directory bin and src directories - this is so cmake will
332 # generate a binary tree that is the same as the source tree but
333 # discardable.
334 #----------------------------------------------------------------------
335
336
337 # Built lib files and 3rd party library files
338
339 SET( SIMULATOR_WORKING_ARCHIVE_DIRECTORY ${SIMULATOR_WORKING_BINARY_DIRECTORY}/lib
340      CACHE PATH
341      "Enter full path to the build debug/release libraries"
342      FORCE
343 )
344
345 MESSAGE( STATUS "The archive output directory is ${SIMULATOR_WORKING_ARCHIVE_DIRECTORY}" )
346
347 SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${SIMULATOR_WORKING_ARCHIVE_DIRECTORY}
348     CACHE PATH
349     "Enter full path to the build debug/release libraries"
350     FORCE
351 )
352
353 IF( WIN32 )
354
355     SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
356         CACHE PATH
357         "Enter full path to the build debug/release libraries"
358         FORCE
359     )
360
361 ELSE( WIN32 )
362
363     SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${SIMULATOR_WORKING_ARCHIVE_DIRECTORY}
364         CACHE PATH
365         "Enter full path to the build debug/release libraries"
366         FORCE
367     )
368
369 ENDIF( WIN32 )
370
371 MESSAGE( STATUS "Shared library directory        ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}" )
372
373 # Required for generated header files
374 SET( SIMULATOR_WORKING_INCLUDE_DIRECTORY
375     ${SIMULATOR_WORKING_BINARY_DIRECTORY}/include
376     CACHE PATH
377     "Enter full path to the simulator built headers."
378     FORCE
379 )
380
381 SET( SIMULATOR_VENDOR_ROOT_DIRECTORY
382     ${SIMULATOR_WORKING_DIRECTORY}/vendor
383     CACHE PATH
384     "Enter full path to the simulator vendor tools/libraries."
385     FORCE
386 )
387
388 MESSAGE( STATUS "Vendor directory                ${SIMULATOR_VENDOR_ROOT_DIRECTORY}" )
389
390 ## \note PackageConfigure CMake Global, Directory and Target Property PACKAGECONFIGURE_PC_FILES
391 ## sets the location of a working directory for pkg-config utility pc files. This is used for
392 ## files that override or augment the /usr/... /lib/pkgconfig directory files.
393 ## If CMAKE_LIBRARY_OUTPUT_DIRECTORY is set - defaults to CMAKE_LIBRARY_OUTPUT_DIRECTORY/pkgconfig,
394 ## if not then CMAKE_BINARY_DIR/pkgconfig.
395
396 SET_PROPERTY( GLOBAL PROPERTY PACKAGECONFIGURE_PC_FILES ${SIMULATOR_WORKING_ARCHIVE_DIRECTORY}/pkgconfig )
397
398 ## \note PackageConfigure CMake Global, Directory and Target Property PACKAGECONFIGURE_XXX-CONFIG_FILES
399 ## sets the location of a working directory for xxx-config scripts. This is used for
400 ## files that replace, override or augment the /usr/... /bin scripts.
401 ## If set defaults to CMAKE_RUNTIME_OUTPUT_DIRECTORY - else CMAKE_BINARY_DIR
402
403 SET_PROPERTY( GLOBAL PROPERTY PACKAGECONFIGURE_XXX-CONFIG_FILES ${SIMULATOR_WORKING_BINARY_DIRECTORY}/Release )
404
405 FILE( MAKE_DIRECTORY ${SIMULATOR_WORKING_SOURCE_DIRECTORY} )
406 FILE( MAKE_DIRECTORY ${SIMULATOR_WORKING_BINARY_DIRECTORY} )
407 FILE( MAKE_DIRECTORY ${SIMULATOR_WORKING_INCLUDE_DIRECTORY} )
408 FILE( MAKE_DIRECTORY ${SIMULATOR_WORKING_ARCHIVE_DIRECTORY} )
409 FOREACH( DIR ${CMAKE_CONFIGURATION_TYPES} )
410     FILE( MAKE_DIRECTORY ${SIMULATOR_WORKING_BINARY_DIRECTORY}/${DIR} )
411 ENDFOREACH( DIR )
412
413 FILE( MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} )
414
415
416 # ////////////////////////////////////////////////////////////////////////////////////////////
Note: See TracBrowser for help on using the browser.