Windows下编译CGMA

本文记录在Windows下编译CGMA的流程。

一、环境

|-------|---------------------------------------------------|
| 操作系统 | Windows 10/11,x64 |
| CMake | 3.20 或更高版本。CMakeUserPresets.json 的最低版本要求为 3.20。 |

二、依赖

|------------------------|---------------------------------------------------------------------------------------------|
| MinGW-w64: | 需要 g++、gcc 和 mingw32-make |
| Visual Studio 2022 | 安装"使用 C++ 的桌面开发"和 x64 工具集。vs2022 preset 使用 Visual Studio 17 2022、host=x64 和 x64 架构。 |
| VS Code | CMake Tools,C/C++ |

默认配置可以不依赖外部 CAD 几何内核,构建 Facet 和 Virtual 后端:

选项 默认值 说明
BUILD_SHARED_LIBS ON 生成 DLL 和导入库
CGM_FACET ON Facet 几何后端
CGM_VIRTUAL ON Virtual 几何后端
CGM_OCC OFF OpenCascade 后端
CGM_ACIS OFF ACIS 后端
CGM_KCM preset 中为 OFF KCM 能力

基础构建不需要 OpenCascade 或 ACIS。启用 CGM_OCC=ON 时,需要预先安装与当前编译器和架构匹配的 OpenCascade/OCE,并通过 OCE_DIR 或 CMAKE_PREFIX_PATH 让 CMake 找到 OCEConfig.cmake。启用 CGM_ACIS=ON 时,还需要可用的 ACIS SDK;SDK 不包含在本仓库中。

三、编译

2.1 下载

bash 复制代码
git clone https://github.com/vibraphone/cgma.git
cd ./cgma/
git checkout -b cmake origin/camke

2.2 编译

新建CMakeUserPresets.json,并添加以下内容,

