FindOCC.cmake 3.33 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
# Try to find OCE / OCC
# Once done this will define
#
# OCC_FOUND          - system has OCC - OpenCASCADE
# OCC_INCLUDE_DIR    - where the OCC include directory can be found
# OCC_LIBRARY_DIR    - where the OCC library directory can be found
# OCC_LIBRARIES      - Link this to use OCC
# OCC_OCAF_LIBRARIES - Link this to use OCC OCAF framework
#
# Adapted from FreeCAD: http://free-cad.sf.net

set(TEST_ENV $ENV{OCE_ROOT})
if(NOT DEFINED OCE_DIR AND DEFINED TEST_ENV)
  file(GLOB OCE_DIR $ENV{OCE_ROOT}/lib/oce-*)
endif()

set(TEST_ENV $ENV{OCE_DIR})
if(NOT DEFINED OCE_DIR AND DEFINED TEST_ENV)
  set(OCE_DIR $ENV{OCE_DIR})
endif()

# First try to find OpenCASCADE Community Edition
if(NOT DEFINED OCE_DIR)
  # Check for OSX needs to come first because UNIX evaluates to true on OSX
  if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
    if(DEFINED MACPORTS_PREFIX)
27
      find_package(OCE 0.15 QUIET HINTS ${MACPORTS_PREFIX}/Library/Frameworks)
28
    elseif(DEFINED HOMEBREW_PREFIX)
29
      find_package(OCE 0.15 QUIET HINTS ${HOMEBREW_PREFIX}/Cellar/oce/*)
30 31 32 33 34 35
    endif()
  elseif(UNIX)
    set(OCE_DIR "/usr/local/share/cmake/")
  endif()
endif()

36
find_package(OCE 0.15 QUIET)
37 38 39 40
if(OCE_FOUND)
  message(STATUS "-- OpenCASCADE Community Edition has been found.")
  set(OCC_INCLUDE_DIR ${OCE_INCLUDE_DIRS})
else(OCE_FOUND) #look for OpenCASCADE
Michael Turner's avatar
Michael Turner committed
41

42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
    FIND_PATH(OCC_INCLUDE_DIR Standard_Version.hxx
      /usr/include/opencascade
      /usr/local/include/opencascade
      /usr/local/opt/opencascade/include
      /opt/opencascade/include
      /opt/opencascade/inc
      /opt/local/include/oce
    )
    FIND_LIBRARY(OCC_LIBRARY TKernel
      /usr/lib
      /usr/local/lib
      /usr/local/opt/opencascade/lib
      /opt/opencascade/lib
      opt/local/lib
    )
Michael Turner's avatar
Michael Turner committed
57

58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
  if(OCC_LIBRARY)
    GET_FILENAME_COMPONENT(OCC_LIBRARY_DIR ${OCC_LIBRARY} PATH)
    IF(NOT OCC_INCLUDE_DIR)
      FIND_PATH(OCC_INCLUDE_DIR Standard_Version.hxx
        ${OCC_LIBRARY_DIR}/../inc
      )
    ENDIF()
  endif(OCC_LIBRARY)
endif(OCE_FOUND)

if(OCC_INCLUDE_DIR)
  file(STRINGS ${OCC_INCLUDE_DIR}/Standard_Version.hxx OCC_MAJOR
    REGEX "#define OCC_VERSION_MAJOR.*"
  )
  string(REGEX MATCH "[0-9]+" OCC_MAJOR ${OCC_MAJOR})
  file(STRINGS ${OCC_INCLUDE_DIR}/Standard_Version.hxx OCC_MINOR
    REGEX "#define OCC_VERSION_MINOR.*"
  )
  string(REGEX MATCH "[0-9]+" OCC_MINOR ${OCC_MINOR})
  file(STRINGS ${OCC_INCLUDE_DIR}/Standard_Version.hxx OCC_MAINT
    REGEX "#define OCC_VERSION_MAINTENANCE.*"
  )
  string(REGEX MATCH "[0-9]+" OCC_MAINT ${OCC_MAINT})

  set(OCC_VERSION_STRING "${OCC_MAJOR}.${OCC_MINOR}.${OCC_MAINT}")
endif(OCC_INCLUDE_DIR)

# handle the QUIETLY and REQUIRED arguments and set OCC_FOUND to TRUE if
# all listed variables are TRUE
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(OCC REQUIRED_VARS OCC_INCLUDE_DIR VERSION_VAR OCC_VERSION_STRING)

if(OCC_FOUND)
  set(OCC_LIBRARIES
    TKFillet
    TKMesh
    TKernel
    TKG2d
    TKG3d
    TKMath
    TKIGES
    TKSTL
    TKShHealing
    TKXSBase
    TKBool
    TKBO
    TKBRep
    TKTopAlgo
    TKGeomAlgo
    TKGeomBase
    TKOffset
    TKPrim
    TKSTEP
    TKSTEPBase
    TKSTEPAttr
    TKHLR
    TKFeat
  )
Michael Turner's avatar
Michael Turner committed
116
  if(OCC_VERSION_STRING VERSION_LESS 6.7)
Michael Turner's avatar
Michael Turner committed
117
    MESSAGE(SEND_ERROR "OCC version too low")
Michael Turner's avatar
Michael Turner committed
118
  endif(OCC_VERSION_STRING VERSION_LESS 6.7)
Michael Turner's avatar
Michael Turner committed
119
  message(STATUS "-- Found OCE/OpenCASCADE with OCC version: ${OCC_VERSION_STRING}")
120
endif(OCC_FOUND)