← Back to team overview

kicad-developers team mailing list archive

[PATCH] Allow OpenCASCADE standard edition

 

​Hi All-

Currently, the build requires the opencascade community edition.  For
various reasons, I need to have the current non-community edition of
OpenCASCADE installed on my work machine.

The attached patch allows compiling KiCad with either the OpenCASCADE
community edition or standard edition.

I've tested on a homebrew-based Mac install as well as Linux but haven't
verified MSW, if someone would be willing to test it there, that would be
great!  The basic search routines are lightly modified from FreeCAD's logic
and keep their LGPL copyright on the CMake file.

-Seth​
From 9ee142958fce6419ec6301caa9a6d9353f93b62b Mon Sep 17 00:00:00 2001
From: Seth Hillbrand <hillbrand@xxxxxxxxxxx>
Date: Thu, 25 Jan 2018 16:38:29 -0800
Subject: [PATCH] Allow Kicad to use OpenCascade

Adds the option of using OpenCascade not just the community edition.
---
 CMakeLists.txt                     |   9 ++-
 CMakeModules/FindOpenCASCADE.cmake | 150 +++++++++++++++++++++++++++++++++++++
 plugins/3d/oce/CMakeLists.txt      |   4 +-
 plugins/3d/oce/loadmodel.cpp       |   2 -
 utils/kicad2step/CMakeLists.txt    |   4 +-
 5 files changed, 160 insertions(+), 9 deletions(-)
 create mode 100644 CMakeModules/FindOpenCASCADE.cmake

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 967927fb5..747d14aa9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -559,9 +559,12 @@ endif()
 
 # Find OpenCascade Community Edition, required for STEP plugin and tools
 if( KICAD_USE_OCE )
-    set( LIBS_OCE TKBinXCAF TKPCAF TKSTEP TKXDESTEP TKIGES TKXDEIGES )
-
-    find_package( OCE 0.16 REQUIRED ${LIBS_OCE} )
+    find_package(OpenCASCADE)
+    if( NOT OCC_FOUND )
+        MESSAGE( FATAL_ERROR "================================================================\n"
+                             "Neither OpenCASCADE Community Edition nor OpenCASCADE was found!\n"
+                             "================================================================\n")
+    endif()
 endif()
 
 # Assist with header file searching optimization:
