Skip to content

Commit

Permalink
Another try at OGRE2.1/OGRE2.2 on Windows (gazebosim#177)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
  • Loading branch information
mjcarroll authored Aug 16, 2021
1 parent 85e4c98 commit 33908b1
Showing 1 changed file with 119 additions and 60 deletions.
179 changes: 119 additions & 60 deletions cmake/FindIgnOGRE2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ macro(select_lib_by_build_type LIBRARY_STR OUTPUT_VAR)
endif()
endmacro()

# this macro and the version parsing logic below is taken from the
# FindOGRE.cmake file distributed by ogre
macro(get_preprocessor_entry CONTENTS KEYWORD VARIABLE)
string(REGEX MATCH
"# *define +${KEYWORD} +((\"([^\n]*)\")|([^ \n]*))"
PREPROC_TEMP_VAR
${${CONTENTS}}
)
if (CMAKE_MATCH_3)
set(${VARIABLE} ${CMAKE_MATCH_3})
else ()
set(${VARIABLE} ${CMAKE_MATCH_4})
endif ()
endmacro()

if (NOT WIN32)
set(PKG_CONFIG_PATH_ORIGINAL $ENV{PKG_CONFIG_PATH})

Expand Down Expand Up @@ -190,21 +205,6 @@ if (NOT WIN32)
list(APPEND OGRE2_INCLUDE_DIRS ${dir_include})
endforeach()

# this macro and the version parsing logic below is taken from the
# FindOGRE.cmake file distributed by ogre
macro(get_preprocessor_entry CONTENTS KEYWORD VARIABLE)
string(REGEX MATCH
"# *define +${KEYWORD} +((\"([^\n]*)\")|([^ \n]*))"
PREPROC_TEMP_VAR
${${CONTENTS}}
)
if (CMAKE_MATCH_3)
set(${VARIABLE} ${CMAKE_MATCH_3})
else ()
set(${VARIABLE} ${CMAKE_MATCH_4})
endif ()
endmacro()

file(READ ${OGRE2_INCLUDE}/OgrePrerequisites.h OGRE_TEMP_VERSION_CONTENT)
get_preprocessor_entry(OGRE_TEMP_VERSION_CONTENT OGRE_VERSION_MAJOR OGRE2_VERSION_MAJOR)
get_preprocessor_entry(OGRE_TEMP_VERSION_CONTENT OGRE_VERSION_MINOR OGRE2_VERSION_MINOR)
Expand Down Expand Up @@ -276,58 +276,117 @@ if (NOT WIN32)
ign_pkg_config_library_entry(IgnOGRE2 OgreMain)

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)
foreach(ogre_component ${IgnOGRE2_FIND_COMPONENTS})
set(OGRE_${ogre_component}_FOUND FALSE)
endforeach()
# currently designed to work with osrf vcpkg ogre2 portfile

set(OGRE2_FOUND TRUE)
set(OGRE_LIBRARIES "")
set(OGRE2_VERSION "")
set(OGRE2_VERSION_MAJOR "")
set(OGRE2_VERSION_MINOR "")
set(OGRE2_RESOURCE_PATH "")

set(OGRE2_SEARCH_VER "OGRE-${IgnOGRE2_FIND_VERSION_MAJOR}.${IgnOGRE2_FIND_VERSION_MINOR}")
set(OGRE2_PATHS "")
if(${IgnOGRE2_FIND_VERSION_MINOR} EQUAL 2)
message(STATUS "Finding 2")
# Specific case for osrf ogre 2.2 vcpkg
foreach(_rootPath ${VCPKG_CMAKE_FIND_ROOT_PATH})
list(APPEND OGRE2_PATHS "${_rootPath}/share/ogre22")
endforeach()
set(OGRE2_INC_PATHS "")
foreach(_rootPath ${VCPKG_CMAKE_FIND_ROOT_PATH})
list(APPEND OGRE2_PATHS "${_rootPath}/lib/${OGRE2_SEARCH_VER}/")
list(APPEND OGRE2_PATHS "${_rootPath}/lib/${OGRE2_SEARCH_VER}/manual-link/")
list(APPEND OGRE2_INC_PATHS "${_rootPath}/include/${OGRE2_SEARCH_VER}")
endforeach()

find_library(OGRE2_LIBRARY
NAMES "OgreMain"
HINTS ${OGRE2_PATHS}
NO_DEFAULT_PATH)

find_path(OGRE2_INCLUDE
NAMES "Ogre.h"
HINTS ${OGRE2_INC_PATHS})

if("${OGRE2_LIBRARY}" STREQUAL "OGRE2_LIBRARY-NOTFOUND")
set(OGRE2_FOUND false)
else()
set(OGRE2_PATHS ${VCPKG_CMAKE_FIND_ROOT_PATH})
set(OGRE2_LIBRARIES ${OGRE2_LIBRARY})
endif()

find_package(OGRE2
HINTS ${OGRE2_PATHS}
COMPONENTS ${IgnOGRE2_FIND_COMPONENTS})
set(OGRE2_INCLUDE_DIRS ${OGRE_INCLUDE_DIRS})
# Imported from OGRE1: link component libs outside of static build
foreach(ogre_component ${IgnOGRE2_FIND_COMPONENTS})
if (OGRE_${ogre_component}_FOUND)
list(APPEND OGRE_LIBRARIES "${OGRE_${ogre_component}_LIBRARIES}")
endif()
endforeach()

