📄 findboost.cmake
字号:
# Read the whole file: # SET(BOOST_VERSION 0) SET(BOOST_LIB_VERSION "") FILE(READ "${Boost_INCLUDE_DIR}/boost/version.hpp" _boost_VERSION_HPP_CONTENTS) STRING(REGEX REPLACE ".*#define BOOST_VERSION ([0-9]+).*" "\\1" Boost_VERSION "${_boost_VERSION_HPP_CONTENTS}") STRING(REGEX REPLACE ".*#define BOOST_LIB_VERSION \"([0-9_]+)\".*" "\\1" Boost_LIB_VERSION "${_boost_VERSION_HPP_CONTENTS}") SET(Boost_LIB_VERSION ${Boost_LIB_VERSION} CACHE INTERNAL "The library version string for boost libraries") SET(Boost_VERSION ${Boost_VERSION} CACHE INTERNAL "The version number for boost libraries") IF(NOT "${Boost_VERSION}" STREQUAL "0") MATH(EXPR Boost_MAJOR_VERSION "${Boost_VERSION} / 100000") MATH(EXPR Boost_MINOR_VERSION "${Boost_VERSION} / 100 % 1000") MATH(EXPR Boost_SUBMINOR_VERSION "${Boost_VERSION} % 100") set(Boost_ERROR_REASON "${Boost_ERROR_REASON}Boost version: ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}\nBoost include path: ${Boost_INCLUDE_DIR}") ENDIF(NOT "${Boost_VERSION}" STREQUAL "0") ELSE(Boost_INCLUDE_DIR) set(Boost_ERROR_REASON "${Boost_ERROR_REASON}Unable to find the Boost header files. Please set BOOST_ROOT to the root directory containing Boost or BOOST_INCLUDEDIR to the directory containing Boost's headers.") ENDIF(Boost_INCLUDE_DIR) # Setting some more suffixes for the library SET (Boost_LIB_PREFIX "") IF ( WIN32 AND Boost_USE_STATIC_LIBS ) SET (Boost_LIB_PREFIX "lib") ENDIF ( WIN32 AND Boost_USE_STATIC_LIBS ) SET (_boost_COMPILER "-gcc") IF (MSVC90) SET (_boost_COMPILER "-vc90") ELSEIF (MSVC80) SET (_boost_COMPILER "-vc80") ELSEIF (MSVC71) SET (_boost_COMPILER "-vc71") ENDIF(MSVC90) IF (MINGW) EXEC_PROGRAM(${CMAKE_CXX_COMPILER} ARGS -dumpversion OUTPUT_VARIABLE _boost_COMPILER_VERSION ) STRING(REGEX REPLACE "([0-9])\\.([0-9])\\.[0-9]" "\\1\\2" _boost_COMPILER_VERSION ${_boost_COMPILER_VERSION}) SET (_boost_COMPILER "-mgw${_boost_COMPILER_VERSION}") ENDIF(MINGW) IF (UNIX) IF (NOT CMAKE_COMPILER_IS_GNUCC) # We assume that we have the Intel compiler. SET (_boost_COMPILER "-il") ELSE (NOT CMAKE_COMPILER_IS_GNUCC) # Determine which version of GCC we have. EXEC_PROGRAM(${CMAKE_CXX_COMPILER} ARGS -dumpversion OUTPUT_VARIABLE _boost_COMPILER_VERSION ) STRING(REGEX REPLACE "([0-9])\\.([0-9])\\.[0-9]" "\\1\\2" _boost_COMPILER_VERSION ${_boost_COMPILER_VERSION}) IF(APPLE) IF(Boost_MINOR_VERSION) IF(${Boost_MINOR_VERSION} GREATER 35) # In Boost 1.36.0 and newer, the mangled compiler name used # on Mac OS X/Darwin is "xgcc". SET(_boost_COMPILER "-xgcc${_boost_COMPILER_VERSION}") ELSE(${Boost_MINOR_VERSION} GREATER 35) # In Boost <= 1.35.0, there is no mangled compiler name for # the Mac OS X/Darwin version of GCC. SET(_boost_COMPILER "") ENDIF(${Boost_MINOR_VERSION} GREATER 35) ELSE(Boost_MINOR_VERSION) # We don't know the Boost version, so assume it's # pre-1.36.0. SET(_boost_COMPILER "") ENDIF(Boost_MINOR_VERSION) ELSE() SET (_boost_COMPILER "-gcc${_boost_COMPILER_VERSION}") ENDIF() ENDIF (NOT CMAKE_COMPILER_IS_GNUCC) ENDIF(UNIX) SET (_boost_MULTITHREADED "-mt") IF( NOT Boost_USE_MULTITHREADED ) SET (_boost_MULTITHREADED "") ENDIF( NOT Boost_USE_MULTITHREADED ) SET( _boost_STATIC_TAG "") IF (WIN32) IF(MSVC) SET (_boost_ABI_TAG "g") ENDIF(MSVC) IF( Boost_USE_STATIC_LIBS ) SET( _boost_STATIC_TAG "-s") ENDIF( Boost_USE_STATIC_LIBS ) ENDIF(WIN32) SET (_boost_ABI_TAG "${_boost_ABI_TAG}d") # ------------------------------------------------------------------------ # Begin finding boost libraries # ------------------------------------------------------------------------ FOREACH(COMPONENT ${Boost_FIND_COMPONENTS}) STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT) SET( Boost_${UPPERCOMPONENT}_LIBRARY "Boost_${UPPERCOMPONENT}_LIBRARY-NOTFOUND" ) SET( Boost_${UPPERCOMPONENT}_LIBRARY_RELEASE "Boost_${UPPERCOMPONENT}_LIBRARY_RELEASE-NOTFOUND" ) SET( Boost_${UPPERCOMPONENT}_LIBRARY_DEBUG "Boost_${UPPERCOMPONENT}_LIBRARY_DEBUG-NOTFOUND") # Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES IF( Boost_USE_STATIC_LIBS ) SET( _boost_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) IF(WIN32) SET(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) ELSE(WIN32) SET(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) ENDIF(WIN32) ENDIF( Boost_USE_STATIC_LIBS ) FIND_LIBRARY(Boost_${UPPERCOMPONENT}_LIBRARY_RELEASE NAMES ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}-${Boost_LIB_VERSION} ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_STATIC_TAG}-${Boost_LIB_VERSION} ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED} ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_STATIC_TAG} ${Boost_LIB_PREFIX}boost_${COMPONENT} HINTS ${_boost_LIBRARIES_SEARCH_DIRS} ) FIND_LIBRARY(Boost_${UPPERCOMPONENT}_LIBRARY_DEBUG NAMES ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}-${_boost_ABI_TAG}-${Boost_LIB_VERSION} ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_STATIC_TAG}${_boost_ABI_TAG}-${Boost_LIB_VERSION} ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}-${_boost_ABI_TAG} ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_STATIC_TAG}${_boost_ABI_TAG} ${Boost_LIB_PREFIX}boost_${COMPONENT}-${_boost_ABI_TAG} HINTS ${_boost_LIBRARIES_SEARCH_DIRS} ) _Boost_ADJUST_LIB_VARS(${UPPERCOMPONENT}) IF( Boost_USE_STATIC_LIBS ) SET(CMAKE_FIND_LIBRARY_SUFFIXES ${_boost_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) ENDIF( Boost_USE_STATIC_LIBS ) ENDFOREACH(COMPONENT) # ------------------------------------------------------------------------ # End finding boost libraries # ------------------------------------------------------------------------ SET(Boost_INCLUDE_DIRS ${Boost_INCLUDE_DIR} ) SET(Boost_FOUND FALSE) IF(Boost_INCLUDE_DIR) SET( Boost_FOUND TRUE ) # Check the version of Boost against the requested version. if (Boost_FIND_VERSION AND NOT Boost_FIND_VERSION_MINOR) message(SEND_ERROR "When requesting a specific version of Boost, you must provide at least the major and minor version numbers, e.g., 1.34") endif (Boost_FIND_VERSION AND NOT Boost_FIND_VERSION_MINOR) if(Boost_MAJOR_VERSION LESS "${Boost_FIND_VERSION_MAJOR}" ) set( Boost_FOUND FALSE ) set(_Boost_VERSION_AGE "old") elseif(Boost_MAJOR_VERSION EQUAL "${Boost_FIND_VERSION_MAJOR}" ) if(Boost_MINOR_VERSION LESS "${Boost_FIND_VERSION_MINOR}" ) set( Boost_FOUND FALSE ) set(_Boost_VERSION_AGE "old") elseif(Boost_MINOR_VERSION EQUAL "${Boost_FIND_VERSION_MINOR}" ) if( Boost_FIND_VERSION_PATCH AND Boost_SUBMINOR_VERSION LESS "${Boost_FIND_VERSION_PATCH}" ) set( Boost_FOUND FALSE ) set(_Boost_VERSION_AGE "old") endif( Boost_FIND_VERSION_PATCH AND Boost_SUBMINOR_VERSION LESS "${Boost_FIND_VERSION_PATCH}" ) endif( Boost_MINOR_VERSION LESS "${Boost_FIND_VERSION_MINOR}" ) endif( Boost_MAJOR_VERSION LESS "${Boost_FIND_VERSION_MAJOR}" ) if (Boost_FOUND AND Boost_FIND_VERSION_EXACT) # If the user requested an exact version of Boost, check # that. We already know that the Boost version we have is >= the # requested version. set(_Boost_VERSION_AGE "new") # If the user didn't specify a patchlevel, it's 0. if (NOT Boost_FIND_VERSION_PATCH) set(Boost_FIND_VERSION_PATCH 0) endif (NOT Boost_FIND_VERSION_PATCH) # We'll set Boost_FOUND true again if we have an exact version match. set(Boost_FOUND FALSE) if(Boost_MAJOR_VERSION EQUAL "${Boost_FIND_VERSION_MAJOR}" ) if(Boost_MINOR_VERSION EQUAL "${Boost_FIND_VERSION_MINOR}" ) if(Boost_SUBMINOR_VERSION EQUAL "${Boost_FIND_VERSION_PATCH}" ) set( Boost_FOUND TRUE ) endif(Boost_SUBMINOR_VERSION EQUAL "${Boost_FIND_VERSION_PATCH}" ) endif( Boost_MINOR_VERSION EQUAL "${Boost_FIND_VERSION_MINOR}" ) endif( Boost_MAJOR_VERSION EQUAL "${Boost_FIND_VERSION_MAJOR}" ) endif (Boost_FOUND AND Boost_FIND_VERSION_EXACT) if(NOT Boost_FOUND) # State that we found a version of Boost that is too new or too old. set(Boost_ERROR_REASON "${Boost_ERROR_REASON}\nDetected version of Boost is too ${_Boost_VERSION_AGE}. Requested version was ${Boost_FIND_VERSION_MAJOR}.${Boost_FIND_VERSION_MINOR}") if (Boost_FIND_VERSION_PATCH) set(Boost_ERROR_REASON "${Boost_ERROR_REASON}.${Boost_FIND_VERSION_PATCH}") endif (Boost_FIND_VERSION_PATCH) if (NOT Boost_FIND_VERSION_EXACT) set(Boost_ERROR_REASON "${Boost_ERROR_REASON} (or newer)") endif (NOT Boost_FIND_VERSION_EXACT) set(Boost_ERROR_REASON "${Boost_ERROR_REASON}.") endif (NOT Boost_FOUND) if (Boost_FOUND) set(_boost_CHECKED_COMPONENT FALSE) set(_Boost_MISSING_COMPONENTS) foreach(COMPONENT ${Boost_FIND_COMPONENTS}) string(TOUPPER ${COMPONENT} COMPONENT) set(_boost_CHECKED_COMPONENT TRUE) if(NOT Boost_${COMPONENT}_FOUND) string(TOLOWER ${COMPONENT} COMPONENT) list(APPEND _Boost_MISSING_COMPONENTS ${COMPONENT}) set( Boost_FOUND FALSE) endif(NOT Boost_${COMPONENT}_FOUND) endforeach(COMPONENT) endif (Boost_FOUND) if (_Boost_MISSING_COMPONENTS) # We were unable to find some libraries, so generate a sensible # error message that lists the libraries we were unable to find. set(Boost_ERROR_REASON "${Boost_ERROR_REASON}\nThe following Boost libraries could not be found:\n") foreach(COMPONENT ${_Boost_MISSING_COMPONENTS}) set(Boost_ERROR_REASON "${Boost_ERROR_REASON} boost_${COMPONENT}\n") endforeach(COMPONENT) list(LENGTH Boost_FIND_COMPONENTS Boost_NUM_COMPONENTS_WANTED) list(LENGTH _Boost_MISSING_COMPONENTS Boost_NUM_MISSING_COMPONENTS) if (${Boost_NUM_COMPONENTS_WANTED} EQUAL ${Boost_NUM_MISSING_COMPONENTS}) set(Boost_ERROR_REASON "${Boost_ERROR_REASON}No Boost libraries were found. You may need to set Boost_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT to the location of Boost.") else (${Boost_NUM_COMPONENTS_WANTED} EQUAL ${Boost_NUM_MISSING_COMPONENTS}) set(Boost_ERROR_REASON "${Boost_ERROR_REASON}Some (but not all) of the required Boost libraries were found. You may need to install these additional Boost libraries. Alternatively, set Boost_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT to the location of Boost.") endif (${Boost_NUM_COMPONENTS_WANTED} EQUAL ${Boost_NUM_MISSING_COMPONENTS}) endif (_Boost_MISSING_COMPONENTS) IF( NOT Boost_LIBRARY_DIRS AND NOT _boost_CHECKED_COMPONENT ) # Compatibility Code for backwards compatibility with CMake # 2.4's FindBoost module. # Look for the boost library path. # Note that the user may not have installed any libraries # so it is quite possible the Boost_LIBRARY_PATH may not exist. SET(_boost_LIB_DIR ${Boost_INCLUDE_DIR}) IF("${_boost_LIB_DIR}" MATCHES "boost-[0-9]+") GET_FILENAME_COMPONENT(_boost_LIB_DIR ${_boost_LIB_DIR} PATH) ENDIF ("${_boost_LIB_DIR}" MATCHES "boost-[0-9]+") IF("${_boost_LIB_DIR}" MATCHES "/include$") # Strip off the trailing "/include" in the path. GET_FILENAME_COMPONENT(_boost_LIB_DIR ${_boost_LIB_DIR} PATH) ENDIF("${_boost_LIB_DIR}" MATCHES "/include$") IF(EXISTS "${_boost_LIB_DIR}/lib") SET (_boost_LIB_DIR ${_boost_LIB_DIR}/lib) ELSE(EXISTS "${_boost_LIB_DIR}/lib") IF(EXISTS "${_boost_LIB_DIR}/stage/lib") SET(_boost_LIB_DIR ${_boost_LIB_DIR}/stage/lib) ELSE(EXISTS "${_boost_LIB_DIR}/stage/lib") SET(_boost_LIB_DIR "") ENDIF(EXISTS "${_boost_LIB_DIR}/stage/lib") ENDIF(EXISTS "${_boost_LIB_DIR}/lib") IF(_boost_LIB_DIR AND EXISTS "${_boost_LIB_DIR}") SET(Boost_LIBRARY_DIRS ${_boost_LIB_DIR} CACHE FILEPATH "Boost library directory") ENDIF(_boost_LIB_DIR AND EXISTS "${_boost_LIB_DIR}") ENDIF( NOT Boost_LIBRARY_DIRS AND NOT _boost_CHECKED_COMPONENT ) ELSE(Boost_INCLUDE_DIR) SET( Boost_FOUND FALSE) ENDIF(Boost_INCLUDE_DIR) IF (Boost_FOUND) IF (NOT Boost_FIND_QUIETLY) MESSAGE(STATUS "Boost version: ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}") ENDIF(NOT Boost_FIND_QUIETLY) IF (NOT Boost_FIND_QUIETLY) MESSAGE(STATUS "Found the following Boost libraries:") ENDIF(NOT Boost_FIND_QUIETLY) FOREACH ( COMPONENT ${Boost_FIND_COMPONENTS} ) STRING( TOUPPER ${COMPONENT} UPPERCOMPONENT ) IF ( Boost_${UPPERCOMPONENT}_FOUND ) IF (NOT Boost_FIND_QUIETLY) MESSAGE (STATUS " ${COMPONENT}") ENDIF(NOT Boost_FIND_QUIETLY) SET(Boost_LIBRARIES ${Boost_LIBRARIES} ${Boost_${UPPERCOMPONENT}_LIBRARY}) ENDIF ( Boost_${UPPERCOMPONENT}_FOUND ) ENDFOREACH(COMPONENT) ELSE (Boost_FOUND) IF (Boost_FIND_REQUIRED) message(SEND_ERROR "Unable to find the requested Boost libraries.\n${Boost_ERROR_REASON}") ENDIF(Boost_FIND_REQUIRED) ENDIF(Boost_FOUND) # Under Windows, automatic linking is performed, so no need to specify the libraries. IF (WIN32) IF (NOT MINGW) SET(Boost_LIBRARIES "") ENDIF (NOT MINGW) ENDIF(WIN32) # show the Boost_INCLUDE_DIRS AND Boost_LIBRARIES variables only in the advanced view MARK_AS_ADVANCED(Boost_INCLUDE_DIR Boost_INCLUDE_DIRS Boost_LIBRARY_DIRS Boost_USE_MULTITHREADED )ENDIF(_boost_IN_CACHE)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -