Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/CMakeLists.txt @ 8412

Last change on this file since 8412 was 8412, checked in by rgrieder, 13 years ago

MSVC specific:
Sorted out Visual Leak Detector handling (it's now treated like a real library, not as a hack).
Also, the vld.h include is gone and with it windows.h.

  • Property svn:eol-style set to native
File size: 8.6 KB
Line 
1 #
2 #             ORXONOX - the hottest 3D action shooter ever to exist
3 #                             > www.orxonox.net <
4 #
5 #        This program is free software; you can redistribute it and/or
6 #         modify it under the terms of the GNU General Public License
7 #        as published by the Free Software Foundation; either version 2
8 #            of the License, or (at your option) any later version.
9 #
10 #       This program is distributed in the hope that it will be useful,
11 #        but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 #                 GNU General Public License for more details.
14 #
15 #   You should have received a copy of the GNU General Public License along
16 #      with this program; if not, write to the Free Software Foundation,
17 #     Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18 #
19 #
20 #  Author:
21 #    Reto Grieder
22 #  Description:
23 #    Configures the compilers and sets build options.
24 #
25
26# Required macros and functions
27INCLUDE(FlagUtilities)
28INCLUDE(TargetUtilities)
29
30# Configure the two headers and set some options
31INCLUDE(OrxonoxConfig.cmake)
32
33####### Library Behaviour (dependencies) ########
34
35# Disable auto linking completely for Boost and POCO
36ADD_COMPILER_FLAGS("-DBOOST_ALL_NO_LIB")
37ADD_COMPILER_FLAGS("-DPOCO_NO_AUTOMATIC_LIBS")
38
39IF(WIN32)
40  # If no defines are specified, these libs get linked statically
41  ADD_COMPILER_FLAGS("-DBOOST_ALL_DYN_LINK" LINK_BOOST_DYNAMIC)
42  #ADD_COMPILER_FLAGS("-DENET_DLL"           LINK_ENET_DYNAMIC)
43  ADD_COMPILER_FLAGS("-DLUA_BUILD_AS_DLL"   LINK_LUA5.1_DYNAMIC)
44  # If no defines are specified, these libs get linked dynamically
45  ADD_COMPILER_FLAGS("-DCEGUI_STATIC -DTOLUA_STATIC" NOT LINK_CEGUI_DYNAMIC)
46  ADD_COMPILER_FLAGS("-DOGRE_STATIC_LIB"    NOT LINK_OGRE_DYNAMIC)
47  ADD_COMPILER_FLAGS("-DSTATIC_BUILD"       NOT LINK_TCL_DYNAMIC)
48
49  # Target Windows XP as minimum Windows version
50  # And try to catch all the different macro defines for that...
51  ADD_COMPILER_FLAGS("-D_WIN32_WINNT=0x0501")
52  ADD_COMPILER_FLAGS("-D_WIN32_WINDOWS=0x0501")
53  ADD_COMPILER_FLAGS("-DWINVER=0x0501")
54  ADD_COMPILER_FLAGS("-DNTDDI_VERSION=0x05010000")
55ENDIF(WIN32)
56
57# Visual Leak Dectector configuration
58IF(MSVC AND VLD_FOUND)
59  OPTION(VISUAL_LEAK_DETECTOR_ENABLE "Memory leak detector" OFF)
60  IF(VISUAL_LEAK_DETECTOR_ENABLE)
61    # Force library linking by forcing the inclusion of a symbol
62    ADD_LINKER_FLAGS("-INCLUDE:__imp_?vld@@3VVisualLeakDetector@@A" Debug)
63    IF(MSVC90)
64      # VS 2008 incremental linker crashes with /INCLUDE most of the time
65      REMOVE_LINKER_FLAGS("-INCREMENTAL:YES" Debug)
66      ADD_LINKER_FLAGS   ("-INCREMENTAL:NO"  Debug)
67    ENDIF()
68  ENDIF()
69ENDIF()
70
71######### Library Behaviour (external) ##########
72
73# Use TinyXML++
74ADD_COMPILER_FLAGS("-DTIXML_USE_TICPP")
75
76# Default linking for externals is SHARED
77SET(ORXONOX_EXTERNAL_LINK_MODE "STATIC" CACHE STRING "Link mode for external libraries that we build ourselves. Note: on Windows, some libraries cannot be linked shared.")
78
79IF(ORXONOX_EXTERNAL_LINK_MODE STREQUAL "SHARED")
80  SET(_external_shared_link TRUE)
81ELSE()
82  SET(_external_shared_link FALSE)
83ENDIF()
84# If no defines are specified, these libs get linked dynamically
85ADD_COMPILER_FLAGS("-DENET_DLL"                    WIN32     _external_shared_link)
86ADD_COMPILER_FLAGS("-DOGRE_GUIRENDERER_STATIC_LIB" WIN32 NOT _external_shared_link)
87ADD_COMPILER_FLAGS("-DOIS_STATIC_LIB"              WIN32 NOT _external_shared_link)
88
89############## Include Directories ##############
90
91# Set the search paths for include files
92INCLUDE_DIRECTORIES(
93  # OrxonoxConfig.h
94  ${CMAKE_CURRENT_BINARY_DIR}
95
96  # All includes in "externals" should be prefixed with the path
97  # relative to "external" to avoid conflicts
98  ${CMAKE_CURRENT_SOURCE_DIR}/external
99  # Include directories needed even if only included by Orxonox
100  ${CMAKE_CURRENT_SOURCE_DIR}/external/bullet
101  ${CMAKE_CURRENT_SOURCE_DIR}/external/ois
102
103  # External
104  ${OGRE_INCLUDE_DIR}
105  ${CEGUI_INCLUDE_DIR}
106  ${CEGUI_TOLUA_INCLUDE_DIR}
107  #${ENET_INCLUDE_DIR}
108  ${Boost_INCLUDE_DIRS}
109  ${POCO_INCLUDE_DIR}
110  ${OPENAL_INCLUDE_DIRS}
111  ${ALUT_INCLUDE_DIR}
112  ${VORBIS_INCLUDE_DIR}
113  ${OGG_INCLUDE_DIR}
114  ${LUA5.1_INCLUDE_DIR}
115  ${TCL_INCLUDE_PATH}
116  ${DIRECTX_INCLUDE_DIR}
117  ${ZLIB_INCLUDE_DIR}
118)
119
120IF(CEGUI_OLD_VERSION)
121  INCLUDE_DIRECTORIES(${CEGUILUA_INCLUDE_DIR})
122ENDIF()
123
124IF (DBGHELP_FOUND)
125  INCLUDE_DIRECTORIES(${DBGHELP_INCLUDE_DIR})
126ENDIF()
127
128IF(VISUAL_LEAK_DETECTOR_ENABLE)
129  INCLUDE_DIRECTORIES(${VLD_INCLUDE_DIR})
130ENDIF()
131
132############## CEGUI OGRE Renderer ##############
133
134IF(CEGUI_OGRE_RENDERER_BUILD_REQUIRED)
135  SET(CEGUI_OGRE_RENDERER_LIBRARY ogreceguirenderer_orxonox)
136ENDIF()
137
138################### Tolua Bind ##################
139
140# Create directory because the tolua application doesn't work otherwise
141IF(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/toluabind/${CMAKE_CFG_INTDIR})
142  FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/toluabind/${CMAKE_CFG_INTDIR})
143ENDIF()
144
145INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/toluabind/${CMAKE_CFG_INTDIR})
146
147################ Sub Directories ################
148
149ADD_SUBDIRECTORY(external)
150ADD_SUBDIRECTORY(libraries)
151ADD_SUBDIRECTORY(orxonox)
152SET(ORXONOX_MODULES CACHE INTERNAL "")
153ADD_SUBDIRECTORY(modules)
154
155################## Executable ###################
156
157INCLUDE_DIRECTORIES(
158  ${CMAKE_CURRENT_SOURCE_DIR}/libraries
159  ${CMAKE_CURRENT_SOURCE_DIR}/orxonox
160)
161
162# Translate argument
163IF(ORXONOX_USE_WINMAIN)
164  SET(ORXONOX_WIN32 WIN32)
165ENDIF()
166
167SET(ORXONOX_MAIN_FILES Orxonox.cc)
168
169# Add special source file for OS X
170IF(APPLE)
171  LIST(APPEND ORXONOX_MAIN_FILES OrxonoxMac.mm)
172ENDIF()
173
174ORXONOX_ADD_EXECUTABLE(orxonox-main
175  # When defined as WIN32 this removes the console window on Windows
176  ${ORXONOX_WIN32}
177  LINK_LIBRARIES
178    orxonox
179  SOURCE_FILES
180    ${ORXONOX_MAIN_FILES}
181  OUTPUT_NAME orxonox
182)
183# Main executable should depend on all modules
184ADD_DEPENDENCIES(orxonox-main ${ORXONOX_MODULES})
185
186# Get name to configure the run scripts
187GET_TARGET_PROPERTY(_exec_loc orxonox-main LOCATION)
188GET_FILENAME_COMPONENT(_exec_name ${_exec_loc} NAME)
189SET(ORXONOX_EXECUTABLE_NAME ${_exec_name} CACHE INTERNAL "")
190
191
192# When using Visual Studio we want to use the output directory as working
193# directory and we also want to specify where the external dlls
194# (lua, ogre, etc.) are. The problem hereby is that these information cannot
195# be specified in CMake because they are not stored in the actual project file.
196# This workaround will create a configured *.vcproj.user file that holds the
197# right values. When starting the solution for the first time,
198# these get written to the *vcproj.yourPCname.yourname.user
199IF(MSVC)
200  IF(CMAKE_CL_64)
201    SET(MSVC_PLATFORM "x64")
202  ELSE()
203    SET(MSVC_PLATFORM "Win32")
204  ENDIF()
205  IF(MSVC10)
206    CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/orxonox-main.vcxproj.user.in" "${CMAKE_CURRENT_BINARY_DIR}/orxonox-main.vcxproj.user")
207  ELSE()
208    STRING(REGEX REPLACE "^Visual Studio ([0-9][0-9]?).*$" "\\1"
209           VISUAL_STUDIO_VERSION_SIMPLE "${CMAKE_GENERATOR}")
210    CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/orxonox-main.vcproj.user.in" "${CMAKE_CURRENT_BINARY_DIR}/orxonox-main.vcproj.user")
211  ENDIF()
212ENDIF(MSVC)
213
214# Apple Mac OS X specific build settings
215IF(APPLE)
216  # On Apple we need to link to AppKit and Foundation frameworks
217  TARGET_LINK_LIBRARIES(orxonox-main
218    "-framework AppKit"
219    "-framework Foundation"
220  )
221
222  # Post-build step for the creation of the Dev-App bundle
223  INCLUDE(PrepareDevBundle)
224  ADD_CUSTOM_COMMAND(
225    TARGET orxonox-main
226    POST_BUILD
227    # Copy the executable into the Orxonox.app
228    COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/${ORXONOX_EXECUTABLE_NAME}" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/${PROJECT_NAME}.app/Contents/MacOS"
229    # Copy the dev-build marker file to Orxonox.app
230    COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/orxonox_dev_build.keep_me" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/${PROJECT_NAME}.app/Contents/MacOS"
231    # Create a shortcut of the application to the root of the build tree
232    COMMAND ${CMAKE_COMMAND} -E create_symlink "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/${PROJECT_NAME}.app" "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.app"
233  )
234ENDIF(APPLE)
235
236#################### Doxygen ####################
237
238# Prepare include paths for Doxygen. This is necessary to display
239# the correct path to use when including a file, e.g.
240# core/XMLPort.h instead of src/core/XMLPort.h
241
242INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/modules)
243GET_DIRECTORY_PROPERTY(_temp INCLUDE_DIRECTORIES)
244# Replace ';' by spaces
245STRING(REPLACE ";" " " _temp "${_temp}")
246SET(DOXYGEN_INCLUDE_DIRECTORIES "${_temp}" PARENT_SCOPE)
Note: See TracBrowser for help on using the repository browser.