select_lib_by_build_type("${OGRE_LIBRARIES}" OGRE2_LIBRARIES)
if(NOT OGRE2_INCLUDE)
set(OGRE2_FOUND false)
endif()

set(OGRE2_PLUGINS_VCPKG Plugin_ParticleFX RenderSystem_GL RenderSystem_GL3Plus RenderSystem_Direct3D11)
if (OGRE2_FOUND)
set(OGRE2_INCLUDE_DIRS ${OGRE2_INC_PATHS})
set(OGRE2_LIBRARY_DIRS ${OGRE2_PATHS})

file(READ ${OGRE2_INCLUDE}/OgrePrerequisites.h OGRE_TEMP_VERSION_CONTENT)
get_preprocessor_entry(OGRE_TEMP_VERSION_CONTENT OGRE_VERSION_MAJOR OGRE2_VERSION_MAJOR)
get_preprocessor_entry(OGRE_TEMP_VERSION_CONTENT OGRE_VERSION_MINOR OGRE2_VERSION_MINOR)
get_preprocessor_entry(OGRE_TEMP_VERSION_CONTENT OGRE_VERSION_PATCH OGRE2_VERSION_PATCH)
get_preprocessor_entry(OGRE_TEMP_VERSION_CONTENT OGRE_VERSION_NAME OGRE2_VERSION_NAME)
set(OGRE2_VERSION "${OGRE2_VERSION_MAJOR}.${OGRE2_VERSION_MINOR}.${OGRE2_VERSION_PATCH}")
set(OGRE_TEMP_VERSION_CONTENT "")

macro(ogre_find_component COMPONENT HEADER PATH_HINTS)
set(PREFIX OGRE2_${COMPONENT})
find_path(${PREFIX}_INCLUDE_DIR
NAMES ${HEADER}
HINTS ${OGRE2_INCLUDE_DIRS}
PATH_SUFFIXES
${PATH_HINTS} ${COMPONENT} ${OGRE2_SEARCH_VER}/${COMPONENT})

find_library(${PREFIX}_LIBRARY
NAMES
"Ogre${COMPONENT}"
"Ogre${COMPONENT}_d"
HINTS
${OGRE2_LIBRARY_DIRS}
NO_DEFAULT_PATH)

if (NOT ${PREFIX}_FOUND)
if (${PREFIX}_INCLUDE_DIR AND ${PREFIX}_LIBRARY)
set(${PREFIX}_FOUND TRUE)
set(${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIR})
set(${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARY})
message(STATUS "Found ${PREFIX}: ${${PREFIX}_LIBRARIES}")
endif()
endif()
endmacro()

# look for Overlay component
ogre_find_component(Overlay OgreOverlaySystem.h "Overlay")
#look for HlmsPbs component
ogre_find_component(HlmsPbs OgreHlmsPbs.h Hlms/Pbs/)
#look for HlmsUnlit component
ogre_find_component(HlmsUnlit OgreHlmsUnlit.h Hlms/Unlit)

foreach(component ${IgnOGRE2_FIND_COMPONENTS})
set(PREFIX OGRE2_${component})
if(${PREFIX}_FOUND)
set(component_TARGET_NAME "IgnOGRE2-${component}::IgnOGRE2-${component}")
set(component_INCLUDE_DIRS ${PREFIX}_INCLUDE_DIRS)
# append the Hlms/Common include dir if it exists.
string(FIND ${component} "Hlms" HLMS_POS)
if(${HLMS_POS} GREATER -1)
foreach (dir ${OGRE2_INCLUDE_DIRS})
get_filename_component(dir_name "${dir}" NAME)
if ("${dir_name}" STREQUAL "OGRE-${OGRE2_VERSION_MAJOR}.${OGRE2_VERSION_MINOR}")
set(dir_include "${dir}/Hlms/Common")
if (EXISTS ${dir_include})
list(APPEND component_INCLUDE_DIRS ${dir_include})
endif()
endif()
endforeach()
endif()

foreach(PLUGIN ${OGRE2_PLUGINS_VCPKG})
if(OGRE_${PLUGIN}_FOUND)
message("Plugin found: ${PLUGIN}")
list(APPEND OGRE2_INCLUDE_DIRS ${OGRE_${PLUGIN}_INCLUDE_DIRS})
endif()
endforeach()
set(component_LIBRARIES ${${PREFIX}_LIBRARIES})

include(IgnPkgConfig)
ign_pkg_config_library_entry(IgnOGRE2 OgreMain)
ign_import_target(${component}
TARGET_NAME ${component_TARGET_NAME}
LIB_VAR component_LIBRARIES
INCLUDE_VAR component_INCLUDE_DIRS
)
list(APPEND OGRE2_LIBRARIES ${component_TARGET_NAME})
endif()
endforeach()
endif()
endif()

set(IgnOGRE2_FOUND false)
Expand Down

0 comments on commit 33908b1

Please sign in to comment.