CMakeLists.txt 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. cmake_minimum_required(VERSION 2.8)
  2. project(openhmd C CXX)
  3. set(CMAKE_C_FLAGS "-std=c99")
  4. set(CMAKE_POSITION_INDEPENDENT_CODE ON)
  5. set(LIB_VERSION_MAJOR 0)
  6. set(LIB_VERSION_MINOR 1)
  7. set(LIB_VERSION_PATCH 0)
  8. set(LIB_VERSION_STRING ${LIB_VERSION_MAJOR}.${LIB_VERSION_MINOR}.${LIB_VERSION_PATCH})
  9. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
  10. include_directories(${CMAKE_CURRENT_LIST_DIR}/include)
  11. if (MSVC)
  12. # Add the "lib" prefix for generated .lib outputs.
  13. set(LIB_PREFIX lib)
  14. else (MSVC)
  15. # When building with "make", "lib" prefix will be added automatically by
  16. # the build tool.
  17. set(LIB_PREFIX)
  18. endif (MSVC)
  19. #source files set just for Android
  20. set(openhmd_source_files
  21. ${CMAKE_CURRENT_LIST_DIR}/src/openhmd.c
  22. ${CMAKE_CURRENT_LIST_DIR}/src/platform-win32.c
  23. ${CMAKE_CURRENT_LIST_DIR}/src/drv_dummy/dummy.c
  24. ${CMAKE_CURRENT_LIST_DIR}/src/omath.c
  25. ${CMAKE_CURRENT_LIST_DIR}/src/platform-posix.c
  26. ${CMAKE_CURRENT_LIST_DIR}/src/fusion.c
  27. ${CMAKE_CURRENT_LIST_DIR}/src/shaders.c
  28. )
  29. OPTION(OPENHMD_DRIVER_OCULUS_RIFT "Oculus Rift DK1 and DK2" ON)
  30. OPTION(OPENHMD_DRIVER_DEEPOON "Deepoon E2" ON)
  31. OPTION(OPENHMD_DRIVER_WMR "Windows Mixed Reality" ON)
  32. OPTION(OPENHMD_DRIVER_PSVR "Sony PSVR" ON)
  33. OPTION(OPENHMD_DRIVER_HTC_VIVE "HTC Vive" ON)
  34. OPTION(OPENHMD_DRIVER_NOLO "NOLO VR CV1" ON)
  35. OPTION(OPENHMD_DRIVER_EXTERNAL "External sensor driver" ON)
  36. OPTION(OPENHMD_DRIVER_ANDROID "General Android driver" OFF)
  37. OPTION(OPENHMD_EXAMPLE_SIMPLE "Simple test binary" ON)
  38. OPTION(OPENHMD_EXAMPLE_SDL "SDL OpenGL test (outdated)" OFF)
  39. if(OPENHMD_DRIVER_OCULUS_RIFT)
  40. set(openhmd_source_files ${openhmd_source_files}
  41. ${CMAKE_CURRENT_LIST_DIR}/src/drv_oculus_rift/rift.c
  42. ${CMAKE_CURRENT_LIST_DIR}/src/drv_oculus_rift/packet.c
  43. )
  44. add_definitions(-DDRIVER_OCULUS_RIFT)
  45. find_package(HIDAPI REQUIRED)
  46. include_directories(${HIDAPI_INCLUDE_DIRS})
  47. set(LIBS ${LIBS} ${HIDAPI_LIBRARIES})
  48. endif(OPENHMD_DRIVER_OCULUS_RIFT)
  49. if(OPENHMD_DRIVER_DEEPOON)
  50. set(openhmd_source_files ${openhmd_source_files}
  51. ${CMAKE_CURRENT_LIST_DIR}/src/drv_deepoon/deepoon.c
  52. ${CMAKE_CURRENT_LIST_DIR}/src/drv_deepoon/packet.c
  53. )
  54. add_definitions(-DDRIVER_DEEPOON)
  55. find_package(HIDAPI REQUIRED)
  56. include_directories(${HIDAPI_INCLUDE_DIRS})
  57. set(LIBS ${LIBS} ${HIDAPI_LIBRARIES})
  58. endif(OPENHMD_DRIVER_DEEPOON)
  59. if(OPENHMD_DRIVER_WMR)
  60. set(openhmd_source_files ${openhmd_source_files}
  61. ${CMAKE_CURRENT_LIST_DIR}/src/drv_wmr/wmr.c
  62. ${CMAKE_CURRENT_LIST_DIR}/src/drv_wmr/packet.c
  63. )
  64. add_definitions(-DDRIVER_WMR)
  65. find_package(HIDAPI REQUIRED)
  66. include_directories(${HIDAPI_INCLUDE_DIRS})
  67. set(LIBS ${LIBS} ${HIDAPI_LIBRARIES})
  68. endif(OPENHMD_DRIVER_WMR)
  69. if(OPENHMD_DRIVER_PSVR)
  70. set(openhmd_source_files ${openhmd_source_files}
  71. ${CMAKE_CURRENT_LIST_DIR}/src/drv_psvr/psvr.c
  72. ${CMAKE_CURRENT_LIST_DIR}/src/drv_psvr/packet.c
  73. )
  74. add_definitions(-DDRIVER_PSVR)
  75. find_package(HIDAPI REQUIRED)
  76. include_directories(${HIDAPI_INCLUDE_DIRS})
  77. set(LIBS ${LIBS} ${HIDAPI_LIBRARIES})
  78. endif(OPENHMD_DRIVER_PSVR)
  79. if(OPENHMD_DRIVER_HTC_VIVE)
  80. set(openhmd_source_files ${openhmd_source_files}
  81. ${CMAKE_CURRENT_LIST_DIR}/src/drv_htc_vive/vive.c
  82. ${CMAKE_CURRENT_LIST_DIR}/src/drv_htc_vive/packet.c
  83. #${CMAKE_CURRENT_LIST_DIR}/src/ext_deps/miniz.c
  84. ${CMAKE_CURRENT_LIST_DIR}/src/ext_deps/mjson.c
  85. )
  86. add_definitions(-DDRIVER_HTC_VIVE)
  87. find_package(HIDAPI REQUIRED)
  88. include_directories(${HIDAPI_INCLUDE_DIRS})
  89. set(LIBS ${LIBS} ${HIDAPI_LIBRARIES})
  90. endif(OPENHMD_DRIVER_HTC_VIVE)
  91. if(OPENHMD_DRIVER_NOLO)
  92. set(openhmd_source_files ${openhmd_source_files}
  93. ${CMAKE_CURRENT_LIST_DIR}/src/drv_nolo/nolo.c
  94. ${CMAKE_CURRENT_LIST_DIR}/src/drv_nolo/packet.c
  95. )
  96. add_definitions(-DDRIVER_NOLO)
  97. find_package(HIDAPI REQUIRED)
  98. include_directories(${HIDAPI_INCLUDE_DIRS})
  99. set(LIBS ${LIBS} ${HIDAPI_LIBRARIES})
  100. endif(OPENHMD_DRIVER_NOLO)
  101. if (OPENHMD_DRIVER_EXTERNAL)
  102. set(openhmd_source_files ${openhmd_source_files}
  103. ${CMAKE_CURRENT_LIST_DIR}/src/drv_external/external.c
  104. )
  105. add_definitions(-DDRIVER_EXTERNAL)
  106. endif(OPENHMD_DRIVER_EXTERNAL)
  107. if (OPENHMD_DRIVER_ANDROID)
  108. set(openhmd_source_files ${openhmd_source_files}
  109. ${CMAKE_CURRENT_LIST_DIR}/src/drv_android/android.c
  110. )
  111. add_definitions(-DDRIVER_ANDROID)
  112. endif(OPENHMD_DRIVER_ANDROID)
  113. if (OPENHMD_EXAMPLE_SIMPLE)
  114. add_subdirectory(./examples/simple)
  115. endif(OPENHMD_EXAMPLE_SIMPLE)
  116. if (OPENHMD_EXAMPLE_SDL)
  117. find_package(SDL2 REQUIRED)
  118. find_package(GLEW REQUIRED)
  119. find_package(OpenGL REQUIRED)
  120. add_subdirectory(./examples/opengl)
  121. endif (OPENHMD_EXAMPLE_SDL)
  122. if (UNIX)
  123. set(LIBS ${LIBS} rt pthread)
  124. endif (UNIX)
  125. link_libraries(${LIBS})
  126. add_library(openhmd-shared SHARED ${openhmd_source_files})
  127. SET_TARGET_PROPERTIES(openhmd-shared PROPERTIES OUTPUT_NAME openhmd CLEAN_DIRECT_OUTPUT 1 VERSION ${LIB_VERSION_STRING} SOVERSION ${LIB_VERSION_MAJOR})
  128. add_library(openhmd-static STATIC ${openhmd_source_files})
  129. SET_TARGET_PROPERTIES(openhmd-static PROPERTIES OUTPUT_NAME openhmd CLEAN_DIRECT_OUTPUT 1)
  130. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_DIR}/)
  131. #install properties
  132. install (TARGETS openhmd-shared openhmd-static DESTINATION lib)
  133. install (FILES include/openhmd.h DESTINATION include)