- # cmake system for OIS created on the 5th of April by thomas{at}thomasfischer{DOT}biz
- # setup some cmake requirements - must be done first
- cmake_minimum_required(VERSION 2.4)
- if(COMMAND cmake_policy)
- cmake_policy(SET CMP0003 NEW)
- endif(COMMAND cmake_policy)
- # loose if - else constructs
- SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE)
- # add some functions we use that are shipped with cmake
- INCLUDE(CheckLibraryExists)
- INCLUDE(CheckIncludeFile)
- INCLUDE(CheckCCompilerFlag)
- INCLUDE(CheckCSourceCompiles)
- # define the project
- project(OIS)
- # general flags for all platforms
- add_definitions("-D_LIB")
- # add include directory for ois lib
- include_directories (includes)
- # platform specific things
- IF(WIN32)
- # add some flag that removes a lot of false warnings
- add_definitions("-D_CRT_SECURE_NO_WARNINGS")
- FILE(GLOB sources src/*.cpp src/win32/*.cpp src/*.h src/win32/*.h)
- set(OS_LIBS dxguid.lib dinput8.lib)
- set(ffconsole_src demos/FFConsoleDemo.cpp demos/FFConsoleDemoResource.rc)
- set(console_src demos/OISConsole.cpp demos/OISConsoleResource.rc)
- # check for libs and include files we want to use
- CHECK_LIBRARY_EXISTS(dinput8 DirectInput8Create "" HAVE_DXINPUT_LIBS)
- if(NOT HAVE_DXINPUT_LIBS)
- message(FATAL_ERROR "could not link against DirectX input, please check of you have the required libraries installed")
- endif()
- CHECK_INCLUDE_FILE(dinput.h HAVE_DXINPUT_INCLUDES)
- if(NOT HAVE_DXINPUT_INCLUDES)
- message(FATAL_ERROR "could not find the DirectX includes. Please install them.")
- endif()
- CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_INCLUDES)
- if(NOT HAVE_WINDOWS_INCLUDES)
- message(FATAL_ERROR "could not find the windows platform includes. Please install them.")
- endif()
- ELSEIF(UNIX)
- FILE(GLOB sources src/*.cpp src/linux/*.cpp src/*.h src/linux/*.h)
- set(OS_LIBS X11)
- set(ffconsole_src demos/FFConsoleDemo.cpp)
- set(console_src demos/OISConsole.cpp)
- # check for libs and include files we want to use
- CHECK_LIBRARY_EXISTS(X11 XOpenDisplay "" HAVE_X11_LIBS)
- if(NOT HAVE_X11_LIBS)
- message(FATAL_ERROR "could not link against X11, please check of you have the required libraries installed")
- endif()
- CHECK_INCLUDE_FILE(X11/keysym.h HAVE_X11_INCLUDES)
- if(NOT HAVE_X11_INCLUDES)
- message(FATAL_ERROR "could not find the X11 includes. Please install them.")
- endif()
- ELSEIF(APPLE)
- FILE(GLOB sources src/*.cpp src/mac/*.cpp src/*.h src/mac/*.h)
- set(OS_LIBS X11)
- set(ffconsole_src demos/FFConsoleDemo.cpp)
- set(console_src demos/OISConsole.cpp)
- ENDIF(WIN32)
- # some versioning things
- SET(LIB_MAJOR_VERSION "1")
- SET(LIB_MINOR_VERSION "4")
- SET(LIB_BUILD_VERSION "0")
- SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_BUILD_VERSION}")
- IF(NOT DEFINED LIB_INSTALL_DIR)
- SET(LIB_INSTALL_DIR "lib${LIB_SUFFIX}")
- ENDIF(NOT DEFINED LIB_INSTALL_DIR)
- # Needed for OIS.pc.in
- SET(prefix ${CMAKE_INSTALL_PREFIX})
- SET(exec_prefix "\${prefix}")
- SET(libdir "\${exec_prefix}/${LIB_INSTALL_DIR}")
- SET(bindir "\${exec_prefix}/bin")
- SET(includedir "\${prefix}/include")
- SET(PACKAGE_NAME "OIS")
- SET(PACKAGE_VERSION "${LIB_VERSION}")
- # configuration of the config.h and PkgConfig
- #CONFIGURE_FILE(
- # "${OIS_SOURCE_DIR}/includes/config.h.in"
- # "${OIS_BINARY_DIR}/includes/config.h")
- CONFIGURE_FILE(
- "${OIS_SOURCE_DIR}/OIS.pc.in"
- "${OIS_BINARY_DIR}/OIS.pc"
- @ONLY)
- # some additional compiler flags
- ADD_DEFINITIONS(-Wall)
- CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
- IF(HAVE_W_EXTRA)
- ADD_DEFINITIONS(-Wextra)
- ENDIF()
- # Set visibility options if available
- IF(NOT WIN32)
- CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
- int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
- CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_SWITCH)
- IF(HAVE_VISIBILITY_SWITCH)
- CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
- int main() {return 0;}" HAVE_GCC_VISIBILITY)
- IF(HAVE_GCC_VISIBILITY)
- ADD_DEFINITIONS(-fvisibility=hidden -DHAVE_GCC_VISIBILITY)
- ENDIF()
- ENDIF()
- ENDIF()
- # build the library
- set(LIBNAME "ois")
- add_library(${LIBNAME} STATIC ${sources} ${sources_win})
- target_link_libraries(${LIBNAME} ${OS_LIBS})
- SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES VERSION ${LIB_VERSION} SOVERSION ${LIB_MAJOR_VERSION})
- # build ffconsole demo
- add_executable(ffconsole ${ffconsole_src})
- target_link_libraries(ffconsole ${LIBNAME})
- # build console demo
- add_executable(console ${console_src})
- target_link_libraries(console ${LIBNAME})
- # install the library
- INSTALL(TARGETS ${LIBNAME}
- RUNTIME DESTINATION bin
- LIBRARY DESTINATION ${LIB_INSTALL_DIR}
- ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
- )
- # install the headers
- INSTALL(DIRECTORY includes/ DESTINATION include/OIS FILES_MATCHING PATTERN "*.h" PATTERN ".svn" EXCLUDE)
- # install the PkgConfig file
- INSTALL(FILES "${OIS_BINARY_DIR}/OIS.pc" DESTINATION "${LIB_INSTALL_DIR}/pkgconfig")