diff --git a/CMakeModules/FindOpenCASCADE.cmake b/CMakeModules/FindOpenCASCADE.cmake
new file mode 100644
index 000000000..8fe9c912c
--- /dev/null
+++ b/CMakeModules/FindOpenCASCADE.cmake
@@ -0,0 +1,150 @@
+# 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
+
+############################################################################
+#
+# Modifications Copyright (C) 2018 Seth Hillbrand
+#
+# Based on FindOpenCasCade.cmake by the FreeCAD CADx development team
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+
+# First try to find OpenCASCADE Community Edition
+if(NOT DEFINED OCE_INCLUDE_DIR)
+  # Check for OSX needs to come first because UNIX evaluates to true on OSX
+  if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+    if(DEFINED HOMEBREW_PREFIX)
+      find_package(OCE QUIET HINTS ${HOMEBREW_PREFIX}/Cellar/oce/*)
+    elseif(DEFINED MACPORTS_PREFIX)
+      find_package(OCE QUIET HINTS ${MACPORTS_PREFIX}/Library/Frameworks)
+    endif()
+  else()
+    find_package(OCE QUIET)
+  endif()
+endif()
+
+if(OCE_FOUND)
+  message(STATUS "-- OpenCASCADE Community Edition has been found.")
+  set(OCC_INCLUDE_DIR ${OCE_INCLUDE_DIRS})
+else(OCE_FOUND) #look for OpenCASCADE
+  if(WIN32)
+    if(CYGWIN OR MINGW)
+    FIND_PATH(OCC_INCLUDE_DIR Standard_Version.hxx
+        /usr/include/opencascade
+        /usr/local/include/opencascade
+        /opt/opencascade/include
+        /opt/opencascade/inc
+      )
+      FIND_LIBRARY(OCC_LIBRARY TKernel
+        /usr/lib
+        /usr/local/lib
+        /opt/opencascade/lib
+      )
+    else(CYGWIN OR MINGW)
+    FIND_PATH(OCC_INCLUDE_DIR Standard_Version.hxx
+        "[HKEY_LOCAL_MACHINE\\SOFTWARE\\SIM\\OCC\\2;Installation Path]/include"
+      )
+      FIND_LIBRARY(OCC_LIBRARY TKernel
+        "[HKEY_LOCAL_MACHINE\\SOFTWARE\\SIM\\OCC\\2;Installation Path]/lib"
+      )
+    endif(CYGWIN OR MINGW)
+  else(WIN32)
+    FIND_PATH(OCC_INCLUDE_DIR Standard_Version.hxx
+      /usr/include/opencascade
+      /usr/local/include/opencascade
+      /opt/opencascade/include
+      /opt/opencascade/inc
+    )
+    FIND_LIBRARY(OCC_LIBRARY TKernel
+      /usr/lib
+      /usr/local/lib
+      /opt/opencascade/lib
+    )
+  endif(WIN32)
+  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
+    TKMesh
+    TKernel
+    TKG2d
+    TKG3d
+    TKMath
+    TKIGES
+    TKSTL
+    TKXSBase
+    TKBin
+    TKBO
+    TKCDF
+    TKBRep
+    TKTopAlgo
+    TKGeomAlgo
+    TKGeomBase
+    TKPrim
+    TKSTEP
+    TKSTEPBase
+    TKSTEPAttr
+    TKFeat
+  )
+  set(OCC_OCAF_LIBRARIES
+    TKCAF
+    TKXCAF
+    TKLCAF
+    TKXDESTEP
+    TKXDEIGES
+  )
+  if(OCC_VERSION_STRING VERSION_LESS 6.7.3)
+    list(APPEND OCC_OCAF_LIBRARIES TKAdvTools)
+  endif(OCC_VERSION_STRING VERSION_LESS 6.7.3)
+  message(STATUS "-- Found OCE/OpenCASCADE version: ${OCC_VERSION_STRING}")
+  message(STATUS "-- OCE/OpenCASCADE include directory: ${OCC_INCLUDE_DIR}")
+  message(STATUS "-- OCE/OpenCASCADE shared libraries directory: ${OCC_LIBRARY_DIR}")
+endif(OCC_FOUND)
diff --git a/plugins/3d/oce/CMakeLists.txt b/plugins/3d/oce/CMakeLists.txt
index 6c6163118..a27df761a 100644
--- a/plugins/3d/oce/CMakeLists.txt
+++ b/plugins/3d/oce/CMakeLists.txt
@@ -13,7 +13,7 @@
 #
 
 include_directories( SYSTEM
-    ${OCE_INCLUDE_DIRS}
+    ${OCC_INCLUDE_DIR}
 )
 
 add_library( s3d_plugin_oce MODULE
@@ -21,7 +21,7 @@ add_library( s3d_plugin_oce MODULE
         loadmodel.cpp
         )
 
-target_link_libraries( s3d_plugin_oce kicad_3dsg ${LIBS_OCE} ${wxWidgets_LIBRARIES} )
+target_link_libraries( s3d_plugin_oce kicad_3dsg ${OCC_LIBRARIES} ${OCC_OCAF_LIBRARIES} ${wxWidgets_LIBRARIES} )
 
 if( APPLE )
     # puts library into the main kicad.app bundle in build tree
diff --git a/plugins/3d/oce/loadmodel.cpp b/plugins/3d/oce/loadmodel.cpp
index 9d581f363..5ae69dc74 100644
--- a/plugins/3d/oce/loadmodel.cpp
+++ b/plugins/3d/oce/loadmodel.cpp
@@ -40,7 +40,6 @@
 #include <TopoDS_Shape.hxx>
 #include <Quantity_Color.hxx>
 #include <XCAFApp_Application.hxx>
-#include <Handle_XCAFApp_Application.hxx>
 
 #include <AIS_Shape.hxx>
 
@@ -53,7 +52,6 @@
 
 #include <XCAFDoc_DocumentTool.hxx>
 #include <XCAFDoc_ColorTool.hxx>
-#include <Handle_XCAFDoc_ColorTool.hxx>
 #include <XCAFDoc_ShapeTool.hxx>
 
 #include <BRep_Tool.hxx>
diff --git a/utils/kicad2step/CMakeLists.txt b/utils/kicad2step/CMakeLists.txt
index a60153f42..aa05455d0 100644
--- a/utils/kicad2step/CMakeLists.txt
+++ b/utils/kicad2step/CMakeLists.txt
@@ -5,7 +5,7 @@ include_directories( BEFORE
 )
 
 include_directories( SYSTEM 
-    ${OCE_INCLUDE_DIRS}
+    ${OCC_INCLUDE_DIR}
 )
 
 set( K2S_FILES
@@ -28,7 +28,7 @@ endif( MINGW )
 
 add_executable( kicad2step ${K2S_FILES} )
 
-target_link_libraries( kicad2step ${wxWidgets_LIBRARIES} ${LIBS_OCE} )
+target_link_libraries( kicad2step ${wxWidgets_LIBRARIES} ${OCC_LIBRARIES} ${OCC_OCAF_LIBRARIES} )
 
 if( APPLE )
     # puts binaries into the *.app bundle while linking
-- 
2.11.0


Follow ups