Compile and install OpenCASCADE under Windows

OpenCASCADE (hereinafter referred to as OCC) is an open source geometric modeling system that provides modeling methods such as surfaces and solids, and has been widely used in CAD, CAE, CAM and other software development.

Although OpenCASCADE and other projects also provide compiled OpenCASCADE, the cmake Imported Libraries output by it often target specific paths. For example, in OpenCASCADEFoundationClassesTargets.cmake, set the TBB path referenced by TKernel and TKMath to "C:/occt-3rdparty/Windows-64-VC14/tbb44_20160526oss/lib/intel64/vc14/tbb.lib".

# Create imported target TKernel
add_library(TKernel SHARED IMPORTED)

set_target_properties(TKernel PROPERTIES
  INTERFACE_LINK_LIBRARIES "advapi32.lib;gdi32.lib;user32.lib;C:/occt-3rdparty/Windows-64-VC14/tbb44_20160526oss/lib/intel64/vc14/tbb.lib;C:/occt-3rdparty/Windows-64-VC14/tbb44_20160526oss/lib/intel64/vc14/tbbmalloc.lib;wsock32.lib;psapi.lib"
)

# Create imported target TKMath
add_library(TKMath SHARED IMPORTED)

set_target_properties(TKMath PROPERTIES
  INTERFACE_LINK_LIBRARIES "TKernel;C:/occt-3rdparty/Windows-64-VC14/tbb44_20160526oss/lib/intel64/vc14/tbb.lib;C:/occt-3rdparty/Windows-64-VC14/tbb44_20160526oss/lib/intel64/vc14/tbbmalloc.lib"
)

Moreover, the versions of VTK, Qt and other libraries in the official installation package provided by OpenCASCADE are relatively backward. Therefore, it is often necessary to recompile OpenCASCADE according to the local environment. This is the main reason for writing this article.

Ref. from OpenCASCADE Documentation

In most cases you would want to rebuild OCCT from sources on your platform (OS, compiler) before using it in your project, to ensure binary compatibility and appropriate configuration of the library. See Build, Debug and Upgrade for instructions on building OCCT from sources on supported platforms.

The OpenCASCADE official website has provided the compilation and installation method of OpenCASCADE. This article only combines the actual operation process to briefly describe its main points.

zero, environment

Operating system: Windows 10

Compiler: Visual Studio Community 2019

1. Obtain the OpenCASCADE code

There are several ways to obtain the OpenCASCADE source code:

  • OpenCASCADE official Git warehouse code

You need to sign the "Contrinutor License Agreement" to obtain the corresponding permissions, and then use git to download.

  • GitHub

GitHub has many OpeCASCADE Fork repositories.

git clone https://github.com/Open-Cascade-SAS/OCCT.git
cd ./OCCT/
git checkout -b OpenCASCADE-7.6.0 V7_6_0
  • OpenCASCADE installation package

The OpenCASCADE installation package also includes the OpenCASCADE source code, as well as compiled third-party libraries.

This article uses the OpenCASCADE source code in the "opencascade-7.6.0-vc14-64.exe" installation package.

2. Download the third-party library

3. Build the project

Set "3RDPARTY_DIR" to "D:\YouQuan\CaeFrameworks\OpenCASCADE\occt-3rdparty", build and generate the project.

Fourth, compile and install

Open the generated "OCCT.sln", build "ALL_BUILD" to complete the compilation; build "INSTALL" to complete the installation.

5. Frequently asked questions

Question : The "USE_VTK" option was enabled when building OpenCASCADE, and the VTK-related path was specified correctly.

 However, using find_package(OpenCASCADE) in my own project to reference OpenCASCADE reported an error, indicating that VTK::IOImage could not be found.

Answer : After the "USE_VTK" option is enabled, OpenCASCADEDrawTargets.cmake will reference VTK::IOImage, and VTK::IOImage can only be defined after referencing VTK. Therefore, you need to refer to VTK first, and then refer to OpenCASCADE.

# VTK
FIND_PACKAGE(VTK)

# occ
FIND_PACKAGE(OpenCASCADE)
ADD_DEFINITIONS(-DNO_COMMONSAMPLE_EXPORTS)

network information

OpenCASCADE Documentationhttps://dev.opencascade.org/doc/overview/html/index.html

Guess you like

Origin blog.csdn.net/qq_26221775/article/details/128794507