Skip to content

Commit

Permalink
add logic to find ogre and its components when there is also another …
Browse files Browse the repository at this point in the history
…source installation in the colcon workspace

Signed-off-by: Ian Chen <ichen@osrfoundation.org>
  • Loading branch information
iche033 committed Jul 1, 2021
1 parent 3b78702 commit f559887
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion cmake/FindIgnOGRE.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ if (NOT WIN32)

# loop through pkg config paths and find an ogre version that is < 2.0.0
foreach(pkg_path ${PKG_CONFIG_PATH_TMP})

if (NOT EXISTS ${pkg_path})
continue()
endif()

unset(OGRE_FOUND)
unset(OGRE_INCLUDE_DIRS)
unset(OGRE_LIBRARY_DIRS)
unset(OGRE_LIBRARIES)

set(ENV{PKG_CONFIG_PATH} ${pkg_path})
ign_pkg_check_modules_quiet(OGRE "OGRE >= ${full_version}"
NO_CMAKE_ENVIRONMENT_PATH
Expand All @@ -91,6 +101,31 @@ if (NOT WIN32)
if (NOT ${OGRE_VERSION} VERSION_LESS 2.0.0)
set (OGRE_FOUND false)
else ()
# set library dirs if the value is empty
if (NOT ${OGRE_LIBRARY_DIRS} OR ${OGRE_LIBRARY_DIRS} STREQUAL "")
execute_process(COMMAND pkg-config --variable=libdir OGRE
OUTPUT_VARIABLE _pkgconfig_invoke_result
RESULT_VARIABLE _pkgconfig_failed)
if(_pkgconfig_failed)
IGN_BUILD_WARNING ("Failed to find OGRE's library directory. The build will succeed, but there will likely be run-time errors.")
else()
# set ogre library dir and strip line brak
set(OGRE_LIBRARY_DIRS ${_pkgconfig_invoke_result})
string(REGEX REPLACE "\n$" "" OGRE_LIBRARY_DIRS "${OGRE_LIBRARY_DIRS}")

string(FIND "${OGRE_LIBRARIES}" "${OGRE_LIBRARY_DIRS}" substr_found)
# in some cases the value of OGRE_LIBRARIES is "OgreMain;pthread"
# Convert this to full path to library
if (substr_found EQUAL -1)
foreach(OGRE_LIBRARY_NAME ${OGRE_LIBRARIES})
find_library(OGRE_LIBRARY NAMES ${OGRE_LIBRARY_NAME}
HINTS ${OGRE_LIBRARY_DIRS} NO_DEFAULT_PATH)
list (APPEND TMP_OGRE_LIBRARIES "${OGRE_LIBRARY}")
endforeach()
set(OGRE_LIBRARIES ${TMP_OGRE_LIBRARIES})
endif()
endif()
endif()
break()
endif()
endif()
Expand All @@ -107,9 +142,10 @@ if (NOT WIN32)

# find ogre components
foreach(component ${IgnOGRE_FIND_COMPONENTS})
ign_pkg_check_modules_quiet(IgnOGRE-${component} "OGRE-${component} >= ${full_version}")
ign_pkg_check_modules_quiet(IgnOGRE-${component} "OGRE-${component} >= ${full_version}" NO_CMAKE_ENVIRONMENT_PATH)
if(IgnOGRE-${component}_FOUND)
list(APPEND OGRE_LIBRARIES IgnOGRE-${component}::IgnOGRE-${component})

elseif(IgnOGRE_FIND_REQUIRED_${component})
set(OGRE_FOUND false)
endif()
Expand Down

0 comments on commit f559887

Please sign in to comment.