cmake: Add LAYOUT option to control install paths.
[gemrb.git] / CMakeLists.txt
blob7ceddf8c0283582bc4c40e0f133e954c610599e7
1 cmake_minimum_required(VERSION 2.4.4)
2 if(COMMAND cmake_policy)
3       cmake_policy(SET CMP0003 NEW)
4       cmake_policy(SET CMP0005 NEW)
5 endif(COMMAND cmake_policy)
7 PROJECT(GemRB)
9 IF(PREFIX)
10   SET(PREFIX CACHE PATH "Abbreviation for CMAKE_INSTALL_PREFIX.")
11   SET(CMAKE_INSTALL_PREFIX ${PREFIX})
12 ENDIF(PREFIX)
14 if (NOT "${LAYOUT}")
15         if (WIN32)
16                 set(LAYOUT "home")
17         else (WIN32)
18                 set(LAYOUT "fhs")
19         endif (WIN32)
20 endif (NOT "${LAYOUT}")
22 SET(LAYOUT CACHE STRING "Directory layout.")
24 if (${LAYOUT} MATCHES "home")
25         IF( NOT PLUGIN_DIR )
26                 SET( PLUGIN_DIR ${CMAKE_INSTALL_PREFIX}/plugins )
27         ENDIF( NOT PLUGIN_DIR )
28         IF( NOT DATA_DIR )
29                 SET( DATA_DIR ${CMAKE_INSTALL_PREFIX} )
30         ENDIF( NOT DATA_DIR )
31         IF( NOT MAN_DIR )
32                 SET( MAN_DIR ${CMAKE_INSTALL_PREFIX}/man/man6 )
33         ENDIF( NOT MAN_DIR )
34         IF( NOT BIN_DIR )
35                 SET( BIN_DIR ${CMAKE_INSTALL_PREFIX} )
36         ENDIF( NOT BIN_DIR )
37         IF( NOT SYSCONF_DIR )
38                 SET( SYSCONF_DIR ${CMAKE_INSTALL_PREFIX} )
39         ENDIF( NOT SYSCONF_DIR )
40         IF( NOT LIB_DIR )
41                 SET( LIB_DIR ${CMAKE_INSTALL_PREFIX} )
42         ENDIF( NOT LIB_DIR )
43 elseif (${LAYOUT} MATCHES "fhs")
44         IF( NOT LIB_DIR )
45                 SET( LIB_DIR ${CMAKE_INSTALL_PREFIX}/lib/gemrb )
46         ENDIF( NOT LIB_DIR )
47         IF( NOT PLUGIN_DIR )
48                 SET( PLUGIN_DIR ${LIB_DIR}/plugins )
49         ENDIF( NOT PLUGIN_DIR )
50         IF( NOT DATA_DIR )
51                 SET( DATA_DIR ${CMAKE_INSTALL_PREFIX}/share/gemrb )
52         ENDIF( NOT DATA_DIR )
53         IF( NOT MAN_DIR )
54                 SET( MAN_DIR ${CMAKE_INSTALL_PREFIX}/share/man/man6 )
55         ENDIF( NOT MAN_DIR )
56         IF( NOT BIN_DIR )
57                 SET( BIN_DIR ${CMAKE_INSTALL_PREFIX}/bin )
58         ENDIF( NOT BIN_DIR )
59         IF( NOT SYSCONF_DIR )
60                 SET( SYSCONF_DIR ${CMAKE_INSTALL_PREFIX}/etc/gemrb )
61         ENDIF( NOT SYSCONF_DIR )
62 else (${LAYOUT} MATCHES "opt")
63         IF( NOT LIB_DIR )
64                 SET( LIB_DIR ${CMAKE_INSTALL_PREFIX}/lib )
65         ENDIF( NOT LIB_DIR )
66         IF( NOT PLUGIN_DIR )
67                 SET( PLUGIN_DIR ${LIB_DIR}/plugins )
68         ENDIF( NOT PLUGIN_DIR )
69         IF( NOT DATA_DIR )
70                 SET( DATA_DIR ${CMAKE_INSTALL_PREFIX}/share/ )
71         ENDIF( NOT DATA_DIR )
72         IF( NOT MAN_DIR )
73                 SET( MAN_DIR ${CMAKE_INSTALL_PREFIX}/man/man6 )
74         ENDIF( NOT MAN_DIR )
75         IF( NOT BIN_DIR )
76                 SET( BIN_DIR ${CMAKE_INSTALL_PREFIX}/bin )
77         ENDIF( NOT BIN_DIR )
78         IF( NOT SYSCONF_DIR )
79                 SET( SYSCONF_DIR ${CMAKE_INSTALL_PREFIX}/etc )
80         ENDIF( NOT SYSCONF_DIR )
81 endif (${LAYOUT} MATCHES "home")
84 IF(CMAKE_COMPILER_IS_GNUCXX)
85  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror")
86 ENDIF(CMAKE_COMPILER_IS_GNUCXX)
88 MESSAGE(STATUS "Looking for Python libraries")
89 INCLUDE(FindPythonLibs)
90 IF(PYTHON_LIBRARY)
91  MESSAGE(STATUS "Python Libraries Found")
92 ELSE(PYTHON_LIBRARY)
93  MESSAGE(FATAL_ERROR "Unable to find Python development libraries. Please get it from www.python.org")
94 ENDIF(PYTHON_LIBRARY)
96 MESSAGE(STATUS "Looking for openAL libraries")
97 INCLUDE(FindOpenAL)
98 IF(OPENAL_FOUND)
99  MESSAGE(STATUS "openal found")
100 ELSE(OPENAL_FOUND)
101  MESSAGE(ERROR "unable to find openal. please set OPENALDIR environment variable or get it from www.openal.org")
102 ENDIF(OPENAL_FOUND)
104 MESSAGE(STATUS "Looking for SDL")
105 INCLUDE(FindSDL)
106 IF(SDL_FOUND)
107  MESSAGE(STATUS "SDL found")
108 ELSE(SDL_FOUND)
109  MESSAGE(FATAL_ERROR "unable to find SDL. please get it from www.libsdl.org")
110 ENDIF(SDL_FOUND)
112 MESSAGE( STATUS "Looking for Zlib" )
113 #SET(ZLIB_FIND_REQUIRED TRUE)
114 INCLUDE(FindZLIB)
116 MESSAGE( STATUS "Looking for libPNG" )
117 INCLUDE(FindPNG)
118 IF(PNG_FOUND)
119  MESSAGE( STATUS "libPNG found" )
120 ELSE(PNG_FOUND)
121  MESSAGE( STATUS "WARNING : GemRB will be built without any PNG support. Get it from www.libpng.org" )
122 ENDIF(PNG_FOUND)
124 IF(UNIX)
125  MESSAGE(STATUS "Looking for dl library")
126  FIND_LIBRARY(DLD_LIBRARY_PATH dl dld)
127  IF(DLD_LIBRARY_PATH)
128   MESSAGE(STATUS "dl library found")
129  ELSE(DLD_LIBRARY_PATH)
130   MESSAGE(FATAL_ERROR "dl library not found")
131  ENDIF(DLD_LIBRARY_PATH)
132 ENDIF(UNIX)
134 MESSAGE(STATUS "Looking for Ogg Vorbis support")
135 FIND_LIBRARY(VORBIS_LIBRARY vorbisfile)
137 ADD_DEFINITIONS("-DHAVE_CONFIG_H")
139 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
141 #Platform checks
142 INCLUDE (CheckTypeSize)
143 CHECK_TYPE_SIZE("int" SIZEOF_INT)
144 CHECK_TYPE_SIZE("long int" SIZEOF_LONG_INT)
146 INCLUDE (CheckFunctionExists)
147 CHECK_FUNCTION_EXISTS("snprintf" HAVE_SNPRINTF)
148 CHECK_FUNCTION_EXISTS("strndup" HAVE_STRNDUP)
150 #Unneeded on windows
151 IF(NOT WIN32)
152 INCLUDE (CheckCXXSourceCompiles)
153 CHECK_CXX_SOURCE_COMPILES("typedef void *(* voidvoid)(void);
155 void *object = 0;
156 voidvoid function;
157 function = (voidvoid) object;
158 " PERMITS_OBJECT_TO_FUNCTION_CAST)
160 IF( NOT PERMITS_OBJECT_TO_FUNCTION_CAST )
161  SET(HAVE_FORBIDDEN_OBJECT_TO_FUNCTION_CAST 1)
162 ENDIF( NOT PERMITS_OBJECT_TO_FUNCTION_CAST )
163 ENDIF(NOT WIN32)
165 IF(VORBIS_LIBRARY)
166  SET(HAS_VORBIS_SUPPORT 1)
167 ELSE(VORBIS_LIBRARY)
168  SET(VORBIS_LIBRARY "")
169 ENDIF(VORBIS_LIBRARY)
171 IF(APPLE)
172  FIND_LIBRARY(SDL_MAIN_LIBRARY_PATH SDLmain)
173  FIND_LIBRARY(COCOA_LIBRARY_PATH Cocoa)
174 ENDIF(APPLE)
176 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
178 #Plugin addition macro
179 MACRO(ADD_GEMRB_PLUGIN plugin_name)
180 ADD_LIBRARY(${plugin_name} MODULE ${ARGN})
181 SET_TARGET_PROPERTIES(${plugin_name} PROPERTIES PREFIX "")
182 IF(WIN32)
183  TARGET_LINK_LIBRARIES(${plugin_name} gemrb_core)
184 ENDIF(WIN32)
185 IF(APPLE)
186  TARGET_LINK_LIBRARIES(${plugin_name} gemrb_core)
187 ENDIF(APPLE)
188 INSTALL(TARGETS ${plugin_name} DESTINATION ${PLUGIN_DIR})
189 ENDMACRO(ADD_GEMRB_PLUGIN)
191 #gemrb overrides macro
192 MACRO(ADD_GEMRB_OVERRIDE game_name)
193 FILE( GLOB FILES_TO_INSTALL *.2da *.bmp *.ini *.chu *.ids *.bcs *.vvc *.mos *.spl *.wav *.pro)
194 INSTALL( FILES ${FILES_TO_INSTALL} DESTINATION ${DATA_DIR}/override/${game_name} )
195 ENDMACRO(ADD_GEMRB_OVERRIDE )
197 ADD_SUBDIRECTORY( gemrb )
198 INSTALL( FILES gemrb.6 DESTINATION ${MAN_DIR} )
200 CONFIGURE_FILE(
201   "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
202   "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
203   IMMEDIATE @ONLY
206 ADD_CUSTOM_TARGET( uninstall
207   "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" )