cmake: Move installation of plugins to macro.
[gemrb.git] / CMakeLists.txt
blob83121c358388fc7a31f5445d7a17efb3edd6f707
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 PLUGIN_INSTALL_DIR )
15  SET( PLUGIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/plugins )
16 ENDIF( NOT PLUGIN_INSTALL_DIR )
18 IF( NOT OVERRIDE_INSTALL_DIR )
19  SET( OVERRIDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/override )
20 ENDIF( NOT OVERRIDE_INSTALL_DIR )
22 IF( NOT GUISCRIPTS_INSTALL_DIR )
23  SET( GUISCRIPTS_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/GUIScripts )
24 ENDIF( NOT GUISCRIPTS_INSTALL_DIR )
26 IF( NOT MANPAGE_INSTALL_DIR )
27  SET( MANPAGE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/man/man6 )
28 ENDIF( NOT MANPAGE_INSTALL_DIR )
30 IF(CMAKE_COMPILER_IS_GNUCXX)
31  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror")
32 ENDIF(CMAKE_COMPILER_IS_GNUCXX)
34 MESSAGE(STATUS "Looking for Python libraries")
35 INCLUDE(FindPythonLibs)
36 IF(PYTHON_LIBRARY)
37  MESSAGE(STATUS "Python Libraries Found")
38 ELSE(PYTHON_LIBRARY)
39  MESSAGE(FATAL_ERROR "Unable to find Python development libraries. Please get it from www.python.org")
40 ENDIF(PYTHON_LIBRARY)
42 MESSAGE(STATUS "Looking for openAL libraries")
43 INCLUDE(FindOpenAL)
44 IF(OPENAL_FOUND)
45  MESSAGE(STATUS "openal found")
46 ELSE(OPENAL_FOUND)
47  MESSAGE(ERROR "unable to find openal. please set OPENALDIR environment variable or get it from www.openal.org")
48 ENDIF(OPENAL_FOUND)
50 MESSAGE(STATUS "Looking for SDL")
51 INCLUDE(FindSDL)
52 IF(SDL_FOUND)
53  MESSAGE(STATUS "SDL found")
54 ELSE(SDL_FOUND)
55  MESSAGE(FATAL_ERROR "unable to find SDL. please get it from www.libsdl.org")
56 ENDIF(SDL_FOUND)
58 MESSAGE( STATUS "Looking for Zlib" )
59 #SET(ZLIB_FIND_REQUIRED TRUE)
60 INCLUDE(FindZLIB)
62 MESSAGE( STATUS "Looking for libPNG" )
63 INCLUDE(FindPNG)
64 IF(PNG_FOUND)
65  MESSAGE( STATUS "libPNG found" )
66 ELSE(PNG_FOUND)
67  MESSAGE( STATUS "WARNING : GemRB will be built without any PNG support. Get it from www.libpng.org" )
68 ENDIF(PNG_FOUND)
70 IF(UNIX)
71  MESSAGE(STATUS "Looking for dl library")
72  FIND_LIBRARY(DLD_LIBRARY_PATH dl dld)
73  IF(DLD_LIBRARY_PATH)
74   MESSAGE(STATUS "dl library found")
75  ELSE(DLD_LIBRARY_PATH)
76   MESSAGE(FATAL_ERROR "dl library not found")
77  ENDIF(DLD_LIBRARY_PATH)
78 ENDIF(UNIX)
80 MESSAGE(STATUS "Looking for Ogg Vorbis support")
81 FIND_LIBRARY(VORBIS_LIBRARY vorbisfile)
83 ADD_DEFINITIONS("-DHAVE_CONFIG_H" -DPLUGINDIR="${PLUGIN_INSTALL_DIR}")
85 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
87 #Platform checks
88 INCLUDE (CheckTypeSize)
89 CHECK_TYPE_SIZE("int" SIZEOF_INT)
90 CHECK_TYPE_SIZE("long int" SIZEOF_LONG_INT)
92 INCLUDE (CheckFunctionExists)
93 CHECK_FUNCTION_EXISTS("snprintf" HAVE_SNPRINTF)
94 CHECK_FUNCTION_EXISTS("strndup" HAVE_STRNDUP)
96 #Unneeded on windows
97 IF(NOT WIN32)
98 INCLUDE (CheckCXXSourceCompiles)
99 CHECK_CXX_SOURCE_COMPILES("typedef void *(* voidvoid)(void);
101 void *object = 0;
102 voidvoid function;
103 function = (voidvoid) object;
104 " PERMITS_OBJECT_TO_FUNCTION_CAST)
106 IF( NOT PERMITS_OBJECT_TO_FUNCTION_CAST )
107  SET(HAVE_FORBIDDEN_OBJECT_TO_FUNCTION_CAST 1)
108 ENDIF( NOT PERMITS_OBJECT_TO_FUNCTION_CAST )
109 ENDIF(NOT WIN32)
111 IF(VORBIS_LIBRARY)
112  SET(HAS_VORBIS_SUPPORT 1)
113 ELSE(VORBIS_LIBRARY)
114  SET(VORBIS_LIBRARY "")
115 ENDIF(VORBIS_LIBRARY)
117 IF(APPLE)
118  FIND_LIBRARY(SDL_MAIN_LIBRARY_PATH SDLmain)
119  FIND_LIBRARY(COCOA_LIBRARY_PATH Cocoa)
120 ENDIF(APPLE)
122 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
124 #Plugin addition macro
125 MACRO(ADD_GEMRB_PLUGIN plugin_name)
126 ADD_LIBRARY(${plugin_name} MODULE ${ARGN})
127 SET_TARGET_PROPERTIES(${plugin_name} PROPERTIES PREFIX "")
128 IF(WIN32)
129  TARGET_LINK_LIBRARIES(${plugin_name} gemrb_core)
130 ENDIF(WIN32)
131 IF(APPLE)
132  TARGET_LINK_LIBRARIES(${plugin_name} gemrb_core)
133 ENDIF(APPLE)
134 INSTALL(TARGETS ${plugin_name} DESTINATION ${PLUGIN_INSTALL_DIR})
135 ENDMACRO(ADD_GEMRB_PLUGIN)
137 #gemrb overrides macro
138 MACRO(ADD_GEMRB_OVERRIDE game_name)
139 FILE( GLOB FILES_TO_INSTALL *.2da *.bmp *.ini *.chu *.ids *.bcs *.vvc *.mos *.spl *.wav *.pro)
140 INSTALL( FILES ${FILES_TO_INSTALL} DESTINATION ${OVERRIDE_INSTALL_DIR}/${game_name} )
141 ENDMACRO(ADD_GEMRB_OVERRIDE )
143 ADD_SUBDIRECTORY( gemrb )
144 INSTALL( FILES gemrb.6 DESTINATION ${MANPAGE_INSTALL_DIR} )
146 CONFIGURE_FILE(
147   "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
148   "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
149   IMMEDIATE @ONLY
152 ADD_CUSTOM_TARGET( uninstall
153   "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" )