Auburn / FastNoise2

Modular node graph based noise generation library using SIMD, C++17 and templates
MIT License
1.02k stars 107 forks source link

Error after adding FastNoise to CMake project #84

Closed Michael2109 closed 2 years ago

Michael2109 commented 2 years ago

I would like to add FastNoise to my CMake project. To do so I've added this to my CMakeLists.txt.

add_subdirectory(libraries/FastNoise2)
target_link_libraries(nibbles_01 PRIVATE <other libs> FastNoise)

I then copied the FastNoise2 directory into a libraries directory at the top level of my project.

I can run the project successfully and include FastNoise/FastNoise.h however if I add auto fnSimplex = FastNoise::New<FastNoise::Simplex>(); it instantly exits. If I run the generated .exe I get this error:

image

Here is my full CMakeLists for if there is anything obvious.

cmake_minimum_required(VERSION 3.17)
project(powder_game)

set(CMAKE_CXX_STANDARD 20)
set(FASTNOISE2_NOISETOOL OFF CACHE BOOL "Build Noise Tool" FORCE)

add_executable(nibbles_01 src/main.cpp src/game/simulation/chunks/Chunk.cpp src/game/simulation/chunks/Chunk.h src/game/simulation/chunks/elements/Element.cpp src/game/simulation/chunks/elements/Element.h src/game/simulation/chunks/elements/liquid/Liquid.cpp src/game/simulation/chunks/elements/liquid/Liquid.h src/game/simulation/math/Vector2.cpp src/game/simulation/math/Vector2.h src/game/simulation/math/RandomUtils.cpp src/game/simulation/chunks/elements/liquid/Water.cpp src/game/simulation/chunks/elements/liquid/Water.h src/game/simulation/chunks/elements/solid/immovable/ImmovableSolid.cpp src/game/simulation/chunks/elements/solid/immovable/ImmovableSolid.h src/game/simulation/chunks/elements/solid/Solid.cpp src/game/simulation/chunks/elements/solid/Solid.h src/game/simulation/chunks/elements/gas/Gas.cpp src/game/simulation/chunks/elements/gas/Gas.h src/game/simulation/chunks/elements/solid/movable/MovableSolid.cpp src/game/simulation/chunks/elements/solid/movable/MovableSolid.h src/game/simulation/chunks/elements/solid/immovable/walls/Wall.cpp src/game/simulation/chunks/elements/solid/immovable/walls/Wall.h src/game/simulation/chunks/elements/solid/movable/Sand.cpp src/game/simulation/chunks/elements/solid/movable/Sand.h src/game/simulation/chunks/elements/gas/Fire.cpp src/game/simulation/chunks/elements/gas/Fire.h src/game/simulation/chunks/elements/gas/Smoke.cpp src/game/simulation/chunks/elements/gas/Smoke.h src/game/simulation/chunks/elements/gas/Steam.cpp src/game/simulation/chunks/elements/gas/Steam.h src/game/simulation/chunks/elements/liquid/Lava.cpp src/game/simulation/chunks/elements/liquid/Lava.h src/game/simulation/chunks/elements/liquid/Oil.cpp src/game/simulation/chunks/elements/liquid/Oil.h src/game/simulation/math/concavehull/concavehull.h src/game/simulation/math/simplexnoise/SimplexNoise.cpp src/game/simulation/math/simplexnoise/SimplexNoise.h src/game/simulation/math/perlinnoise/Perlin.cpp src/game/simulation/math/perlinnoise/Perlin.h src/game/simulation/math/fractalnoise/FractalNoise.cpp src/game/simulation/math/fractalnoise/FractalNoise.h src/game/Game.cpp src/game/Game.h src/game/ElementType.h src/game/StatsTracker.cpp src/game/StatsTracker.h src/game/simulation/Simulation.cpp src/game/simulation/Simulation.h src/game/Globals.h src/game/Box2DDebugDraw.cpp src/game/Box2DDebugDraw.h src/game/gameobjects/player/Player.cpp src/game/gameobjects/player/Player.h src/game/gameobjects/Entity.cpp src/game/gameobjects/Entity.h src/game/simulation/math/triangulation/earcut.hpp src/game/simulation/math/concavehull/delaunater.cpp src/game/simulation/math/concavehull/delaunater.h src/game/simulation/chunks/elements/solid/immovable/walls/ores/Ore.cpp src/game/simulation/chunks/elements/solid/immovable/walls/ores/Ore.h src/game/simulation/chunks/elements/solid/immovable/walls/ores/Gold.cpp src/game/simulation/chunks/elements/solid/immovable/walls/ores/Gold.h)

# OpenGL
find_package(OpenGL REQUIRED)

add_subdirectory(3rd_party/Box2D-cmake)
add_subdirectory(CDT-master/CDT)
add_subdirectory(libraries/FastNoise2)

set(GLEW_INCLUDE_DIRS, "C:/Program Files/glew-2.1.0/include/")
set(GLEW_LIBRARIES, "C:/Program Files/glew-2.1.0/lib")

include_directories(headers /usr/include "libraries/SFML/include")

set(SFML_ROOT "libraries/SFML")
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_modules")
find_package(SFML COMPONENTS system window graphics network audio CONFIG REQUIRED)

include_directories(${SFML_INCLUDE_DIR})

# glut32.dll must be present in "project-directory/OpenGL/dll/"
add_custom_target(glutdlllib
        COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/libfreeglut.dll ${CMAKE_BINARY_DIR}
        )
add_custom_target(box2dlib
        COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/box2d.lib ${CMAKE_BINARY_DIR}
        )

add_dependencies(nibbles_01 glutdlllib)
add_dependencies(nibbles_01 box2dlib)

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_modules")

target_link_libraries(nibbles_01 PRIVATE ${OPENGL_LIBRARY} ${SFML_LIBRARIES} ${SFML_DEPENDENCIES}  sfml-system  sfml-network sfml-graphics sfml-window tobanteGaming::Box2D FastNoise)

file(COPY assets DESTINATION ${CMAKE_BINARY_DIR})

# Copy dlls to build
if (WIN32)
    file(GLOB BINARY_DEP_DLLS "${SFML_INCLUDE_DIR}/../bin/*.dll")
    file(COPY ${BINARY_DEP_DLLS} DESTINATION ${CMAKE_BINARY_DIR})
    file(GLOB MINGW_DEP_DLLS "C:/mingw64/bin/*.dll")
    file(COPY ${MINGW_DEP_DLLS} DESTINATION ${CMAKE_BINARY_DIR})
endif ()

How to I add this correctly to my CMake project?

caseymcc commented 2 years ago

I think the error is that you are using mingw. The version of gcc included with mingw will not properly build avx and will crash when ran.

caseymcc commented 2 years ago

You can just build it with VC, if you do not want to run VS just use cmake's build

cmake --build {your build directory}

make sure that cmake generates a VC build

cmake ... -G "Visual Studio 16 2019" -A x64 //or -G "Visual Studio 17 2022" -A x64
Michael2109 commented 2 years ago

@caseymcc That was it and thank you for the quick responses!