HDK
|
The easiest way to compile HDK sample code or your own custom HDK code is to use the hcustom command-line tool. In order to use hcustom, you need csh
. On newer Linux platforms (i.e. Ubuntu), you need to install csh
manually using your package manager since it is not shipped by default.
Once csh
is installed, you can try compiling the SOP Star sample (see SOP/SOP_Star/SOP_Star.C) using hcustom. Open a command shell and run:
hcustom will produce a corresponding object file, SOP_Star.o, and a plugin library, SOP_Star.so, in the current working directory. The library file is automatically installed into $HOME/houdiniX.Y/dso as well. This is where Houdini is able to locate and load your custom plugins.
So if you open Houdini and create a Geometry object, you can dive into the geometry and press TAB->SOP Star
and your Star surface operator will appear.
/bin/csh
) installed on your system.To compile HDK code on Windows using MSVC, open the Windows START menu and choose Side Effects Software -> Houdini X.Y.ZZZ -> Command-line Tools
from your program list. This will launch a command shell with the Houdini environment initialized. hcustom will autodetect your Microsoft Visual C++ distribution. You can confirm that it's correct by running hcustom --output_msvcdir . To manually override this, set the MSVCDir environment variable to point to the Microsoft Visual C++ distribution. Note that this directory should have the subdirectories bin
, include
, and lib
.
Here is an example:
Other than using hcustom, one can build using GNU Make or Visual Studio's nmake, see the Compiling with Makefiles section.
If you wish to build from the Visual Studio IDE, then it's suggested that you use CMake instead, see the Compiling with CMake section.
For other build systems, you need to use the same compiler settings as hcustom. To see what they are, you can run "hcustom --cflags" for the compiler options, and "hcustom --ldflags" for the linker options.
Though hcustom is convenient and easy-to-use, it is not suitable for compiling mid-size and large HDK projects. For one reason, hcustom can only compile a single C++ source file into a plugin library. If your HDK plugin is built from several source files, then it is recommended that the Makefiles from $HFS/toolkit/makefiles be used to manage your compilations.
There are two Makefiles to choose from depending on the make tool that you are using:
make
toolNMAKE
toolThere are also OS-specific Makefiles (i.e. Makefile.osx, Makefile.linux, Makefile.win) which contain platform-specific definitions. These files are referenced by the Makefiles listed above and should never be used directly.
To compile your source files, first create a new Makefile. In your Makefile, you need to define a few variables to setup the compile and link targets. Here is a list of the variables that you can set:
Variable Name | Description |
APPNAME (required) | The filename for your standalone application. If you are building a plugin library, then set DSONAME instead of APPNAME. |
DSONAME (required) | The filename for your plugin library. For the SOP Flatten example, this would be SOP_Flatten.so on Linux and SOP_Flatten.dll on Windows. If you are building a standalone application, then set APPNAME instead of DSONAME. |
INCDIRS | A space-separated list of additional include directories that are searched at compile-time. Each entry in the list should be in the form -I/path/to/include/dir . |
ICONS | Name of the icon files to install. This only applies if you are building a plugin with custom node operators. |
INSTDIR | Directory to install your standalone application or plugin library (and support files). If not specified, then this will default to $HOME/houdiniX.Y. |
LIBDIRS | A space-separated list of additional library directories that are searched at link-time. Each entry in the list should be in the form -L/path/to/lib/dir on Linux and -LIBPATH :C:/path/to/lib/dir on Windows. |
LIBS | A space-separated list of additional libraries to link to at link-time. For shared libraries, use -lmyLibrary on Linux and myLibrary.lib on Windows. For static libraries, use /path/to/lib/myLibrary .a on Linux and myLibrary.lib on Windows. |
OPTIMIZER | The optimization flag. If not specified, then OPTIMIZER is set to -O2 by default on Linux and -Ox on Windows. |
SOURCES (required) | A space-separated list of C++ source files that are to be compiled into the plugin library or application. The source files must have a .C extension. |
After defining the compile and link variables, include one of Makefile.gnu or Makefile.nmake into your Makefile.
Once you have a Makefile created, you can invoke make with various targets.
Target Name | Description |
all | Default target that just builds and links the sources. |
clean | Removes files created by the all target. |
install | This invokes the all and icons targets, and then installs into the value specified by the INSTDIR variable. |
icons | Installs the icons specified by the ICONS variable. |
Below is a simple example Makefile that compiles the SOP_Flatten.C HDK sample.
Below is an example of a custom Makefile on Linux which builds several HDK SOP operators into a single plugin library named StudioSOPs.so:
Now to build your plugin library, go to the directory containing your Makefile and type:
make
or nmake
.CMake is a meta-build system that can generate project files for various build systems and IDE's (such as Make, Visual Studio, and Ninja). This documentation describes how to build HDK code with CMake. CMake's documentation should be referenced for anything that is not Houdini-specific.
A CMake configuration file (HoudiniConfig.cmake
) is provided in $HFS/toolkit/cmake
, which defines an imported library target named Houdini
.
For a simple library, an example CMakeLists.txt would be:
In order for find_package(Houdini)
to succeed, the toolkit/cmake
subdirectory of the Houdini installation you are building against must be in CMAKE_PREFIX_PATH.
There are several ways to specify this path when running CMake:
-DCMAKE_PREFIX_PATH=/path/to/hfs/toolkit/cmake
.Add Entry
button to set a string cache entry for the value of CMAKE_PREFIX_PATH
.CMAKE_PREFIX_PATH
environment variable before running CMake.CMAKE_PREFIX_PATH
can also be extended in CMakeLists.txt
, before the find_package()
call. This can be useful if you require custom logic for determining the path to the Houdini installation (such as inspecting environment variables):
First, create a separate directory that will contain all generated files (such as the generated build system, object files, etc). One convention is to create a subdirectory named build
in the folder containing the root CMakeLists.txt
From the build directory, run cmake
and provide the path to the source directory as an argument. If you followed the above steps, the source directory will be the parent directory.
After running CMake, you are then able to use the generated build system files to compile your code.
Unix Makefiles
or Ninja
generators, simply run make
or ninja
, respectively, in the build directory..sln
file for Visual Studio) will have been generated in the build directory.There are also many optional arguments that can be provided to control CMake's behavior. Some common arguments are:
-G <generator>
Specifies which build system generator to use. If not specified, the default for your platform will be used (such as "Unix Makefiles" for Linux). Some common options are "Unix Makefiles", "Ninja", "Xcode", and "Visual Studio 14 2017 Win64". Running cmake –help
will provide a full list of the supported generators for your system.
-DCMAKE_BUILD_TYPE=<build_type>
Specifies the build type (such as "Debug", "Release", or "RelWithDebInfo") for single-configuration generators such as Make or Ninja. For IDEs such as Visual Studio, the IDE settings can be used to select the desired build type.
See CMake's documentation for more information on running CMake.
The following variables are defined when Houdini is found:
Variable | Description |
Houdini_FOUND | Boolean indicating whether Houdini was found successfully. |
Houdini_VERSION | String containing the version of Houdini that is being built against. |
Houdini_VERSION_MAJOR | The major version component of ${Houdini_VERSION} . For version 16.5.123, this is 16. |
Houdini_VERSION_MINOR | The minor version component of ${Houdini_VERSION} . For version 16.5.123, this is 5. |
Houdini_VERSION_PATCH | The build version component of ${Houdini_VERSION} . For version 16.5.123, this is 123. |
The following functions are available when Houdini is found:
houdini_configure_target( target_name [INSTDIR dir] [TAGINFO str] [LIB_PREFIX prefix] )
Configures several common properties of the specified target:
INSTDIR
: Specifies a custom output directory for the library or executable.LIB_PREFIX
: Specifies a prefix for the library name. The default behavior is to use an empty prefix (e.g. SOP_Star.so
instead of libSOP_Star.so
).TAGINFO
: Additional information to embed in the DSO (for use with sesitag).houdini_get_default_install_dir( <VAR> )
Returns the default installation directory for the platform (for example, $HOME/houdiniX.Y
). This can be used for installing additional files such as documentation and HDAs.
houdini_generate_proto_headers( OUTPUT_VAR generated_headers FILES file ... )
Performs code generation for source files that specify their parameter interface with an embedded DS file.
Houdini is built with special custom allocator libraries that override the default allocation routines (eg. malloc, free, etc.). As such any code you build or link into HDK plugins cannot use their own such libraries such as tbbmalloc_proxy. If you do, then conflicts and crashes can occur as a result.