← Back to team overview

kicad-developers team mailing list archive

Re: [PATCH] Allow OpenCASCADE standard edition

 

Nick-

Thanks for the test.  I'm attaching revised patch that allows multiple
OpenCASCADE installations on a single machine.

I've tested with a few different OpenCASCADE versions down to 6.8 with no
issues installed alongside OCE 0.17.  You can choose which you want to link
by using either "-DKICAD_USE_OCE" or "-DKICAD_USE_OCC".  If both are
specified, "-DKICAD_USE_OCC" will override.

I corrected the cmake message display to be less doubled and correctly show
the library location.

I've also added the OCC version and type to the about window version info.

The "Based on" line was taken from (
https://github.com/FreeCAD/FreeCAD/blob/master/src/FCConfig.h) when trying
to determine how FreeCAD likes to refer to themselves.  The actual
FindOpenCascade.cmake file did not have a copyright header attached but
falls under the license from (
https://github.com/FreeCAD/FreeCAD/blob/master/COPYING).  I note that I had
it written as "FreeCAD CADx development system".  I've corrected this to
read "FreeCAD CAx development system".

I'm not sure to what the "CheckSymbolExists" line is referring.  I don't
see it on my machine.

-Seth

2018-01-29 14:30 GMT-08:00 Nick Østergaard <oe.nick@xxxxxxxxx>:

> Hi Seth,
>
> I just took the patch for a testrun and will state some comments below.
>
> This looks a bit strange:
>
> -- Boost version: 1.66.0
> -- -- OpenCASCADE Community Edition has been found.
> -- -- Found OCE/OpenCASCADE version: 6.8.0
> -- -- OCE/OpenCASCADE include directory: /opt/oce/lib/oce-0.17/../../
> include/oce
> -- -- OCE/OpenCASCADE shared libraries directory:
> -- Check for installed Python Interpreter -- found
>
> The messages are with double -- and the shared libs.
>
> But an improvement with your patch over what is currently in kicad is that
> it found OCE on my system without explicitly specifind OCE_DIR. But how do
> I make it use OCCT when I also have OCE installed?
>
> What does CADx mean in that header?
>
> What is this about?
> -- Looking for /home/amazingdude/kicad-source-mirror/build_seths_
> occt_patch_occt/CMakeFiles/CMakeTmp/CheckSymbolExists.cxx
> -- Looking for /home/amazingdude/kicad-source-mirror/build_seths_
> occt_patch_occt/CMakeFiles/CMakeTmp/CheckSymbolExists.cxx - not found
>
> I tried to test it with removing oce and just have occt installed and got
> something like this:
> -- Found OCC: /opt/opencascade/inc (found version "6.9.1")
> -- -- Found OCE/OpenCASCADE version: 6.9.1
> -- -- OCE/OpenCASCADE include directory: /opt/opencascade/inc
> -- -- OCE/OpenCASCADE shared libraries directory: /opt/opencascade/lib
>
> It did not build against community/opencascade 6.9.1-7. I got the
> following error in a clean build dir.
>
> $ make kicad2step -j1
> [  0%] Linking CXX executable kicad2step
> /usr/bin/ld: cannot find -lTKMesh
> /usr/bin/ld: cannot find -lTKernel
> /usr/bin/ld: cannot find -lTKG2d
> /usr/bin/ld: cannot find -lTKG3d
> /usr/bin/ld: cannot find -lTKMath
> /usr/bin/ld: cannot find -lTKIGES
> /usr/bin/ld: cannot find -lTKSTL
> /usr/bin/ld: cannot find -lTKXSBase
> /usr/bin/ld: cannot find -lTKBin
> /usr/bin/ld: cannot find -lTKBO
> /usr/bin/ld: cannot find -lTKCDF
> /usr/bin/ld: cannot find -lTKBRep
> /usr/bin/ld: cannot find -lTKTopAlgo
> /usr/bin/ld: cannot find -lTKGeomAlgo
> /usr/bin/ld: cannot find -lTKGeomBase
> /usr/bin/ld: cannot find -lTKPrim
> /usr/bin/ld: cannot find -lTKSTEP
> /usr/bin/ld: cannot find -lTKSTEPBase
> /usr/bin/ld: cannot find -lTKSTEPAttr
> /usr/bin/ld: cannot find -lTKFeat
> /usr/bin/ld: cannot find -lTKCAF
> /usr/bin/ld: cannot find -lTKXCAF
> /usr/bin/ld: cannot find -lTKLCAF
> /usr/bin/ld: cannot find -lTKXDESTEP
> /usr/bin/ld: cannot find -lTKXDEIGES
> collect2: error: ld returned 1 exit status
> make[3]: *** [utils/kicad2step/CMakeFiles/kicad2step.dir/build.make:355:
> utils/kicad2step/kicad2step] Error 1
> make[2]: *** [CMakeFiles/Makefile2:3007: utils/kicad2step/CMakeFiles/kicad2step.dir/all]
> Error 2
> make[1]: *** [CMakeFiles/Makefile2:3019: utils/kicad2step/CMakeFiles/kicad2step.dir/rule]
> Error 2
> make: *** [Makefile:979: kicad2step] Error 2
>
> But those libs do existm, searched for the last one;
> $ yaourt  -Ql opencascade | grep TKXDEIGES
> opencascade /opt/opencascade/lib/libTKXDEIGES.so
> opencascade /opt/opencascade/lib/libTKXDEIGES.so.0
> opencascade /opt/opencascade/lib/libTKXDEIGES.so.0.0.0
>
> I got these variables set in the CMakeCache
>
> cat CMakeCache.txt  | grep "OCE\|OCC"
> KICAD_USE_OCE:BOOL=ON
> OCC_INCLUDE_DIR:PATH=/opt/opencascade/inc
> OCC_LIBRARY:FILEPATH=/opt/opencascade/lib/libTKernel.so
> //The directory containing a CMake configuration file for OCE.
> OCE_DIR:PATH=OCE_DIR-NOTFOUND
> //Details about finding OCC
> FIND_PACKAGE_MESSAGE_DETAILS_OCC:INTERNAL=[/opt/opencascade/inc][v6.9.1()]
>
> This is tested on archlinux.
>
> 2018-01-29 19:54 GMT+01:00 Seth Hillbrand <seth.hillbrand@xxxxxxxxx>:
>
>> ​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​
>>
>>
>> _______________________________________________
>> Mailing list: https://launchpad.net/~kicad-developers
>> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
>> Unsubscribe : https://launchpad.net/~kicad-developers
>> More help   : https://help.launchpad.net/ListHelp
>>
>>
>
From f563c526b8646a99365be2fa94ffbc792737835e 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                       |  29 ++++--
 CMakeModules/FindOpenCASCADE.cmake   | 169 +++++++++++++++++++++++++++++++++++
 common/dialog_about/dialog_about.cpp |  18 ++++
 plugins/3d/oce/CMakeLists.txt        |   4 +-
 plugins/3d/oce/loadmodel.cpp         |   2 -
 utils/kicad2step/CMakeLists.txt      |   4 +-
 6 files changed, 215 insertions(+), 11 deletions(-)
 create mode 100644 CMakeModules/FindOpenCASCADE.cmake

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 967927fb5..65085aff3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -70,9 +70,13 @@ option( KICAD_SCRIPTING_ACTION_MENU
     )
 
 option( KICAD_USE_OCE
-    "Build tools and plugins related to OpenCascade Community Edition (default OFF)"
+    "Build tools and plugins related to OpenCascade Community Edition (default ON)"
     ON )
 
+option( KICAD_USE_OCC
+    "Build tools and plugins related to OpenCascade Technology (overrides KICAD_USE_OCE, default OFF)"
+    OFF )
+
 option( KICAD_INSTALL_DEMOS
     "Install kicad demos and examples (default ON)"
     ON )
@@ -321,6 +325,11 @@ if( KICAD_USE_OCE )
     add_definitions( -DKICAD_USE_OCE )
 endif()
 
+if( KICAD_USE_OCC )
+    add_definitions( -DKICAD_USE_OCC )
+    remove_definitions( -DKICAD_USE_OCE )
+endif()
+
 if( KICAD_USE_CUSTOM_PADS )
     add_definitions( -DKICAD_USE_CUSTOM_PADS )
 endif()
@@ -558,10 +567,20 @@ if( KICAD_SPICE )
 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} )
