All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
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 library
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 library
59 find_library(OMPLAPP_LIBRARY ompl_app
60  PATHS ${OMPL_LIB_PATH}
61  PATH_SUFFIXES lib build/lib)
62 if (OMPLAPP_LIBRARY)
63  if (OMPL_FIND_VERSION)
64  get_filename_component(libpath ${OMPLAPP_LIBRARY} PATH)
65  file(GLOB OMPLAPP_LIBS "${libpath}/libompl_app.${OMPL_FIND_VERSION}.*")
66  list(GET OMPLAPP_LIBS -1 OMPLAPP_LIBRARY)
67  endif()
68  set(OMPLAPP_LIBRARIES "${OMPLAPP_LIBRARY}" CACHE FILEPATH "Path to OMPL.app library")
69 endif()
70 
71 # find include path
72 find_path(OMPL_INCLUDE_DIRS SpaceInformation.h
73  PATHS ${OMPL_INCLUDE_PATH}
74  PATH_SUFFIXES base "ompl${OMPL_SUFFIX}/base" "include/ompl${OMPL_SUFFIX}/base" ompl/base include/ompl/base src/ompl/base)
75 if (OMPL_INCLUDE_DIRS)
76  string(REGEX REPLACE "/ompl/base$" "" OMPL_INCLUDE_DIRS ${OMPL_INCLUDE_DIRS})
77 else()
78  set(OMPL_INCLUDE_DIRS "")
79 endif()
80 
81 # find version
82 find_file(OMPL_CONFIG config.h
83  PATHS ${OMPL_INCLUDE_DIRS}
84  PATH_SUFFIXES ompl
85  NO_DEFAULT_PATH)
86 if(OMPL_CONFIG)
87  file(READ ${OMPL_CONFIG} OMPL_CONFIG_STR)
88  string(REGEX REPLACE ".*OMPL_VERSION \"([0-9.]+)\".*" "\\1"
89  OMPL_VERSION
90  "${OMPL_CONFIG_STR}")
91  string(REGEX REPLACE "([0-9]+).([0-9]+).([0-9]+)" "\\1" OMPL_MAJOR_VERSION "${OMPL_VERSION}")
92  string(REGEX REPLACE "([0-9]+).([0-9]+).([0-9]+)" "\\2" OMPL_MINOR_VERSION "${OMPL_VERSION}")
93  string(REGEX REPLACE "([0-9]+).([0-9]+).([0-9]+)" "\\3" OMPL_PATCH_VERSION "${OMPL_VERSION}")
94 endif()
95 
96 find_package_handle_standard_args(OMPL DEFAULT_MSG OMPL_LIBRARIES OMPL_INCLUDE_DIRS)