复制代码
{
    "version": 9,
    "cmakeMinimumRequired": {
        "major": 3,
        "minor": 20,
        "patch": 0
    },
    "configurePresets": [
        {
            "name": "default",
            "hidden": true,
            "displayName": "Default Config",
            "description": "Default build configuration",
            "binaryDir": "${sourceDir}/out/build/${presetName}",
            "cacheVariables": {
                "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
                "CMAKE_BUILD_TYPE": "Debug",
                "CGM_KCM": "OFF"
            }
        },
        {
            "name": "vs2022",
            "hidden": true,
            "inherits": "default",
            "displayName": "Visual Studio 17 2022",
            "description": "This build is using Visual Studio 17 2022 generator",
            "generator": "Visual Studio 17 2022",
            "toolset": "host=x64",
            "architecture": "x64",
            "cacheVariables": {},
            "environment": {
                "VCPKG_ROOT": "D:/vcpkg",
                "HTTP_PROXY": "http://192.168.1.106:7890",
                "HTTPS_PROXY": "http://192.168.1.106:7890",
                "VCPKG_DEFAULT_BINARY_CACHE": "$env{VCPKG_ROOT}/binary-cache",
                "VCPKG_BINARY_SOURCES": "clear;files,$env{VCPKG_ROOT}/binary-cache,readwrite",
                "X_VCPKG_ASSET_SOURCES": "clear;x-azurl,file://$env{VCPKG_ROOT}/asset-cache,,readwrite"
            },
            "condition": {
                "type": "equals",
                "lhs": "${hostSystemName}",
                "rhs": "Windows"
            }
        },
        {
            "name": "vs2022-debug",
            "hidden": false,
            "inherits": "vs2022",
            "displayName": "Visual Studio 17 2022 Debug",
            "description": "Debug-only build for development and source-level debugging",
            "cacheVariables": {
                "CMAKE_CONFIGURATION_TYPES": "Debug"
            }
        },
        {
            "name": "vs2022-release",
            "hidden": false,
            "inherits": "vs2022",
            "displayName": "Visual Studio 17 2022 Release",
            "description": "Release-only build for shipped binaries",
            "cacheVariables": {
                "CMAKE_CONFIGURATION_TYPES": "Release"
            }
        },
        {
            "name": "mingw64",
            "hidden": true,
            "inherits": "default",
            "displayName": "MinGW-w64",
            "description": "This build is using MinGW generator",
            "generator": "MinGW Makefiles",
            "cacheVariables": {},
            "environment": {}
        },
        {
            "name": "mingw64-debug",
            "hidden": false,
            "inherits": "mingw64",
            "displayName": "MinGW-w64 Debug",
            "description": "Debug-only build for development and source-level debugging",
            "cacheVariables": {
                "CMAKE_BUILD_TYPE": "Debug"
            }
        },
        {
            "name": "mingw64-release",
            "hidden": false,
            "inherits": "mingw64",
            "displayName": "MinGW-w64 Release",
            "description": "Release-only build for shipped binaries",
            "cacheVariables": {
                "CMAKE_BUILD_TYPE": "Release"
            }
        },
        {
            "name": "cygwin64",
            "hidden": false,
            "inherits": "default",
            "displayName": "Cygwin64",
            "description": "This build is using Unix Makefiles generator",
            "generator": "Unix Makefiles",
            "cacheVariables": {
                "SALOME_BUILD_TESTS": "OFF",
                "WRAP_PYTHON": "OFF"
            },
            "environment": {}
        },
        {
            "name": "linux_gcc",
            "hidden": true,
            "inherits": "default",
            "displayName": "Linux GCC",
            "description": "Default build using Unix Makefiles generator",
            "generator": "Unix Makefiles",
            "cacheVariables": {
                "CMAKE_C_COMPILER": "/usr/bin/gcc",
                "CMAKE_CXX_COMPILER": "/usr/bin/g++",
                "CMAKE_MAKE_PROGRAM": "/usr/bin/make",
                "CMAKE_INSTALL_PREFIX": "${sourceParentDir}/../artifacts/${presetName}",
                "CMAKE_BUILD_TYPE": "Debug"
            },
            "environment": {
                "VCPKG_ROOT": "$env{HOME}/vcpkg",
                "HTTP_PROXY": "http://192.168.1.106:7890",
                "HTTPS_PROXY": "http://192.168.1.106:7890",
                "VCPKG_DEFAULT_BINARY_CACHE": "$env{VCPKG_ROOT}/binary-cache",
                "VCPKG_BINARY_SOURCES": "clear;files,$env{VCPKG_ROOT}/binary-cache,readwrite",
                "X_VCPKG_ASSET_SOURCES": "clear;x-azurl,file://$env{VCPKG_ROOT}/asset-cache,,readwrite"
            }
        },
        {
            "name": "linux_gcc-debug",
            "hidden": false,
            "inherits": "linux_gcc",
            "displayName": "Linux GCC Debug",
            "description": "Debug-only build for development and source-level debugging",
            "cacheVariables": {
                "CMAKE_BUILD_TYPE": "Debug"
            }
        },
        {
            "name": "linux_gcc-release",
            "hidden": false,
            "inherits": "linux_gcc",
            "displayName": "Linux GCC Release",
            "description": "Release-only build for shipped binaries",
            "cacheVariables": {
                "CMAKE_BUILD_TYPE": "Release"
            }
        }
    ],
    "buildPresets": [
        {
            "name": "default",
            "hidden": true,
            "configurePreset": "default"
        },
        {
            "name": "vs2022-debug",
            "hidden": false,
            "inherits": "default",
            "displayName": "Visual Studio 17 2022 Debug",
            "configurePreset": "vs2022-debug",
            "configuration": "Debug"
        },
        {
            "name": "vs2022-release",
            "hidden": false,
            "inherits": "default",
            "displayName": "Visual Studio 17 2022 Release",
            "configurePreset": "vs2022-release",
            "configuration": "Release"
        },
        {
            "name": "mingw64-debug",
            "hidden": false,
            "inherits": "default",
            "displayName": "MinGW-w64 Debug",
            "configurePreset": "mingw64-debug"
        },
        {
            "name": "mingw64-release",
            "hidden": false,
            "inherits": "default",
            "displayName": "MinGW-w64 Release",
            "configurePreset": "mingw64-release"
        },
        {
            "name": "cygwin64",
            "hidden": false,
            "inherits": "default",
            "displayName": "Cygwinw64",
            "configurePreset": "cygwin64"
        },
        {
            "name": "linux_gcc-debug",
            "hidden": false,
            "inherits": "default",
            "displayName": "Linux GCC Debug",
            "configurePreset": "linux_gcc-debug"
        },
        {
            "name": "linux_gcc-release",
            "hidden": false,
            "inherits": "default",
            "displayName": "Linux GCC Release",
            "configurePreset": "linux_gcc-release"
        }
    ],
    "testPresets": [
        {
            "name": "default",
            "hidden": true,
            "configurePreset": "default",
            "output": {
                "outputOnFailure": true
            },
            "execution": {
                "noTestsAction": "error",
                "stopOnFailure": true
            }
        },
        {
            "name": "vs2022-debug",
            "hidden": false,
            "inherits": "default",
            "displayName": "Visual Studio 17 2022 Debug",
            "configurePreset": "vs2022-debug"
        },
        {
            "name": "vs2022-release",
            "hidden": false,
            "inherits": "default",
            "displayName": "Visual Studio 17 2022 Release",
            "configurePreset": "vs2022-release"
        },
        {
            "name": "mingw64-debug",
            "hidden": false,
            "inherits": "default",
            "displayName": "MinGW-w64 Debug",
            "configurePreset": "mingw64-debug"
        },
        {
            "name": "mingw64-release",
            "hidden": false,
            "inherits": "default",
            "displayName": "MinGW-w64 Release",
            "configurePreset": "mingw64-release"
        },
        {
            "name": "cygwin64",
            "hidden": true,
            "inherits": "default",
            "displayName": "Cygwin64",
            "configurePreset": "cygwin64"
        },
        {
            "name": "linux_gcc-debug",
            "hidden": false,
            "inherits": "default",
            "displayName": "Linux GCC Debug",
            "configurePreset": "linux_gcc-debug"
        },
        {
            "name": "linux_gcc-release",
            "hidden": false,
            "inherits": "default",
            "displayName": "Linux GCC Release",
            "configurePreset": "linux_gcc-release"
        }
    ],
    "packagePresets": [
        {
            "name": "default",
            "hidden": true,
            "configurePreset": "default",
            "generators": [
                "TGZ"
            ]
        },
        {
            "name": "vs2022-debug",
            "hidden": false,
            "inherits": "default",
            "displayName": "Visual Studio 17 2022 Debug",
            "configurePreset": "vs2022-debug",
            "generators": [
                "TGZ"
            ]
        },
        {
            "name": "vs2022-release",
            "hidden": false,
            "inherits": "default",
            "displayName": "Visual Studio 17 2022 Release",
            "configurePreset": "vs2022-release",
            "generators": [
                "TGZ"
            ]
        },
        {
            "name": "mingw64-debug",
            "hidden": false,
            "inherits": "default",
            "displayName": "MinGW-w64 Debug",
            "configurePreset": "mingw64-debug",
            "generators": [
                "TGZ"
            ]
        },
        {
            "name": "mingw64-release",
            "hidden": false,
            "inherits": "default",
            "displayName": "MinGW-w64 Release",
            "configurePreset": "mingw64-release",
            "generators": [
                "TGZ"
            ]
        },
        {
            "name": "linux_gcc-debug",
            "hidden": false,
            "inherits": "default",
            "displayName": "Linux GCC Debug",
            "configurePreset": "linux_gcc-debug",
            "generators": [
                "RPM"
            ]
        },
        {
            "name": "linux_gcc-release",
            "hidden": false,
            "inherits": "default",
            "displayName": "Linux GCC Release",
            "configurePreset": "linux_gcc-release",
            "generators": [
                "RPM"
            ]
        }
    ],
    "workflowPresets": [
        {
            "name": "default",
            "steps": [
                {
                    "type": "configure",
                    "name": "default"
                },
                {
                    "type": "build",
                    "name": "default"
                },
                {
                    "type": "test",
                    "name": "default"
                },
                {
                    "type": "package",
                    "name": "default"
                }
            ]
        },
        {
            "name": "vs2022-debug",
            "displayName": "Visual Studio 17 2022 Debug",
            "steps": [
                {
                    "type": "configure",
                    "name": "vs2022-debug"
                },
                {
                    "type": "build",
                    "name": "vs2022-debug"
                },
                {
                    "type": "test",
                    "name": "vs2022-debug"
                },
                {
                    "type": "package",
                    "name": "vs2022-debug"
                }
            ]
        },
        {
            "name": "vs2022-release",
            "displayName": "Visual Studio 17 2022 Release",
            "steps": [
                {
                    "type": "configure",
                    "name": "vs2022-release"
                },
                {
                    "type": "build",
                    "name": "vs2022-release"
                },
                {
                    "type": "test",
                    "name": "vs2022-release"
                },
                {
                    "type": "package",
                    "name": "vs2022-release"
                }
            ]
        },
        {
            "name": "mingw64-debug",
            "displayName": "MinGW-w64 Debug",
            "steps": [
                {
                    "type": "configure",
                    "name": "mingw64-debug"
                },
                {
                    "type": "build",
                    "name": "mingw64-debug"
                },
                {
                    "type": "test",
                    "name": "mingw64-debug"
                },
                {
                    "type": "package",
                    "name": "mingw64-debug"
                }
            ]
        },
        {
            "name": "mingw64-release",
            "displayName": "MinGW-w64 Release",
            "steps": [
                {
                    "type": "configure",
                    "name": "mingw64-release"
                },
                {
                    "type": "build",
                    "name": "mingw64-release"
                },
                {
                    "type": "test",
                    "name": "mingw64-release"
                },
                {
                    "type": "package",
                    "name": "mingw64-release"
                }
            ]
        },
        {
            "name": "linux_gcc-debug",
            "displayName": "Linux GCC Debug",
            "steps": [
                {
                    "type": "configure",
                    "name": "linux_gcc-debug"
                },
                {
                    "type": "build",
                    "name": "linux_gcc-debug"
                },
                {
                    "type": "test",
                    "name": "linux_gcc-debug"
                },
                {
                    "type": "package",
                    "name": "linux_gcc-debug"
                }
            ]
        },
        {
            "name": "linux_gcc-release",
            "displayName": "Linux GCC Release",
            "steps": [
                {
                    "type": "configure",
                    "name": "linux_gcc-release"
                },
                {
                    "type": "build",
                    "name": "linux_gcc-release"
                },
                {
                    "type": "test",
                    "name": "linux_gcc-release"
                },
                {
                    "type": "package",
                    "name": "linux_gcc-release"
                }
            ]
        }
    ]
}

