FindOMPL.cmake
1 # - Try to find the OMPL library
2 # Once done this will define:
3 #
4 # OMPL_FOUND - OMPL was found
5 # OMPL_INCLUDE_DIRS - The OMPL include directory
6 # OMPL_LIBRARIES - The OMPL library
7 # OMPLAPP_LIBRARIES - The OMPL.app libraries
8 # OMPL_VERSION - The OMPL version in the form <major>.<minor>.<patchlevel>
9 # OMPL_MAJOR_VERSION - Major version
10 # OMPL_MINOR_VERSION - Minor version
11 # OMPL_PATCH_VERSION - Patch version
12 
13 include(FindPackageHandleStandardArgs)
14 
15 # user can set OMPL_PREFIX to specify the prefix path of the OMPL library
16 # and include directory, either as an environment variable or as an
17 # argument to cmake ("cmake -DOMPL_PREFIX=...")
18 if (NOT OMPL_PREFIX)
19  set(OMPL_PREFIX $ENV{OMPL_PREFIX})
20 endif()
21 
22 if (OMPL_FIND_VERSION)
23  set(OMPL_SUFFIX "-${OMPL_VERSION}")
24 else()
25  set(OMPL_SUFFIX "")
26 endif()
27 
28 # user can set OMPL_LIB_PATH to specify the path for the OMPL library
29 # (analogous to OMPL_PREFIX)
30 if (NOT OMPL_LIB_PATH)
31  set(OMPL_LIB_PATH $ENV{OMPL_LIB_PATH})
32  if (NOT OMPL_LIB_PATH)
33  set(OMPL_LIB_PATH ${OMPL_PREFIX})
34  endif()
35 endif()
36 
37 # user can set OMPL_INCLUDE_PATH to specify the path for the OMPL include
38 # directory (analogous to OMPL_PREFIX)
39 if (NOT OMPL_INCLUDE_PATH)
40  set(OMPL_INCLUDE_PATH $ENV{OMPL_INCLUDE_PATH})
41  if (NOT OMPL_INCLUDE_PATH)
42  set(OMPL_INCLUDE_PATH ${OMPL_PREFIX})
43  endif()
44 endif()
45 
46 # find the OMPL library
47 find_library(OMPL_LIBRARY ompl
48  PATHS ${OMPL_LIB_PATH}
49  PATH_SUFFIXES lib build/lib)
50 if (OMPL_LIBRARY)
51  if (OMPL_FIND_VERSION)
52  get_filename_component(libpath ${OMPL_LIBRARY} PATH)
53  file(GLOB OMPL_LIBS "${libpath}/libompl.${OMPL_FIND_VERSION}.*")
54  list(GET OMPL_LIBS -1 OMPL_LIBRARY)
55  endif()
56  set(OMPL_LIBRARIES "${OMPL_LIBRARY}" CACHE FILEPATH "Path to OMPL library")
57 endif()
58 # find the OMPL.app libraries
59 find_library(OMPLAPPBASE_LIBRARY ompl_app_base
60  PATHS ${OMPL_LIB_PATH}
61  PATH_SUFFIXES lib build/lib)
62 find_library(OMPLAPP_LIBRARY ompl_app
63  PATHS ${OMPL_LIB_PATH}
64  PATH_SUFFIXES lib build/lib)
65 if (OMPLAPPBASE_LIBRARY AND OMPLAPP_LIBRARY)
66  if (OMPL_FIND_VERSION)
67  get_filename_component(libpath ${OMPLAPPBASE_LIBRARY} PATH)
68  file(GLOB OMPLAPPBASE_LIBS "${libpath}/libompl_app_base.${OMPL_FIND_VERSION}.*")
69  list(GET OMPLAPPBASE_LIBS -1 OMPLAPPBASE_LIBRARY)
70  get_filename_component(libpath ${OMPLAPP_LIBRARY} PATH)
71  file(GLOB OMPLAPP_LIBS "${libpath}/libompl_app.${OMPL_FIND_VERSION}.*")
72  list(GET OMPLAPP_LIBS -1 OMPLAPP_LIBRARY)
73  endif()
74  set(OMPLAPP_LIBRARIES "${OMPLAPPBASE_LIBRARY};${OMPLAPP_LIBRARY}" CACHE STRING "Paths to OMPL.app libraries")
75 endif()
76 
77 # find include path
78 find_path(OMPL_INCLUDE_DIRS SpaceInformation.h
79  PATHS ${OMPL_INCLUDE_PATH}
80  PATH_SUFFIXES base "ompl${OMPL_SUFFIX}/base" "include/ompl${OMPL_SUFFIX}/base" ompl/base include/ompl/base src/ompl/base)
81 if (OMPL_INCLUDE_DIRS)
82  string(REGEX REPLACE "/ompl/base$" "" OMPL_INCLUDE_DIRS ${OMPL_INCLUDE_DIRS})
83 else()
84  set(OMPL_INCLUDE_DIRS "")
85 endif()
86 
87 # find version
88 find_file(OMPL_CONFIG config.h
89  PATHS ${OMPL_INCLUDE_DIRS}
90  PATH_SUFFIXES ompl
91  NO_DEFAULT_PATH)
92 if(OMPL_CONFIG)
93  file(READ ${OMPL_CONFIG} OMPL_CONFIG_STR)
94  string(REGEX REPLACE ".*OMPL_VERSION \"([0-9.]+)\".*" "\\1"
95  OMPL_VERSION
96  "${OMPL_CONFIG_STR}")
97  string(REGEX REPLACE "([0-9]+).([0-9]+).([0-9]+)" "\\1" OMPL_MAJOR_VERSION "${OMPL_VERSION}")
98  string(REGEX REPLACE "([0-9]+).([0-9]+).([0-9]+)" "\\2" OMPL_MINOR_VERSION "${OMPL_VERSION}")
99  string(REGEX REPLACE "([0-9]+).([0-9]+).([0-9]+)" "\\3" OMPL_PATCH_VERSION "${OMPL_VERSION}")
100 endif()
101 
102 find_package_handle_standard_args(OMPL DEFAULT_MSG OMPL_LIBRARIES OMPL_INCLUDE_DIRS)