This is a CMake template for Rhino plugins, to quickly set up a new C++ project.
The template is distributed as a cookiecutter template, which can be used to generate a new project with the desired name and settings. Have fun cmakers!
| OS | Generator / Compiler | Rhino SDK | CMake |
|---|---|---|---|
|
|
Visual Studio 16 2019 Visual Studio 17 2022 |
Rhino 6 Rhino 7 Rhino 8 |
3.15+ |
| Name | Build Status | Branch | Notes |
|---|---|---|---|
| Downloadable Template |
|
cookietemplate |
cookiecutter gh:9and3/cmake4rhino --checkout cookietemplate
|
| CMake/VS17-2022/Rhino8SDK build |
|
Main |
..
|
You can download the template with the following command in a terminal:
pip install cookiecutter
cookiecutter gh:9and3/cmake4rhino --checkout cookietemplateWhen asked, change the project name with your plug-in name.
The remaining information to change can be found in the CMakeLists.txt file to be filled with your project information, such as the name, version, author, etc:
Lines 20 to 31 in 5d0722a
The logo should be replaced in the res/ folder with your own (remember 256-pixel square .ico file).
Check-in your folder:
cd <your-genereated-project-folder>For debug build:
cmake -S . -B build -G "Visual Studio 17 2022" -A x64 -DRUN_POSTBUILD_RHINO=OFF; cmake --build build --config Debugor release:
cmake -S . -B build -G "Visual Studio 17 2022" -A x64 -DRUN_POSTBUILD_RHINO=OFF; cmake --build build --config ReleaseImportant flags:
-DMFC_ROOT=<path_to_mfc>: Path to the MFC library, if not set it will try to find it in the default location.-DRHINOSDK_ROOT=<path_to_rhino8_sdk>: Path to the Rhino 8 SDK, if not set it will try to find it in the default location.-DRHINO_EXE_PATH=<path_to_rhino_exe>: Path to the Rhino executable, if not set it will try to find it in the default location.-DRUN_POSTBUILD_RHINO=ON: Enable to automatically open RHino and install the plugin after building.
Important
Be sure to install by drag-and-drop the build/Release/YourPlugin.rhp file into the Rhino window before to run the tests. After this, the tests, if enabled, will work every time.
Googletest framework is used, tests can be enabled with -DBUILD_TESTS=ON (default: off).
You can write either unit tests or test your commands:
TEST_F(RhinoDocTest, MyIntegrationTest) {
// macro
const wchar_t* cmdName =
L"!_cmake4rhino "
L"\"test\" "
L"_Enter";
// run the command
bool resCmd = pDoc->RunScript(cmdName);
// get the objects added to the document
ON_SimpleArray<ON_UUID> objectIDs = GetObjectIDs();
ASSERT_TRUE(resCmd) << "Command execution failed";
ASSERT_EQ(objectIDs.Count(), 2) << "No sphere and curve found in the document";
}You can run your command as a macro and read and evaluate the generated geometries as in the example.
Warning
Note that it's not possible to test UI but only command interface and geometries.
|
The cmake project compilation is split in 3 parts:
.rhp compilation or the test part which is a console exec. For this last one we also add the Rhino.Inside.Cpp ([here](https://github.com/mcneel/rhino-developer-samples/blob/8/rhino.inside/cpp/Main.cpp#L7)) headers which allows to run headless instances of Rhino.
|
Contributions to the project are welcome! If you have suggestions, improvements, or bug fixes, please submit a pull request or open an issue.

