zibbr

Random 3d and p2p stuff that was originally the beginnings of an overly ambitious p2p virtual world thingy
git clone https://code.literati.org/zibbr.git
Log | Files | Refs

FindPkgMacros.cmake (5149B)


      1 #-------------------------------------------------------------------
      2 # This file is part of the CMake build system for OGRE
      3 #     (Object-oriented Graphics Rendering Engine)
      4 # For the latest info, see http://www.ogre3d.org/
      5 #
      6 # The contents of this file are placed in the public domain. Feel
      7 # free to make use of it in any way you like.
      8 #-------------------------------------------------------------------
      9 
     10 ##################################################################
     11 # Provides some common functionality for the FindPackage modules
     12 ##################################################################
     13 
     14 # Begin processing of package
     15 macro(findpkg_begin PREFIX)
     16   if (NOT ${PREFIX}_FIND_QUIETLY)
     17     message(STATUS "Looking for ${PREFIX}...")
     18   endif ()
     19 endmacro(findpkg_begin)
     20 
     21 # Display a status message unless FIND_QUIETLY is set
     22 macro(pkg_message PREFIX)
     23   if (NOT ${PREFIX}_FIND_QUIETLY)
     24     message(STATUS ${ARGN})
     25   endif ()
     26 endmacro(pkg_message)
     27 
     28 # Get environment variable, define it as ENV_$var and make sure backslashes are converted to forward slashes
     29 macro(getenv_path VAR)
     30    set(ENV_${VAR} $ENV{${VAR}})
     31    # replace won't work if var is blank
     32    if (ENV_${VAR})
     33      string( REGEX REPLACE "\\\\" "/" ENV_${VAR} ${ENV_${VAR}} )
     34    endif ()
     35 endmacro(getenv_path)
     36 
     37 # Construct search paths for includes and libraries from a PREFIX_PATH
     38 macro(create_search_paths PREFIX)
     39   foreach(dir ${${PREFIX}_PREFIX_PATH})
     40     set(${PREFIX}_INC_SEARCH_PATH ${${PREFIX}_INC_SEARCH_PATH}
     41       ${dir}/include ${dir}/include/${PREFIX} ${dir}/Headers)
     42     set(${PREFIX}_LIB_SEARCH_PATH ${${PREFIX}_LIB_SEARCH_PATH}
     43       ${dir}/lib ${dir}/lib/${PREFIX} ${dir}/Libs)
     44   endforeach(dir)
     45   set(${PREFIX}_FRAMEWORK_SEARCH_PATH ${${PREFIX}_PREFIX_PATH})
     46 endmacro(create_search_paths)
     47 
     48 # clear cache variables if a certain variable changed
     49 macro(clear_if_changed TESTVAR)
     50   # test against internal check variable
     51   if (NOT "${${TESTVAR}}" STREQUAL "${${TESTVAR}_INT_CHECK}")
     52     message(STATUS "${TESTVAR} changed.")
     53     foreach(var ${ARGN})
     54       set(${var} "NOTFOUND" CACHE STRING "x" FORCE)
     55     endforeach(var)
     56   endif ()
     57   set(${TESTVAR}_INT_CHECK ${${TESTVAR}} CACHE INTERNAL "x" FORCE)
     58 endmacro(clear_if_changed)
     59 
     60 # Try to get some hints from pkg-config, if available
     61 macro(use_pkgconfig PREFIX PKGNAME)
     62   find_package(PkgConfig)
     63   if (PKG_CONFIG_FOUND)
     64     pkg_check_modules(${PREFIX} ${PKGNAME})
     65   endif ()
     66 endmacro (use_pkgconfig)
     67 
     68 # Couple a set of release AND debug libraries (or frameworks)
     69 macro(make_library_set PREFIX)
     70   if (${PREFIX}_FWK)
     71     set(${PREFIX} ${${PREFIX}_FWK})
     72   elseif (${PREFIX}_REL AND ${PREFIX}_DBG)
     73     set(${PREFIX} optimized ${${PREFIX}_REL} debug ${${PREFIX}_DBG})
     74   elseif (${PREFIX}_REL)
     75     set(${PREFIX} ${${PREFIX}_REL})
     76   elseif (${PREFIX}_DBG)
     77     set(${PREFIX} ${${PREFIX}_DBG})
     78   endif ()
     79 endmacro(make_library_set)
     80 
     81 # Generate debug names from given release names
     82 macro(get_debug_names PREFIX)
     83   foreach(i ${${PREFIX}})
     84     set(${PREFIX}_DBG ${${PREFIX}_DBG} ${i}d ${i}D ${i}_d ${i}_D ${i}_debug ${i})
     85   endforeach(i)
     86 endmacro(get_debug_names)
     87 
     88 # Add the parent dir from DIR to VAR 
     89 macro(add_parent_dir VAR DIR)
     90   get_filename_component(${DIR}_TEMP "${${DIR}}/.." ABSOLUTE)
     91   set(${VAR} ${${VAR}} ${${DIR}_TEMP})
     92 endmacro(add_parent_dir)
     93 
     94 # Do the final processing for the package find.
     95 macro(findpkg_finish PREFIX)
     96   # skip if already processed during this run
     97   if (NOT ${PREFIX}_FOUND)
     98     if (${PREFIX}_INCLUDE_DIR AND ${PREFIX}_LIBRARY)
     99       set(${PREFIX}_FOUND TRUE)
    100       set(${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIR})
    101       set(${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARY})
    102       if (NOT ${PREFIX}_FIND_QUIETLY)
    103         message(STATUS "Found ${PREFIX}: ${${PREFIX}_LIBRARIES}")
    104       endif ()
    105     else ()
    106       if (NOT ${PREFIX}_FIND_QUIETLY)
    107         message(STATUS "Could not locate ${PREFIX}")
    108       endif ()
    109       if (${PREFIX}_FIND_REQUIRED)
    110         message(FATAL_ERROR "Required library ${PREFIX} not found! Install the library (including dev packages) and try again. If the library is already installed, set the missing variables manually in cmake.")
    111       endif ()
    112     endif ()
    113 
    114     mark_as_advanced(${PREFIX}_INCLUDE_DIR ${PREFIX}_LIBRARY ${PREFIX}_LIBRARY_REL ${PREFIX}_LIBRARY_DBG ${PREFIX}_LIBRARY_FWK)
    115   endif ()
    116 endmacro(findpkg_finish)
    117 
    118 
    119 # Slightly customised framework finder
    120 MACRO(findpkg_framework fwk)
    121   IF(APPLE)
    122     SET(${fwk}_FRAMEWORK_PATH
    123       ${${fwk}_FRAMEWORK_SEARCH_PATH}
    124       ${CMAKE_FRAMEWORK_PATH}
    125       ~/Library/Frameworks
    126       /Library/Frameworks
    127       /System/Library/Frameworks
    128       /Network/Library/Frameworks
    129       /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/System/Library/Frameworks/
    130     )
    131     FOREACH(dir ${${fwk}_FRAMEWORK_PATH})
    132       SET(fwkpath ${dir}/${fwk}.framework)
    133       IF(EXISTS ${fwkpath})
    134         SET(${fwk}_FRAMEWORK_INCLUDES ${${fwk}_FRAMEWORK_INCLUDES}
    135           ${fwkpath}/Headers ${fwkpath}/PrivateHeaders)
    136         if (NOT ${fwk}_LIBRARY_FWK)
    137           SET(${fwk}_LIBRARY_FWK "-framework ${fwk}")
    138         endif ()
    139       ENDIF(EXISTS ${fwkpath})
    140     ENDFOREACH(dir)
    141   ENDIF(APPLE)
    142 ENDMACRO(findpkg_framework)