四、常见问题

4.1 找不到编译器或 Make

确认 D:/msys64/mingw64/bin 已加入 PATH,并检查:

复制代码
Get-Command cmake, gcc, g++, mingw32-make

如果使用 VS2022,请改用 VS2022 开发者 PowerShell,并选择 vs2022-debug preset。

4.2 64 位 MinGW 报指针转换错误

例如:

复制代码
cast from 'const char* const*' to 'long int' loses precision

这是旧代码把 64 位指针转换为 long 导致的。使用当前仓库中的修复,并删除旧构建目录后重新执行 cmake --preset mingw64-debug。

4.3 type_info does not name a type

这是旧头文件在 Windows/MinGW 下没有引入 std::type_info 别名导致的。使用当前仓库版本,并重新配置构建目录。

4.4 cgma_init 链接时出现大量 undefined reference

Facet、Virtual、Cholla 和 Geom 库存在循环依赖。当前 CMake 已在 GNU/Clang 链接器上使用 LINK_GROUP:RESCAN 处理这组库。若构建目录来自旧配置,先清理后重新配置:

复制代码
Remove-Item -Recurse -Force out/build/mingw64-debug
cmake --preset mingw64-debug
cmake --build --preset mingw64-debug --parallel 2

4.5 OpenCascade 未找到

