Windows下编译安装OpenCASCADE

OpenCASCADE (以下简称OCC)是一套开源的几何建模系统,提供了曲面、实体等建模方式,已经广泛应用在CAD、CAE、CAM等软件开发。

虽然OpenCASCADE及其他项目也提供了已经编译好的OpenCASCADE,但是其输出的cmake Imported Libraries往往针对特定的路径。比如,在OpenCASCADEFoundationClassesTargets.cmake中,设置了TKernel、TKMath所引用的TBB路径为“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"
)

而且OpenCASCADE官方提供的安装包内VTK、Qt等库版本较为落后,因此,很多时候需要自己依据本地环境重新编译OpenCASCADE,这是本文编写的主要原因。

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.

OpenCASCADE官网已经提供OpenCASCADE的编译安装方法,本文仅结合实操过程,简述其要点。

零、环境

操作系统:Windows 10

编译器:Visutal Studio Community 2019

一、获取OpenCASCADE代码

有多种方式可以获取OpenCASCADE源代码:

  • OpenCASCADE官方Git仓库代码

需要签署"Contrinutor License Agreement"以获取相应的权限,然后使用git下载即可。

  • GitHub

GitHub有不少OpeCASCADE Fork仓库。

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

OpenCASCADE安装包也包含了OpenCASCADE源代码,同时包含了已经编译好的第三方库。

本文使用“opencascade-7.6.0-vc14-64.exe”安装包内的OpenCASCADE源代码。

二、下载第三方库

三、构建项目

设置"3RDPARTY_DIR"为"D:\YouQuan\CaeFrameworks\OpenCASCADE\occt-3rdparty",构建生成项目。

四、编译安装

打开生成的"OCCT.sln",构建"ALL_BUILD"完成编译;构建"INSTALL"完成安装。

五、常见问题

:构建OpenCASCADE时开启了"USE_VTK"选项,并且正确指定了VTK相关路径,

 但是在自己的项目使用find_package(OpenCASCADE)引用OpenCASCADE报错,提示找不到VTK::IOImage。

:开启了"USE_VTK"选项之后,OpenCASCADEDrawTargets.cmake会引用VTK::IOImage,而VTK::IOImage只有在引用VTK之后参会定义,因此,需要先引用VTK,再引用OpenCASCADE。

# VTK
FIND_PACKAGE(VTK)

# occ
FIND_PACKAGE(OpenCASCADE)
ADD_DEFINITIONS(-DNO_COMMONSAMPLE_EXPORTS)

网络资料

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

猜你喜欢

转载自blog.csdn.net/qq_26221775/article/details/128794507