Skip to content

Including the library in your project

Krazer edited this page Jun 23, 2021 · 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 website 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

For a manually generated (i.e. not generated by CMake) Visual Studio solution(.sln), you will need to add include/lib directories of the library to your solution.

  1. Right click on your project and select Propertiesimage
  2. Select the configuration Release, Debug, etc... You will have to make the changes in steps 3 & 4 for each config. image
  3. Select C\C++ then General and modify the Additional Include Directories to include the FastNoise2 directory. image
  4. Next select Linker then Input and modify the Additional Dependencies to include the FastNoise2 lib FastNoise.lib for release configs and FastNoised.lib for debug configs. image