Permalink
Browse files

Merge pull request #166 from magestik/cmake

List of fixes for modernizing CMake build and fixing MSVC compilation on Windows
  • Loading branch information...
TheOnlyJoey committed Sep 8, 2018
2 parents 6dd9b7e + 8aa3b4a commit 1916d177009300566326d1951aa1dc838ad39fcc
Showing with 68 additions and 31 deletions.
  1. +61 −27 CMakeLists.txt
  2. +2 −2 examples/opengl/CMakeLists.txt
  3. +5 −2 examples/simple/CMakeLists.txt
View
@@ -1,7 +1,8 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.1)
project(openhmd C CXX)
set(CMAKE_C_FLAGS "-std=c99")
project(openhmd C)
set(CMAKE_C_STANDARD 99)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(LIB_VERSION_MAJOR 0)
@@ -10,7 +11,8 @@ set(LIB_VERSION_PATCH 0)
set(LIB_VERSION_STRING ${LIB_VERSION_MAJOR}.${LIB_VERSION_MINOR}.${LIB_VERSION_PATCH})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
include_directories(${CMAKE_CURRENT_LIST_DIR}/include)
option(BUILD_BOTH_STATIC_SHARED_LIB OFF)
if (MSVC)
# Add the "lib" prefix for generated .lib outputs.
@@ -32,18 +34,18 @@ set(openhmd_source_files
${CMAKE_CURRENT_LIST_DIR}/src/shaders.c
)
OPTION(OPENHMD_DRIVER_OCULUS_RIFT "Oculus Rift DK1 and DK2" ON)
OPTION(OPENHMD_DRIVER_DEEPOON "Deepoon E2" ON)
OPTION(OPENHMD_DRIVER_WMR "Windows Mixed Reality" ON)
OPTION(OPENHMD_DRIVER_PSVR "Sony PSVR" ON)
OPTION(OPENHMD_DRIVER_HTC_VIVE "HTC Vive" ON)
OPTION(OPENHMD_DRIVER_NOLO "NOLO VR CV1" ON)
OPTION(OPENHMD_DRIVER_XGVR "3Glasses HMD" ON)
OPTION(OPENHMD_DRIVER_EXTERNAL "External sensor driver" ON)
OPTION(OPENHMD_DRIVER_ANDROID "General Android driver" OFF)
option(OPENHMD_DRIVER_OCULUS_RIFT "Oculus Rift DK1 and DK2" ON)
option(OPENHMD_DRIVER_DEEPOON "Deepoon E2" ON)
option(OPENHMD_DRIVER_WMR "Windows Mixed Reality" ON)
option(OPENHMD_DRIVER_PSVR "Sony PSVR" ON)
option(OPENHMD_DRIVER_HTC_VIVE "HTC Vive" ON)
option(OPENHMD_DRIVER_NOLO "NOLO VR CV1" ON)
option(OPENHMD_DRIVER_XGVR "3Glasses HMD" ON)
option(OPENHMD_DRIVER_EXTERNAL "External sensor driver" ON)
option(OPENHMD_DRIVER_ANDROID "General Android driver" OFF)
OPTION(OPENHMD_EXAMPLE_SIMPLE "Simple test binary" ON)
OPTION(OPENHMD_EXAMPLE_SDL "SDL OpenGL test (outdated)" OFF)
option(OPENHMD_EXAMPLE_SIMPLE "Simple test binary" ON)
option(OPENHMD_EXAMPLE_SDL "SDL OpenGL test (outdated)" OFF)
if(OPENHMD_DRIVER_OCULUS_RIFT)
set(openhmd_source_files ${openhmd_source_files}
@@ -156,17 +158,49 @@ if (OPENHMD_EXAMPLE_SDL)
add_subdirectory(./examples/opengl)
endif (OPENHMD_EXAMPLE_SDL)
if (UNIX)
set(LIBS ${LIBS} rt pthread)
endif (UNIX)
set(TARGETS "")
if (BUILD_BOTH_STATIC_SHARED_LIBS)
# Shared
add_library(openhmd-shared SHARED ${openhmd_source_files})
set_target_properties(openhmd-shared PROPERTIES OUTPUT_NAME openhmd CLEAN_DIRECT_OUTPUT 1)
# Static
add_library(openhmd-static STATIC ${openhmd_source_files})
set_target_properties(openhmd-static PROPERTIES OUTPUT_NAME openhmd CLEAN_DIRECT_OUTPUT 1)
# Alias needed to compile examples
add_library(openhmd ALIAS openhmd-shared)
set(TARGETS "openhmd-shared" "openhmd-static")
else ()
# Static or Shared
add_library(openhmd ${openhmd_source_files})
export(TARGETS openhmd FILE openhmd-config.cmake)
set(TARGETS "openhmd")
endif ()
foreach(target ${TARGETS})
set_target_properties(${target} PROPERTIES VERSION ${LIB_VERSION_STRING} SOVERSION ${LIB_VERSION_MAJOR})
target_include_directories(${target} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(${target} ${LIBS})
if (UNIX)
target_link_libraries(${target} rt pthread)
endif (UNIX)
get_target_property(target_type ${target} TYPE)
if (target_type STREQUAL "STATIC_LIBRARY")
target_compile_definitions(${target} PUBLIC -DOHMD_STATIC)
endif()
link_libraries(${LIBS})
add_library(openhmd-shared SHARED ${openhmd_source_files})
SET_TARGET_PROPERTIES(openhmd-shared PROPERTIES OUTPUT_NAME openhmd CLEAN_DIRECT_OUTPUT 1 VERSION ${LIB_VERSION_STRING} SOVERSION ${LIB_VERSION_MAJOR})
add_library(openhmd-static STATIC ${openhmd_source_files})
SET_TARGET_PROPERTIES(openhmd-static PROPERTIES OUTPUT_NAME openhmd CLEAN_DIRECT_OUTPUT 1)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_DIR}/)
endforeach(target)
#install properties
install (TARGETS openhmd-shared openhmd-static DESTINATION lib)
install (FILES include/openhmd.h DESTINATION include)
install(TARGETS ${TARGETS} DESTINATION lib)
install(FILES include/openhmd.h DESTINATION include)
@@ -1,5 +1,5 @@
project (openglexample)
project (openglexample C)
include_directories(${CMAKE_BINARY_DIR}/include ${SDL2_INCLUDE_DIR} ${GLEW_INCLUDE_DIRS} ${OPENGL_INCLUDE_DIR})
link_directories(${CMAKE_BINARY_DIR})
add_executable(openglexample gl.c main.c)
target_link_libraries(openglexample PRIVATE openhmd-shared m ${SDL2_LIBRARY} ${GLEW_LIBRARIES} ${OPENGL_LIBRARIES})
target_link_libraries(openglexample PRIVATE openhmd m ${SDL2_LIBRARY} ${GLEW_LIBRARIES} ${OPENGL_LIBRARIES})
@@ -1,5 +1,8 @@
project (simple)
project (simple C)
include_directories(${CMAKE_BINARY_DIR}/include)
link_directories(${CMAKE_BINARY_DIR})
add_executable(simple simple.c)
target_link_libraries(simple PRIVATE openhmd-shared m)
target_link_libraries(simple PRIVATE openhmd)
if (UNIX)
target_link_libraries(simple PRIVATE m)
endif()

0 comments on commit 1916d17

Please sign in to comment.