+if( KICAD_USE_OCE OR KICAD_USE_OCC )
+    find_package(OpenCASCADE)
+    if( NOT OCC_FOUND )
+        MESSAGE( FATAL_ERROR "================================================================\n"
+                             "Neither OpenCASCADE Community Edition nor OpenCASCADE was found!\n"
+                             "================================================================\n")
+    endif()
+    if( OCC_VERSION_STRING VERSION_LESS 6.8.0 )
+        MESSAGE( FATAL_ERROR "================================================================\n"
+                             "OpenCASCADE version ${OCC_VERSION_STRING} was found.\n"
+                             "  KiCad requires a minimum version of 6.8.0\n"
+                             "================================================================\n")
+    endif()
+    include_directories( SYSTEM ${OCC_INCLUDE_DIR} )
 endif()
 
 # Assist with header file searching optimization:
diff --git a/CMakeModules/FindOpenCASCADE.cmake b/CMakeModules/FindOpenCASCADE.cmake
new file mode 100644
index 000000000..19055ea55
--- /dev/null
+++ b/CMakeModules/FindOpenCASCADE.cmake
@@ -0,0 +1,169 @@
+# 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
+
+############################################################################
+#
+# Modifications Copyright (C) 2018 Seth Hillbrand
+#
+# Based on FindOpenCasCade.cmake by the FreeCAD CAx 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 AND NOT KICAD_USE_OCC)
+  set(OCC_TYPE "OpenCASCADE Community Edition")
+  set(OCC_INCLUDE_DIR ${OCE_INCLUDE_DIRS})
+  FIND_LIBRARY(OCC_LIBRARY TKernel
+    HINTS
+    ${OCC_LIBRARY_DIR}
+    /usr
+    /usr/local
+    PATH_SUFFIXES lib 
+  )
+else(OCE_FOUND AND NOT KICAD_USE_OCC) #look for OpenCASCADE
+  set(OCC_TYPE "OpenCASCADE Standard Edition")
+  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
+        HINTS
+        ${OCC_LIBRARY_DIR}
+        /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
+      HINTS
+      ${OCC_LIBRARY_DIR}
+      /usr
+      /usr/local
+      /opt/opencascade
+      /opt/opencascade/lin64/gcc
+      PATH_SUFFIXES lib 
+    )
+  endif(WIN32)
+endif(OCE_FOUND AND NOT KICAD_USE_OCC)
+
+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)
+
+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)
+  foreach(lib IN ITEMS
+    TKMesh
+    TKernel
+    TKG2d
+    TKG3d
+    TKMath
+    TKIGES
+    TKSTL
+    TKXSBase
+    TKBin
+    TKBO
+    TKCDF
+    TKBRep
+    TKTopAlgo
+    TKGeomAlgo
+    TKGeomBase
+    TKPrim
+    TKSTEP
+    TKSTEPBase
+    TKSTEPAttr
+    TKFeat
+    TKCAF
+    TKXCAF
+    TKLCAF
+    TKXDESTEP
+    TKXDEIGES
+  )
+
+#Use the specified library location if given
+    find_library(OCC_TEMP_LIB ${lib} PATHS ${OCC_LIBRARY_DIR} NO_DEFAULT_PATH)
+    list(APPEND OCC_LIBRARIES ${OCC_TEMP_LIB})
+    unset(OCC_TEMP_LIB CACHE)
+  endforeach(lib)
+
+  #Convert path names to absolute for cleaner display
+  get_filename_component(OCC_INCLUDE_DIR "${OCC_INCLUDE_DIR}" ABSOLUTE)
+  get_filename_component(OCC_LIBRARY_DIR "${OCC_LIBRARY_DIR}" ABSOLUTE)
+  message(STATUS "Found ${OCC_TYPE} version: ${OCC_VERSION_STRING}")
+  message(STATUS " ++ ${OCC_TYPE} include directory: ${OCC_INCLUDE_DIR}")
+  message(STATUS " ++ ${OCC_TYPE} shared libraries directory: ${OCC_LIBRARY_DIR}")
+endif(OCC_FOUND)
diff --git a/common/dialog_about/dialog_about.cpp b/common/dialog_about/dialog_about.cpp
index 3ab6e8875..00f4b9e55 100644
--- a/common/dialog_about/dialog_about.cpp
+++ b/common/dialog_about/dialog_about.cpp
@@ -35,6 +35,9 @@
 extern std::string GetKicadCurlVersion();
 extern std::string GetCurlLibVersion();
 #endif
