I've created a new project with a CMakeLists.txt and vcpkg in Windows 11 with CLion.
I would like to add Box2D, OpenGL, GLUT, GLEW, and SFML
To do so I've cloned vcpkg in the project directory and added a vcpkg.json.
vcpkg.json
{
"name" : "example-project",
"version-string" : "0.0.1",
"license" : "MIT",
"dependencies" : [
"box2d",
"sfml",
"opengl",
"freeglut",
"glew"
]
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.15)
# Setup vcpkg script with CMake (note: should be placed before project() call)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake CACHE STRING "Vcpkg toolchain file")
project(ExampleApp)
set(CMAKE_CXX_STANDARD 23)
find_package(SFML COMPONENTS system window graphics network audio CONFIG REQUIRED)
find_package(box2d CONFIG REQUIRED)
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
find_package(GLEW REQUIRED)
include_directories(SFML)
include_directories(box2d)
include_directories(OpenGL)
include_directories(OpenGL/include) # OpenGL/include has to contain the required OpenGL's .h files
include_directories(OpenGL/lib) # OpenGL/lib has to contain the required OpenGL's .lib files
set(ExampleApp_SourceFiles example/files)
add_executable(ExampleApp ${ExampleApp_SourceFiles})
target_include_directories(ExampleApp
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
${_VCPKG_INSTALLED_DIR}/include
)
target_include_directories(ExampleApp PRIVATE ${OPENGL_INCLUDE_DIR})
target_link_libraries(ExampleApp PRIVATE GLEW::GLEW)
target_link_libraries(ExampleApp PRIVATE ${OPENGL_LIBRARIES})
target_link_libraries(ExampleApp PRIVATE sfml-system PRIVATE sfml-network PRIVATE sfml-graphics PRIVATE sfml-window)
target_link_libraries(ExampleApp PRIVATE FastNoise)
target_link_libraries(ExampleApp PRIVATE box2d::box2d)
I've added this CMake option for CLion as mentioned in the vcpkg documentation.
-G "MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=C:/Users/micha/CLionProjects/cmake-vcpkg-example/vcpkg/scripts/buildsystems/vcpkg.cmake"
After building this (Using the MinGW Toolchain and Generator) I get errors that files aren't found in box2d and sfml (Likely in the other dependencies too).
Error
C:\Program Files\JetBrains\CLion 2023.1.5\bin\mingw\bin/ld.exe: CMakeFiles\ExampleApp.dir/objects.a(Chunk.cpp.obj): in function `Chunk::~Chunk()':
Chunk
// undefined reference
simulation->game->world->DestroyBody(body);
This method worked fine for adding the fmt and Catch2 libraries but I can't get it to find these other libraries.
What else do I need to do to use these dependencies? I've spent days on this now and can't find any similar examples.