0
\$\begingroup\$

I am working on a game in c++, i want to make a Cmakelists.txt file for build a .exe file.

- ISO C++17
- SDK : 10.0
- Visual C++ 17 (2022) v143
- sfml 2.6.1 / glew 2.1.0 / glm 0.9.9.8
- Modern opengl (3.0) 
- OS : Windows
- Release
- x64
- static (no dll)

c++ folders include :

- F:\libs\glew-2.1.0\include
- F:\libs\SFML-2.6.1\include
- F:\libs\glm-0.9.9.8\glm

lib folders :

- F:\libs\glew-2.1.0\lib\Release\x64
- F:\libs\SFML-2.6.1\lib

lib dependencies :

- glew32s.lib
- sfml-graphics-s.lib
- sfml-window-s.lib
- sfml-system-s.lib
- opengl32.lib
- freetype.lib
- winmm.lib
- gdi32.lib
- sfml-audio-s.lib
- openal32.lib
- flac.lib
- vorbisenc.lib
- vorbisfile.lib
- vorbis.lib
- ogg.lib
- sfml-network-s.lib
- ws2_32.lib

c++ preprocessor :

- SFML_STATIC 

my includes.h :

#ifndef DEF_INCLUDES
#define DEF_INCLUDES

#define GLEW_STATIC
#include <GL/glew.h>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Network.hpp>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/transform.hpp>

//others includes

#endif

My game use a ressource folder name : all

So, i have a file Cmakelists.txt that contain :

cmake_minimum_required(VERSION 3.1)

project(testing)

set(CMAKE_CXX_STANDARD 17) # Set C++ standard to C++17
set(CMAKE_SYSTEM_VERSION 10.0) # Set the Windows SDK version
set(CMAKE_GENERATOR_TOOLSET "host=x64" CACHE STRING "Platform Toolset" FORCE) # Specify the Visual Studio generator
set(CMAKE_GENERATOR_PLATFORM x64)

file(GLOB FILES_CPP_SOURCES
    "src/*.cpp"
    "../Engine2D3D/src/*.cpp"
    "../Engine2D3D/src/shapes/*.cpp"
)

include(FetchContent) # Use FetchContent to download GLEW from the Perlmint repository
FetchContent_Declare(
    GLEW
    GIT_REPOSITORY https://github.com/Perlmint/glew-cmake.git
    GIT_TAG glew-cmake-2.1.0
)
FetchContent_MakeAvailable(GLEW)

include(FetchContent) # Use FetchContent to download SFML from GitHub
FetchContent_Declare(
    SFML
    GIT_REPOSITORY https://github.com/SFML/SFML.git
    GIT_TAG 2.6.1
)
# Specify static linking and release mode for SFML
set(SFML_STATIC_LIBRARIES TRUE)
set(BUILD_SHARED_LIBS FALSE)
FetchContent_MakeAvailable(SFML)

include(FetchContent) # Use FetchContent to download GLM from GitHub
FetchContent_Declare(
    GLM
    GIT_REPOSITORY https://github.com/g-truc/glm.git
    GIT_TAG 0.9.9.8
)
FetchContent_MakeAvailable(GLM)

message(STATUS "SFML_SOURCE_DIR: ${SFML_SOURCE_DIR}")
message(STATUS "GLM_SOURCE_DIR: ${GLM_SOURCE_DIR}")
message(STATUS "GLEW_SOURCE_DIR: ${GLEW_SOURCE_DIR}")

# Include directories for SFML
include_directories(
    ${CMAKE_CURRENT_BINARY_DIR}/_deps/glew-src/include
    ${SFML_SOURCE_DIR}/include
    ${CMAKE_CURRENT_BINARY_DIR}/_deps/glm-src
)

add_executable(${PROJECT_NAME} ${FILES_CPP_SOURCES}) # Add executable

target_link_libraries(${PROJECT_NAME} 
    PRIVATE 
    ${CMAKE_CURRENT_BINARY_DIR}/lib/Release/glew.lib
    sfml-graphics sfml-window sfml-system opengl32
    ${CMAKE_CURRENT_BINARY_DIR}/_deps/sfml-src/extlibs/libs-msvc/x64/freetype.lib 
    ${CMAKE_CURRENT_BINARY_DIR}/_deps/sfml-src/extlibs/libs-msvc/x64/flac.lib 
    ${CMAKE_CURRENT_BINARY_DIR}/_deps/sfml-src/extlibs/libs-msvc/x64/ogg.lib 
    ${CMAKE_CURRENT_BINARY_DIR}/_deps/sfml-src/extlibs/libs-msvc/x64/openal32.lib 
    ${CMAKE_CURRENT_BINARY_DIR}/_deps/sfml-src/extlibs/libs-msvc/x64/vorbis.lib 
    ${CMAKE_CURRENT_BINARY_DIR}/_deps/sfml-src/extlibs/libs-msvc/x64/vorbisenc.lib 
    ${CMAKE_CURRENT_BINARY_DIR}/_deps/sfml-src/extlibs/libs-msvc/x64/vorbisfile.lib
    sfml-audio
    sfml-network
)

# Set flags for static linking
set_target_properties(${PROJECT_NAME} PROPERTIES 
    CXX_STANDARD 17
    CXX_EXTENSIONS NO
)

# Set flags for Release mode
if(CMAKE_BUILD_TYPE STREQUAL "Release")
    target_compile_options(${PROJECT_NAME} PRIVATE -O3)
endif()

All messages output are :

  • SFML_SOURCE_DIR: F:/repos/Big Town/Big Town/build/_deps/sfml-src
  • GLM_SOURCE_DIR:
  • GLEW_SOURCE_DIR:

glm and glew are empty that why i use ${CMAKE_CURRENT_BINARY_DIR} = F:/repos/Big Town/Big Town/build

commands use for i launch my script in a build folder :

  • cmake .. -DCMAKE_BUILD_TYPE=Release -DSFML_STATIC_LIBRARIES=TRUE -DBUILD_SHARED_LIBS=FALSE
  • cmake --build . --config Release

Doing that way it make me a .exe file but when a start it, it launch and stop directly without any error.

When a build using visual studio it work correctly, i suspect i have fail somewhere about linking about sfml/glew or other dependencies in my Cmakelists.txt file.

Thank for reading. If you have any suggestion, tell me about it.

\$\endgroup\$

0

You must log in to answer this question.

Browse other questions tagged .