root/MedicalVisualizationProject/trunk/CMakeLists.txt

Revision 20, 11.1 kB (checked in by robert, 4 years ago)

Added initial cut of build system/framework

Line 
1IF(WIN32)
2    CMAKE_MINIMUM_REQUIRED(VERSION 2.4.6 FATAL_ERROR)
3ELSE(WIN32)
4    IF(APPLE)
5        CMAKE_MINIMUM_REQUIRED(VERSION 2.4.6 FATAL_ERROR)
6        IF(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4 AND ${CMAKE_PATCH_VERSION} LESS 7)
7            MESSAGE("Warning: A critical CMake bug exists in 2.4.6 and below. Trying to build Universal Binaries will result in a compile error that seems unrelated. Either avoid building Universal Binaries by changing the CMAKE_OSX_ARCHITECTURES field to list only your architecture, or upgrade to the current CVS version of CMake or a newer stable version if it exists.")
8        ENDIF(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4 AND ${CMAKE_PATCH_VERSION} LESS 7)
9    ELSE(APPLE)
10        CMAKE_MINIMUM_REQUIRED(VERSION 2.4.0 FATAL_ERROR)
11    ENDIF(APPLE)
12ENDIF(WIN32)
13
14if(COMMAND cmake_policy)
15    # Works around warnings libraries linked against that don't
16    # have absolute paths (e.g. -lpthreads)
17    cmake_policy(SET CMP0003 NEW)
18
19    # Works around warnings about escaped quotes in ADD_DEFINITIONS
20    # statements.
21    cmake_policy(SET CMP0005 OLD)
22endif(COMMAND cmake_policy)
23
24PROJECT(MEDCIALVISUALIZATIONPROJECT)
25
26SET(MEDCIALVISUALIZATIONPROJECT_MAJOR_VERSION 0)
27SET(MEDCIALVISUALIZATIONPROJECT_MINOR_VERSION 0)
28SET(MEDCIALVISUALIZATIONPROJECT_PATCH_VERSION 1)
29SET(MEDCIALVISUALIZATIONPROJECT_SOVERSION 0)
30
31SET(MEDCIALVISUALIZATIONPROJECT_VERSION ${MEDCIALVISUALIZATIONPROJECT_MAJOR_VERSION}.${MEDCIALVISUALIZATIONPROJECT_MINOR_VERSION}.${MEDCIALVISUALIZATIONPROJECT_PATCH_VERSION})
32
33# We want to build SONAMES shared librariess
34SET(MEDCIALVISUALIZATIONPROJECT_SONAMES TRUE)
35SET(OPENTHREADS_SONAMES TRUE)
36
37SET(OpenThreads_SOURCE_DIR ${MEDCIALVISUALIZATIONPROJECT_SOURCE_DIR})
38
39# We have some custom .cmake scripts not in the official distribution.
40# Maybe this can be used override existing behavior if needed?
41SET(CMAKE_MODULE_PATH "${MEDCIALVISUALIZATIONPROJECT_SOURCE_DIR}/CMakeModules;${CMAKE_MODULE_PATH}")
42
43
44# Okay, here's the problem: On some platforms, linking against OpenThreads
45# is not enough and explicit linking to the underlying thread library
46# is also required (e.g. FreeBSD). But OpenThreads may be built with different
47# backends (Pthreads, Sproc, Windows) so we don't know what the underlying
48# thread library is because some platforms support multiple backends (e.g.
49# IRIX supports Sproc and Pthreads). Linking all libraries won't work
50# because the libraries may be incompatible.
51# So the current solution is to attempt best guess linking and exempt certain
52# cases. With IRIX, we're going to hope explicit linking to the underlying
53# library is not necessary. We currently don't case for pthreads on Windows
54# which might be an issue on things like Cygwin. This may need to be fixed.
55FIND_PACKAGE(Threads)
56IF(CMAKE_SYSTEM MATCHES IRIX)
57    # Erase CMAKE_THREAD_LIBS_INIT and hope it works
58    SET(CMAKE_THREAD_LIBS_INIT "" CACHE INTERNAL "")
59ENDIF(CMAKE_SYSTEM MATCHES IRIX)
60
61# Find OpenGL
62FIND_PACKAGE(OpenGL)
63
64IF(UNIX)
65    # Not sure what this will do on Cygwin and Msys
66    # Also, remember OS X X11 is a user installed option so it may not exist.
67    FIND_PACKAGE(X11)
68    # Some Unicies need explicit linkage to the Math library or the build fails.
69    FIND_LIBRARY(MATH_LIBRARY m)
70ENDIF(UNIX)
71
72
73# Make the headers visible to everything
74INCLUDE_DIRECTORIES(
75    ${MEDCIALVISUALIZATIONPROJECT_SOURCE_DIR}/include
76    ${OPENGL_INCLUDE_DIR}
77)
78
79# Common global definitions
80#ADD_DEFINITIONS(-D)
81# Platform specific definitions
82
83########################################################################################################
84##### these were settings located in SetupCommon.cmake used in Luigi builds.... find out what are useful
85########################################################################################################
86#luigi#SET(CMAKE_VERBOSE_MAKEFILE TRUE)
87#luigi#SET(CMAKE_SKIP_RPATH TRUE)
88#luigi#SET(CMAKE_SKIP_RULE_DEPENDENCY TRUE)
89#luigi#IF(UNIX)
90#luigi#    LIST_CONTAINS(contains "g++" ${CMAKE_CXX_COMPILER_LIST})
91#luigi#    IF (contains)
92#luigi#        MESSAGE(${MY_MESSAGE_DEFAULT} "${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} setting  CMAKE_CXX_COMPILER to g++")
93#luigi#        SET(CMAKE_CXX_COMPILER "g++")
94#luigi#        SET(CMAKE_CXX_COMPILER_LOADED 2)
95#luigi#        SET(CMAKE_CXX_COMPILER_WORKS 2)
96#luigi#    ENDIF (contains)
97#luigi#    SET(CMAKE_CXX_FLAGS_RELEASE "-O2")
98#luigi#    SET(CMAKE_CXX_FLAGS_DEBUG "-ggdb -gstabs")
99#luigi#ENDIF(UNIX)
100########################################################################################################
101
102# Common to all platforms:
103SET(OSG_DIR "" CACHE PATH "set to base osg install path")
104
105SET(CMAKE_DEBUG_POSTFIX  "d")
106
107FIND_PACKAGE(OSG)
108
109################################################################################
110# Create bin and lib directories if required
111
112IF("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
113   FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/bin ${CMAKE_BINARY_DIR}/lib)
114ENDIF("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
115
116
117################################################################################
118# Installation stuff
119
120
121IF(UNIX AND NOT WIN32 AND NOT APPLE)
122  IF(CMAKE_SIZEOF_VOID_P MATCHES "8")
123      SET(LIB_POSTFIX "64" CACHE STRING "suffix for 32/64 dir placement")
124      MARK_AS_ADVANCED(LIB_POSTFIX)
125  ENDIF(CMAKE_SIZEOF_VOID_P MATCHES "8")
126ENDIF(UNIX AND NOT WIN32 AND NOT APPLE)
127IF(NOT DEFINED LIB_POSTFIX)
128    SET(LIB_POSTFIX "")
129ENDIF(NOT DEFINED LIB_POSTFIX)
130
131#SET(OUTPUT_BINDIR ${PROJECT_BINARY_DIR}/bin/${CMAKE_SYSTEM_NAME})
132SET(OUTPUT_BINDIR ${PROJECT_BINARY_DIR}/bin)
133MAKE_DIRECTORY(${OUTPUT_BINDIR})
134SET(EXECUTABLE_OUTPUT_PATH ${OUTPUT_BINDIR})
135
136#SET(OUTPUT_LIBDIR ${PROJECT_BINARY_DIR}/lib/${CMAKE_SYSTEM_NAME})
137SET(OUTPUT_LIBDIR ${PROJECT_BINARY_DIR}/lib)
138MAKE_DIRECTORY(${OUTPUT_LIBDIR})
139SET(LIBRARY_OUTPUT_PATH ${OUTPUT_LIBDIR})
140
141
142
143#SET(INSTALL_BINDIR MEDCIALVISUALIZATIONPROJECT/bin)
144#SET(INSTALL_INCDIR MEDCIALVISUALIZATIONPROJECT/include)
145#SET(INSTALL_LIBDIR MEDCIALVISUALIZATIONPROJECT/lib)
146#SET(INSTALL_DOCDIR MEDCIALVISUALIZATIONPROJECT/doc)
147
148################################################################################
149# User Options
150
151
152# Expose CMAKE_INCLUDE_PATH and CMAKE_LIBARY_PATH to the GUI so users
153# may set these values without needing to manipulate the environment.
154SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} CACHE STRING "You may add additional search paths here. Use ; to separate multiple paths.")
155SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} CACHE STRING "You may add additional search paths here. Use ; to separate multiple paths.")
156# We are proposing that a new variable called CMAKE_PREFIX_PATH be introduced
157# to CMake to compliment CMAKE_INCLUDE_PATH and CMAKE_LIBRARY_PATH.
158# A formal feature request has been submited to CMake, Bug #4947.
159# It is intended for those users who have common prefixes for their INCLUDE
160# and LIBRARY locations. So if users have headers in /usr/local/include
161# and libraries in /usr/local/lib, the common prefix is /usr/local.
162# It should also cover the case where headers and libraries are
163# in the same directory.
164# Our proposal expects that FIND_* commands will automatically search for
165# CMAKE_PREFIX_PATH right after CMAKE_INCLUDE_PATH or CMAKE_LIBRARY_PATH.
166# Obviously, since CMake does not currently support this, we must write
167# our Find*.cmake modules to explicitly support this. Otherwise, this variable
168# will have no impact.
169# This is unofficial so this may be removed or changed at anytime.
170SET(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} CACHE STRING "(EXPERIMENTAL) You may add additional search paths here. Use ; to separate multiple paths.")
171
172# Dynamic vs Static Linking
173OPTION(DYNAMIC_MEDCIALVISUALIZATIONPROJECT "Set to ON to build MEDCIALVISUALIZATIONPROJECT for dynamic linking.  Use OFF for static." ON)
174IF   (DYNAMIC_MEDCIALVISUALIZATIONPROJECT)
175    SET(MEDCIALVISUALIZATIONPROJECT_USER_DEFINED_DYNAMIC_OR_STATIC "SHARED")
176ELSE (DYNAMIC_MEDCIALVISUALIZATIONPROJECT)
177    SET(MEDCIALVISUALIZATIONPROJECT_USER_DEFINED_DYNAMIC_OR_STATIC "STATIC")
178ENDIF(DYNAMIC_MEDCIALVISUALIZATIONPROJECT)
179
180INCLUDE(MvpMacroUtils)
181
182# MVP Core
183# ADD_SUBDIRECTORY(src)
184
185# MVP Applications
186OPTION(BUILD_APPLICATIONS "Enable to build MVP Applications (e.g. osgdem)" ON)
187IF   (BUILD_APPLICATIONS)
188    ADD_SUBDIRECTORY(applications)
189ENDIF(BUILD_APPLICATIONS)
190
191
192
193# Set defaults for Universal Binaries. We want 32-bit Intel/PPC on 10.4
194# and 32/64-bit Intel/PPC on >= 10.5. Anything <= 10.3 doesn't support.
195IF(APPLE)
196    # These are just defaults/recommendations, but how we want to build
197    # out of the box. But the user needs to be able to change these options.
198    # So we must only set the values the first time CMake is run, or we
199    # will overwrite any changes the user sets.
200    # FORCE is used because the options are not reflected in the UI otherwise.
201    # Seems like a good place to add version specific compiler flags too.
202    IF(NOT MVP_CONFIG_HAS_BEEN_RUN_BEFORE)
203        # This is really fragile, but CMake doesn't provide the OS system
204        # version information we need. (Darwin versions can be changed
205        # independently of OS X versions.)
206        # It does look like CMake handles the CMAKE_OSX_SYSROOT automatically.
207        IF(EXISTS /Developer/SDKs/10.5.sdk)
208            SET(CMAKE_OSX_ARCHITECTURES "ppc;i386;ppc64;x86_64" CACHE STRING "Build architectures for OSX" FORCE)
209            SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.5 -ftree-vectorize -fvisibility-inlines-hidden" CACHE STRING "Flags used by the compiler during all build types." FORCE)
210        ELSE(EXISTS /Developer/SDKs/10.5.sdk)
211            IF(EXISTS /Developer/SDKs/MacOSX10.4u.sdk)
212                SET(CMAKE_OSX_ARCHITECTURES "ppc;i386" CACHE STRING "Build architectures for OSX" FORCE)
213                SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.4 -ftree-vectorize -fvisibility-inlines-hidden" CACHE STRING "Flags used by the compiler during all build types." FORCE)
214            ELSE(EXISTS /Developer/SDKs/MacOSX10.4u.sdk)
215                # No Universal Binary support
216                # Should break down further to set the -mmacosx-version-min,
217                # but the SDK detection is too unreliable here.
218            ENDIF(EXISTS /Developer/SDKs/MacOSX10.4u.sdk)
219        ENDIF(EXISTS /Developer/SDKs/10.5.sdk)
220    ENDIF(NOT MVP_CONFIG_HAS_BEEN_RUN_BEFORE)
221
222    OPTION(MVP_BUILD_APPLICATION_BUNDLES "Enable the building of applications and examples as OSX Bundles" OFF)
223
224ENDIF(APPLE)
225
226
227# This needs to be run very last so other parts of the scripts can take
228# advantage of this.
229IF(NOT MVP_CONFIG_HAS_BEEN_RUN_BEFORE)
230    SET(MVP_CONFIG_HAS_BEEN_RUN_BEFORE 1 CACHE INTERNAL "Flag to track whether this is the first time running CMake or if CMake has been configured before")
231ENDIF(NOT MVP_CONFIG_HAS_BEEN_RUN_BEFORE)
232
233
234#-----------------------------------------------------------------------------
235### uninstall target
236#-----------------------------------------------------------------------------
237CONFIGURE_FILE(
238  "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/cmake_uninstall.cmake.in"
239  "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
240  IMMEDIATE @ONLY)
241ADD_CUSTOM_TARGET(uninstall
242  "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
243
Note: See TracBrowser for help on using the browser.