From a0815350588137841b2420066f227d63f0041766 Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Wed, 18 Aug 2021 19:14:02 -0500 Subject: [PATCH] Revert "Another try at OGRE2.1/OGRE2.2 on Windows (#177)" This reverts commit 33908b1f2fe67bffdca69c225c0fc286f86000c2. --- cmake/FindIgnOGRE2.cmake | 179 +++++++++++++-------------------------- 1 file changed, 60 insertions(+), 119 deletions(-) diff --git a/cmake/FindIgnOGRE2.cmake b/cmake/FindIgnOGRE2.cmake index 0e1aecf6..cb5bb843 100644 --- a/cmake/FindIgnOGRE2.cmake +++ b/cmake/FindIgnOGRE2.cmake @@ -92,21 +92,6 @@ 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}) @@ -205,6 +190,21 @@ 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) @@ -276,117 +276,58 @@ if (NOT WIN32) ign_pkg_config_library_entry(IgnOGRE2 OgreMain) else() #WIN32 - - 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 "") - 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}") + # reset ogre variables to be sure they dont conflict with OGRE1 + # todo(anyone) May need to change this to set( "") + # 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( ""), 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() - - 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) + # currently designed to work with osrf vcpkg ogre2 portfile + 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() else() - set(OGRE2_LIBRARIES ${OGRE2_LIBRARY}) + set(OGRE2_PATHS ${VCPKG_CMAKE_FIND_ROOT_PATH}) endif() - if(NOT OGRE2_INCLUDE) - set(OGRE2_FOUND false) - 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() - 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() + select_lib_by_build_type("${OGRE_LIBRARIES}" OGRE2_LIBRARIES) - set(component_LIBRARIES ${${PREFIX}_LIBRARIES}) + set(OGRE2_PLUGINS_VCPKG Plugin_ParticleFX RenderSystem_GL RenderSystem_GL3Plus RenderSystem_Direct3D11) - 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() + foreach(PLUGIN ${OGRE2_PLUGINS_VCPKG}) + if(OGRE_${PLUGIN}_FOUND) + message("Plugin found: ${PLUGIN}") + list(APPEND OGRE2_INCLUDE_DIRS ${OGRE_${PLUGIN}_INCLUDE_DIRS}) + endif() + endforeach() + + include(IgnPkgConfig) + ign_pkg_config_library_entry(IgnOGRE2 OgreMain) endif() set(IgnOGRE2_FOUND false)