+#if defined( KICAD_USE_OCC ) | defined( KICAD_USE_OCE )
+#include <Standard_Version.hxx>
+#endif
 
 #include <boost/version.hpp>
 #include <wx/clipbrd.h>
@@ -473,6 +476,14 @@ void DIALOG_ABOUT::buildVersionInfoData( wxString& aMsg, bool aFormatHtml )
                       << ( BOOST_VERSION / 100 % 1000 ) << wxT( "." )
                       << ( BOOST_VERSION % 100 ) << eol;
 
+#ifdef KICAD_USE_OCC
+    aMsg << indent4 << "OpenCASCADE Technology: " << OCC_VERSION_COMPLETE << eol;
+#endif
+
+#ifdef KICAD_USE_OCE
+    aMsg << indent4 << "OpenCASCADE Community Edition: " << OCC_VERSION_COMPLETE << eol;
+#endif
+
 #ifdef BUILD_GITHUB_PLUGIN
     aMsg << indent4 << "Curl: " << GetCurlLibVersion() << eol;
 #endif
@@ -557,6 +568,13 @@ void DIALOG_ABOUT::buildVersionInfoData( wxString& aMsg, bool aFormatHtml )
     aMsg << OFF;
 #endif
 
+    aMsg << indent4 << "KICAD_USE_OCC=";
+#ifdef KICAD_USE_OCC
+    aMsg << ON;
+#else
+    aMsg << OFF;
+#endif
+
     aMsg << indent4 << "KICAD_SPICE=";
 #ifdef KICAD_SPICE
     aMsg << ON;
diff --git a/plugins/3d/oce/CMakeLists.txt b/plugins/3d/oce/CMakeLists.txt
index 6c6163118..1c6df742d 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} ${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..53186213a 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} )
 
 if( APPLE )
     # puts binaries into the *.app bundle while linking
-- 
2.11.0


Follow ups

References