Browse Source

CMake: Detect VRPN and build support for it when present

I inadvertently rewrote FindVRPN.cmake doing this - I didn't
think to check if it already existed before overwriting.
Oh well, the new version is a bit simpler.
Sam Edwards 7 years ago
parent
commit
f701e36aa5
3 changed files with 59 additions and 33 deletions
  1. 15 33
      cmake/modules/FindVRPN.cmake
  2. 5 0
      panda/CMakeLists.txt
  3. 39 0
      panda/src/vrpn/CMakeLists.txt

+ 15 - 33
cmake/modules/FindVRPN.cmake

@@ -1,45 +1,27 @@
 # Filename: FindVRPN.cmake
-# Author: kestred (29 Nov, 2013)
+# Authors: CFSworks (2 Nov, 2018)
 #
 # Usage:
 #   find_package(VRPN [REQUIRED] [QUIET])
 #
-# It sets the following variables:
-#   VRPN_FOUND   - system has libvrpn
-#   VRPN_INCLUDE_DIR   - the vrpn include directory
-#   VRPN_LIBRARY_DIR   - the vrpn library directory
-#   VRPN_LIBRARY - the path to the library binary
+# Once done this will define:
+#   VRPN_FOUND       - system has VRPN
+#   VRPN_INCLUDE_DIR - the include directory containing VRPN header files
+#   VRPN_LIBRARY     - the path to the VRPN client library
 #
 
-if(VRPN_INCLUDE_DIR AND VRPN_LIBRARY_DIR)
-	set(FOUND_VRPN TRUE)
-else()
-	# Find the vrpn include files
-	find_path(VRPN_INCLUDE_DIR
-		NAMES "vrpn_Keyboard.h"
-		PATHS "/usr/include"
-		      "/usr/local/include"
-		      "/opt/vrpn/include"
-		PATH_SUFFIXES "" "vrpn"
-		DOC "The path to vrpn's include directory."
-	)
+if(NOT VRPN_INCLUDE_DIR)
+  find_path(VRPN_INCLUDE_DIR "vrpn_Connection.h")
 
-	# Find the libvrpn library (.a, .so)
-	find_library(VRPN_LIBRARY
-		NAMES "vrpn"
-		      "libvrpn"
-		PATHS "/usr"
-		      "/usr/local"
-		      "/opt/vrpn"
-		PATH_SUFFIXES "lib" "lib32" "lib64"
-	)
-	get_filename_component(VRPN_LIBRARY_DIR "${VRPN_LIBRARY}" PATH)
-	set(VRPN_LIBRARY_DIR "${VRPN_LIBRARY_DIR}" CACHE PATH "The path to vrpn's library directory.") # Library path
+  mark_as_advanced(VRPN_INCLUDE_DIR)
+endif()
+
+if(NOT VRPN_LIBRARY)
+  find_library(VRPN_LIBRARY
+    NAMES "vrpn")
 
-	mark_as_advanced(VRPN_INCLUDE_DIR)
-	mark_as_advanced(VRPN_LIBRARY_DIR)
-	mark_as_advanced(VRPN_LIBRARY)
+  mark_as_advanced(VRPN_LIBRARY)
 endif()
 
 include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(VRPN DEFAULT_MSG VRPN_LIBRARY VRPN_INCLUDE_DIR VRPN_LIBRARY_DIR)
+find_package_handle_standard_args(VRPN DEFAULT_MSG VRPN_INCLUDE_DIR VRPN_LIBRARY)

+ 5 - 0
panda/CMakeLists.txt

@@ -54,6 +54,7 @@ add_subdirectory(src/recorder)
 add_subdirectory(src/testbed)
 add_subdirectory(src/text)
 add_subdirectory(src/tform)
+add_subdirectory(src/vrpn)
 add_subdirectory(src/wgldisplay)
 add_subdirectory(src/windisplay)
 add_subdirectory(src/x11display)
@@ -108,4 +109,8 @@ if(HAVE_PYTHON)
   if(HAVE_ODE)
     add_python_module(ode p3ode IMPORT panda3d.core)
   endif()
+
+  if(HAVE_VRPN)
+    add_python_module(vrpn p3vrpn IMPORT panda3d.core)
+  endif()
 endif()

+ 39 - 0
panda/src/vrpn/CMakeLists.txt

@@ -0,0 +1,39 @@
+if(NOT HAVE_VRPN)
+  return()
+endif()
+
+set(P3VRPN_HEADERS
+  config_vrpn.h
+  vrpnAnalogDevice.h vrpnAnalogDevice.I
+  vrpnAnalog.h vrpnAnalog.I
+  vrpnButtonDevice.h vrpnButtonDevice.I
+  vrpnButton.h vrpnButton.I
+  vrpnClient.h vrpnClient.I
+  vrpnDialDevice.h vrpnDialDevice.I
+  vrpnDial.h vrpnDial.I
+  vrpn_interface.h
+  vrpnTrackerDevice.h vrpnTrackerDevice.I
+  vrpnTracker.h vrpnTracker.I
+)
+
+set(P3VRPN_SOURCES
+  config_vrpn.cxx
+  vrpnAnalog.cxx
+  vrpnAnalogDevice.cxx
+  vrpnButton.cxx
+  vrpnButtonDevice.cxx
+  vrpnClient.cxx
+  vrpnDial.cxx
+  vrpnDialDevice.cxx
+  vrpnTracker.cxx
+  vrpnTrackerDevice.cxx
+)
+
+composite_sources(p3vrpn P3VRPN_SOURCES)
+add_library(p3vrpn ${P3VRPN_HEADERS} ${P3VRPN_SOURCES})
+set_target_properties(p3vrpn PROPERTIES DEFINE_SYMBOL BUILDING_VRPN)
+target_link_libraries(p3vrpn panda PKG::VRPN)
+target_interrogate(p3vrpn ALL)
+
+install(TARGETS p3vrpn DESTINATION lib RUNTIME DESTINATION bin)
+install(FILES ${P3VRPN_HEADERS} DESTINATION include/panda3d)