Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix building OGRE / OGRE2 from source in colcon workspace #174

Merged
merged 4 commits into from
Aug 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions cmake/FindIgnOGRE.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ if (NOT WIN32)
RESULT_VARIABLE _pkgconfig_failed)
if(_pkgconfig_failed)
IGN_BUILD_WARNING ("Failed to get pkg-config search paths")
elseif (NOT "_pkgconfig_invoke_result" STREQUAL "")
elseif (NOT _pkgconfig_invoke_result STREQUAL "")
set (PKG_CONFIG_PATH_TMP "${PKG_CONFIG_PATH_TMP}:${_pkgconfig_invoke_result}")
endif()

Expand All @@ -83,6 +83,13 @@ 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()
set(OGRE_FOUND false)
set(OGRE_INCLUDE_DIRS "")
set(OGRE_LIBRARY_DIRS "")
set(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 +98,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 break
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,7 +139,7 @@ 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})
Expand Down
13 changes: 12 additions & 1 deletion cmake/FindIgnOGRE2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ if (NOT WIN32)
RESULT_VARIABLE _pkgconfig_failed)
if(_pkgconfig_failed)
IGN_BUILD_WARNING ("Failed to get pkg-config search paths")
elseif (NOT "_pkgconfig_invoke_result" STREQUAL "")
elseif (NOT _pkgconfig_invoke_result STREQUAL "")
set (PKG_CONFIG_PATH_TMP "${PKG_CONFIG_PATH_TMP}:${_pkgconfig_invoke_result}")
endif()

Expand Down Expand Up @@ -217,6 +217,8 @@ if (NOT WIN32)
foreach(component ${IgnOGRE2_FIND_COMPONENTS})
find_library(OGRE2-${component}
NAMES
"Ogre${component}_d.${OGRE2_VERSION}"
"Ogre${component}_d"
"Ogre${component}.${OGRE2_VERSION}"
"Ogre${component}"
HINTS ${OGRE2_LIBRARY_DIRS})
Expand Down Expand Up @@ -275,6 +277,15 @@ if (NOT WIN32)

else() #WIN32
# reset ogre variables to be sure they dont conflict with OGRE1
# todo(anyone) May need to change this to set(<variable> "")
# and verify that it works on Windows.
# More info: when evaluating Variable References of the form ${VAR}, CMake
# first searches for a normal variable with that name. If no such normal
# variable exists, CMake will then search for a cache entry with that name.
# Because of this unsetting a normal variable can expose a cache variable
# that was previously hidden. To force a variable reference of the form ${VAR}
# to return an empty string, use set(<variable> ""), which clears the normal
# variable but leaves it defined.
unset(OGRE_FOUND)
unset(OGRE_INCLUDE_DIRS)
unset(OGRE_LIBRARIES)
Expand Down