Skip to content

9and3/cmake4rhino

Repository files navigation

cmake4rhino

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!

Install Lgif


Supported Toolchains & Platforms:
OS Generator / Compiler Rhino SDK CMake
Windows Visual Studio 16 2019
Visual Studio 17 2022
Rhino 6
Rhino 7
Rhino 8
3.15+
CI status:
Name Build Status Branch Notes
Downloadable Template cookietemplate cookiecutter gh:9and3/cmake4rhino --checkout cookietemplate
CMake/VS17-2022/Rhino8SDK build Main ..

Quickstart

Download the template

You can download the template with the following command in a terminal:

pip install cookiecutter
cookiecutter gh:9and3/cmake4rhino --checkout cookietemplate

When asked, change the project name with your plug-in name.

Project information

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:

set(PLUGIN_COMPANY_NAME "Your Own Organization")
set(PLUGIN_NAME "cmake4rhino")
set(PLUGIN_ADDRESS "123 Developer Street City State 12345-6789")
set(PLUGIN_COUNTRY "My Country")
set(PLUGIN_PHONE "123-456-7890")
set(PLUGIN_FAX "123-456-7891")
set(PLUGIN_EMAIL "support@mycompany.com")
set(PLUGIN_WEBSITE "https://www.mycompany.com")
set(PLUGIN_UPDATE_URL "https://www.mycompany.com/update")
set(PLUGIN_LEGAL_COPYRIGHT "Copyright © 2025 Your Name or Company")
set(PLUGIN_FILE_DESCRIPTION "Rhino C++ Plugin in CMake for Custom Development")
set(PLUGIN_ID "5AC5581C-0559-492F-9E46-21574EE7F52B")

Logo

The logo should be replaced in the res/ folder with your own (remember 256-pixel square .ico file).

Compile

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 Debug

or release:

cmake -S . -B build -G "Visual Studio 17 2022" -A x64 -DRUN_POSTBUILD_RHINO=OFF; cmake --build build --config Release

Important 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.

Testing

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.

How it works

diagramw The cmake project compilation is split in 3 parts:
  • PLUGIN_CORE: your external library
  • PLUGIN_RHP: the Rhino plugin itself
  • PLUGIN_TEST: where your tests live
Basically, Rhino is linked two times with different flags based on the .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

Contributions to the project are welcome! If you have suggestions, improvements, or bug fixes, please submit a pull request or open an issue.

About

A CMake template for Rhino C++ plug-in development.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Contributors