Guest

Untitled

By: a guest on Dec 14th, 2010  |  syntax: None  |  size: 4.87 KB  |  hits: 143  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. # cmake system for OIS created on the 5th of April by thomas{at}thomasfischer{DOT}biz
  2.  
  3. # setup some cmake requirements - must be done first
  4. cmake_minimum_required(VERSION 2.4)
  5.  
  6. if(COMMAND cmake_policy)
  7.   cmake_policy(SET CMP0003 NEW)
  8. endif(COMMAND cmake_policy)
  9.  
  10. # loose if - else constructs
  11. SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE)
  12.  
  13. # add some functions we use that are shipped with cmake
  14. INCLUDE(CheckLibraryExists)
  15. INCLUDE(CheckIncludeFile)
  16. INCLUDE(CheckCCompilerFlag)
  17. INCLUDE(CheckCSourceCompiles)
  18.  
  19. # define the project
  20. project(OIS)
  21.  
  22. # general flags for all platforms
  23. add_definitions("-D_LIB")
  24. # add include directory for ois lib
  25. include_directories (includes)
  26.  
  27. # platform specific things
  28. IF(WIN32)
  29.         # add some flag that removes a lot of false warnings
  30.         add_definitions("-D_CRT_SECURE_NO_WARNINGS")
  31.         FILE(GLOB sources src/*.cpp src/win32/*.cpp src/*.h src/win32/*.h)
  32.         set(OS_LIBS dxguid.lib dinput8.lib)
  33.         set(ffconsole_src demos/FFConsoleDemo.cpp demos/FFConsoleDemoResource.rc)
  34.         set(console_src demos/OISConsole.cpp demos/OISConsoleResource.rc)
  35.         # check for libs and include files we want to use
  36.         CHECK_LIBRARY_EXISTS(dinput8 DirectInput8Create "" HAVE_DXINPUT_LIBS)
  37.         if(NOT HAVE_DXINPUT_LIBS)
  38.                 message(FATAL_ERROR "could not link against DirectX input, please check of you have the required libraries installed")
  39.         endif()
  40.         CHECK_INCLUDE_FILE(dinput.h HAVE_DXINPUT_INCLUDES)
  41.         if(NOT HAVE_DXINPUT_INCLUDES)
  42.                 message(FATAL_ERROR "could not find the DirectX includes. Please install them.")
  43.         endif()
  44.         CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_INCLUDES)
  45.         if(NOT HAVE_WINDOWS_INCLUDES)
  46.                 message(FATAL_ERROR "could not find the windows platform includes. Please install them.")
  47.         endif()
  48. ELSEIF(UNIX)
  49.         FILE(GLOB sources src/*.cpp src/linux/*.cpp src/*.h src/linux/*.h)
  50.         set(OS_LIBS X11)
  51.         set(ffconsole_src demos/FFConsoleDemo.cpp)
  52.         set(console_src demos/OISConsole.cpp)
  53.         # check for libs and include files we want to use
  54.         CHECK_LIBRARY_EXISTS(X11 XOpenDisplay "" HAVE_X11_LIBS)
  55.         if(NOT HAVE_X11_LIBS)
  56.                 message(FATAL_ERROR "could not link against X11, please check of you have the required libraries installed")
  57.         endif()
  58.         CHECK_INCLUDE_FILE(X11/keysym.h HAVE_X11_INCLUDES)
  59.         if(NOT HAVE_X11_INCLUDES)
  60.                 message(FATAL_ERROR "could not find the X11 includes. Please install them.")
  61.         endif()
  62.  
  63. ELSEIF(APPLE)
  64.         FILE(GLOB sources src/*.cpp src/mac/*.cpp src/*.h src/mac/*.h)
  65.         set(OS_LIBS X11)
  66.         set(ffconsole_src demos/FFConsoleDemo.cpp)
  67.         set(console_src demos/OISConsole.cpp)
  68. ENDIF(WIN32)
  69.  
  70.  
  71. # some versioning things
  72. SET(LIB_MAJOR_VERSION "1")
  73. SET(LIB_MINOR_VERSION "4")
  74. SET(LIB_BUILD_VERSION "0")
  75. SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_BUILD_VERSION}")
  76. IF(NOT DEFINED LIB_INSTALL_DIR)
  77.   SET(LIB_INSTALL_DIR "lib${LIB_SUFFIX}")
  78. ENDIF(NOT DEFINED LIB_INSTALL_DIR)
  79.  
  80.  
  81. # Needed for OIS.pc.in
  82. SET(prefix ${CMAKE_INSTALL_PREFIX})
  83. SET(exec_prefix "\${prefix}")
  84. SET(libdir "\${exec_prefix}/${LIB_INSTALL_DIR}")
  85. SET(bindir "\${exec_prefix}/bin")
  86. SET(includedir "\${prefix}/include")
  87. SET(PACKAGE_NAME "OIS")
  88. SET(PACKAGE_VERSION "${LIB_VERSION}")
  89.  
  90. # configuration of the config.h and PkgConfig
  91. #CONFIGURE_FILE(
  92. #    "${OIS_SOURCE_DIR}/includes/config.h.in"
  93. #    "${OIS_BINARY_DIR}/includes/config.h")
  94. CONFIGURE_FILE(
  95.     "${OIS_SOURCE_DIR}/OIS.pc.in"
  96.     "${OIS_BINARY_DIR}/OIS.pc"
  97.     @ONLY)
  98.  
  99. # some additional compiler flags
  100. ADD_DEFINITIONS(-Wall)
  101. CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
  102. IF(HAVE_W_EXTRA)
  103.         ADD_DEFINITIONS(-Wextra)
  104. ENDIF()
  105.  
  106. # Set visibility options if available
  107. IF(NOT WIN32)
  108.         CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
  109.                                                                 int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
  110.  
  111.         CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_SWITCH)
  112.         IF(HAVE_VISIBILITY_SWITCH)
  113.                 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
  114.                                                                         int main() {return 0;}" HAVE_GCC_VISIBILITY)
  115.                 IF(HAVE_GCC_VISIBILITY)
  116.                         ADD_DEFINITIONS(-fvisibility=hidden -DHAVE_GCC_VISIBILITY)
  117.                 ENDIF()
  118.         ENDIF()
  119. ENDIF()
  120.  
  121. # build the library
  122. set(LIBNAME "ois")
  123. add_library(${LIBNAME} STATIC ${sources} ${sources_win})
  124. target_link_libraries(${LIBNAME} ${OS_LIBS})
  125. SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES VERSION ${LIB_VERSION} SOVERSION ${LIB_MAJOR_VERSION})
  126.  
  127. # build ffconsole demo
  128. add_executable(ffconsole ${ffconsole_src})
  129. target_link_libraries(ffconsole ${LIBNAME})
  130.  
  131. # build console demo
  132. add_executable(console ${console_src})
  133. target_link_libraries(console ${LIBNAME})
  134.  
  135. # install the library
  136. INSTALL(TARGETS ${LIBNAME}
  137.         RUNTIME DESTINATION bin
  138.         LIBRARY DESTINATION ${LIB_INSTALL_DIR}
  139.         ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
  140. )
  141. # install the headers
  142. INSTALL(DIRECTORY includes/ DESTINATION include/OIS FILES_MATCHING PATTERN "*.h" PATTERN ".svn" EXCLUDE)
  143.  
  144. # install the PkgConfig file
  145. INSTALL(FILES "${OIS_BINARY_DIR}/OIS.pc" DESTINATION "${LIB_INSTALL_DIR}/pkgconfig")