基础 Facet/Virtual 构建不需要 OCC。若确实需要 OCC,确认 OCEConfig.cmake 存在,并在配置时指定路径,例如:

复制代码
cmake --preset mingw64-debug -DOCE_DIR="D:/path/to/oce/lib/cmake/OCE"

也可以将 OCE 安装前缀放入 CMAKE_PREFIX_PATH。OCC 库必须与当前编译器和 x64 架构匹配。

参考资料

CUBIT

CGM

GitHub: CGMA

相关推荐
水饺编程1 小时前
第2章:Linux 基础,在 root 中创建用户账号
linux·c语言·汇编·1024程序员节
AMASENSYS艾马斯2 小时前
变频器过载能力参数解读与工程应用
驱动开发·嵌入式硬件·其他·硬件工程·精益工程
梯度下降者2 小时前
全栈 JS 性能监控:在生产环境实现长任务(Long Task)的采集与上报
用户体验·性能监控·1024程序员节·rum·长任务·全栈js
Soonyang Zhang4 小时前
aisimulate分析(一)——算子workload建模
仿真·1024程序员节·vllm·推理框架·sglang
jimy14 小时前
lvalue、xvalue、prvalue(二):引用是哪一类?
开发语言·c++·1024程序员节
贾伟康5 小时前
【健康菜谱助手|04】HarmonyOS ArkTS 一周膳食计划实战:管理日期、餐次与菜谱替换的联动
软件测试·移动开发·harmonyos·arkts·arkui·1024程序员节
AI浩5 小时前
Xiaomi-Lens-0 技术报告
人工智能·计算机视觉·1024程序员节
2601_967980116 小时前
Python之wxPython模块的安装
linux·windows·python·wxpython·gui设计·1024程序员节
minglie17 小时前
电枢的主题和概念
学习·1024程序员节