Skip to content

Including the library in your project

Auburn edited this page Jun 24, 2024 · 12 revisions

CMake

In source tree

If you are including FastNoise2 in your repo either by direct source copy or git submodule you can do the following

In your CMakeLists.txt file you will need to include the sub directory where FastNoise2 is. The simplest way is to have a deps/dependencies directory where the source is located `deps/FastNoise2' is what I will assume here.

  1. Open your CMakeLists.txt
  2. Set whatever FastNoise options you would like using, i.e. set(FASTNOISE_OPTION ON/OFF CACHE BOOL "Description of option" FORCE)
  3. Add the sub directory with add_subdirectory(deps/FastNoise2).
  4. Link the FastNoise target to your target using target_link_libraries(your_project FastNoise)

For an executable it should look something like this

set(FASTNOISE2_NOISETOOL OFF CACHE BOOL "Build Noise Tool" FORCE) #example if don't need the graph tool
add_subdirectory(deps/FastNoise2)
...
add_executable(your_project ${source})
...
target_link_libraries(your_project PRIVATE FastNoise ...)

If you are adding it to a lib it should be pretty much the same. The only differences are swapping the add_executable for add_library and if you are building a static lib you have to make sure the FastNoise target is added as PUBLIC in target_link_libraries as shown below.

set(FASTNOISE2_NOISETOOL OFF CACHE BOOL "Build Noise Tool" FORCE) #example if don't need the graph tool
add_subdirectory(deps/FastNoise2)
...
add_library(your_project ${source})
...
target_link_libraries(your_project PUBLIC FastNoise ...)

Installed

If you have compiled and installed via CMake or downloaded the binaries from the latest release you can do the following. You will need to add the library location to the CMAKE_PREFIX_PATH in your CMakeList.txt

set(CMAKE_PREFIX_PATH lib_directory ${CMAKE_PREFIX_PATH})
...
find_package(FastNoise CONFIG REQUIRED) #use REQUIRED if the lib has to be found for the project to work
...
add_executable(your_project ${source})
...
target_link_libraries(your_project PRIVATE FastNoise ...)

again if you are building FastNoise into a static library (like noted above) use the PUBLIC attribute rather than PRIVATE for target_link_libraries.

UE4

Suggest using, https://github.com/caseymcc/UE4CMake

Visual Studio

You will need the compiled binaries to follow these steps, they can be downloaded from the Releases or compiled using CMake

These steps use the shared (dll) FastNoise2 binaries, if you are compiling using CMake use -D BUILD_SHARED_LIBS=ON to build as a dll

In this guide the FastNoise2 folder from the latest release has been placed next to project file (.vcxproj), you can do the same or adjust the file paths in the guide accordingly

Project Config

1: Right click on your project (not solution) and select Properties

image

2: Select the configuration Release, Debug, etc... You will have to make the changes in steps 3, 4 & 5 for each config.

image

3: Select C\C++ then General and use the dropdown arrow on the right side of Additional Include Directories to add the FastNoise2 include directory ./FastNoise2/include

image

4: Next select Linker then General and use the dropdown arrow on the right side of Additional Library Directories to add the FastNoise2 lib directory ./FastNoise2/lib

image

5: Still under Linker select Input and use the dropdown arrow on the right side of Additional Dependencies to add the FastNoise2 lib filename, FastNoise.lib for release configs and FastNoiseD.lib for debug configs.

image

Deploy the DLL

After following the previous steps you should be able to compile and link with the FastNoise2 library but trying to run the program will give you this error

image

To fix this we need to deploy the DLL with the program EXE. We can setup Visual Studio to do this automatically on build

1: Right click on a file filter (or the project) select Add and Existing Item... then navigate to the ./FastNoise2/bin folder and select FastNoise.dll and FastNoiseD.dll to add

image

2: Right click on the newly added dll file and select Properties (Repeat this and the remaining steps for both dll files)

image

3: Change the Item Type to Copy File

image

4: Change the Configuration to the opposite of the dll, so FastNoise.dll -> Debug or FastNoiseD.dll -> Release

Set Excluded From Build to Yes, this will stop the dll being deployed for the incorrect build config

image

Done!

You should now be able to include FastNoise2 into your Visual Studio project using #include <FastNoise/FastNoise.h>

When building it should link with the FastNoise .lib then copy the .dll file to the output directory and your program should run!

Getting started using FastNoise2

Demo

Here are the demo Visual Studio 2019 project files used to create the above guide, look at the setup here if you are struggling with the above steps

FastNoise2Demo.zip