Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - need_help_with_cmake

Pages: [1]
1
General / CMake in SFML 2.5
« on: May 16, 2018, 04:59:53 am »
Hi SFML team and forum readers,

I'm trying to use the new SFML CMake files with minimal success. I have good knowledge of C++, but only working knowledge of CMake. I have a few goals I'm trying to accomplish:

1. Embed SFML in my project (gets compiled as part of project; no separate step)
2. Include SFML statically
3. Expose SFML to other packages (should be a result of 1)

I was able to get the default SFML project building so long as I don't change anything.

However, I want to include SFML in my project, and my current workflow is to call CMake twice - once for SFML, and once for my project. I would like to be able to set up my project such that SFML appears as part of the resultant solution/etc.

My project is set up as follows:

/cmake
|    /modules
|    |    Findimgui.cmake
|    |    Findimgui-sfml.cmake
|    CMakeLists.txt (Main project CMake file)
/intermediate
|    /SFML
|    SFMLConfig.cmake
|    SFMLConfigDependencies.cmake
|    ... etc
/third-party
|    /SFML
|    < basically contents of the SFML GitHub repo; some files/folders get deleted >
/my-project
|     ...

I have a Python script to run CMake, the relevant lines are as follows:
run("cmake -A x64 -T host=x64 -DBUILD_SHARED_LIBS=OFF ../../third-party/SFML/", cwd='intermediate/SFML/')
run("cmake -A x64 -T host=x64 -DBUILD_SHARED_LIBS=OFF ../cmake/", cwd='intermediate/')

My main CMakeLists.txt:
cmake_minimum_required(VERSION 3.1)

project(my_proj)

set(my_proj_VERSION_MAJOR 0)
set(my_proj_VERSION_MINOR 1)

set(EXECUTABLE_NAME "my_proj")
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)

# Custom packages
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/modules/")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../third-party/SFML/cmake/Modules")

# SFML
#set(SFML_STATIC_LIBRARIES TRUE) # Can't compile static yet
set(SFML_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../intermediate/SFML/")
set(SFML_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../third-party/SFML/")
#set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../third-party/SFML/cmake/Modules")
#set(SFML_ROOT ${SFML_ROOT} "${CMAKE_CURRENT_SOURCE_DIR}/../third-party/SFML/cmake/Modules")
#message(STATUS "CMAKE_LIBRARY_PATH: ${CMAKE_LIBRARY_PATH}")
find_package(SFML 2.5 COMPONENTS graphics audio network REQUIRED)

# Imgui
find_package(imgui)
include_directories(${IMGUI_INCLUDE_DIRS})

find_package(imgui-sfml)
include_directories(${IMGUI_SFML_INCLUDE_DIRS})

add_executable(my_proj ../main.cpp)

target_link_libraries(my_proj
    sfml-graphics
    sfml-audio
    sfml-network
    imgui
    imgui-sfml
    )

add_dependencies(my_proj
    imgui
    imgui-sfml
)

If I compile SFML as a shared library, I can get pretty close - but my_proj and imgui-sfml are trying to use .lib files instead of .dll files, so I get linker errors.

Contents of Findimgui-sfml.cmake:
cmake_minimum_required(VERSION 3.1)

project(imgui-sfml)

file(GLOB_RECURSE IMGUI_SFML_SRC
    "${CMAKE_CURRENT_SOURCE_DIR}/../third-party/imgui-sfml/*.cpp"
)

find_package(SFML 2.5 COMPONENTS graphics REQUIRED)

set(IMGUI_SFML_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../third-party/imgui-sfml/")

add_library(imgui-sfml STATIC
    ${IMGUI_SFML_SRC}
)

target_link_libraries(imgui-sfml
    sfml-graphics
)

If I try to compile SFML statically, I get errors about missing packages:
-- Selecting Windows SDK version 10.0.17134.0 to target Windows 10.0.16299.
CMake Error at D:/code/my_proj/intermediate/SFML/SFMLConfig.cmake:139 (message):
  SFML found but some of its dependencies are missing ( FreeType OpenAL Ogg
  Vorbis VorbisFile VorbisEnc FLAC)
Call Stack (most recent call first):
  CMakeLists.txt:28 (find_package)


CMake Error at CMakeLists.txt:28 (find_package):
  Found package configuration file:

    D:/code/my_proj/cmake/../intermediate/SFML/SFMLConfig.cmake

  but it set SFML_FOUND to FALSE so package "SFML" is considered to be NOT
  FOUND.


-- Configuring incomplete, errors occurred!

I would appreciate any help/suggestions with this.

Thanks for your time, and please let me know if more information is required.

Thanks!

Pages: [1]
anything