From 1c898e15a5cc5ae2ef9a9a207d0c79cf68b32250 Mon Sep 17 00:00:00 2001 From: Blargian Date: Tue, 28 Nov 2023 15:23:40 +0100 Subject: [PATCH] Update CmakeLists.txt for building on windows and add some information about it in the readme --- CMakeLists.txt | 37 +++++++++++++++++++++++++++++++++++-- README.md | 2 ++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index efc342b..1069664 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,45 @@ cmake_minimum_required(VERSION 3.22) project(sorting-visualizer) -set(SFML_DIR "lib/SFML-2.5.1/lib/cmake/SFML") +set(default_build_type "Release") +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + message( STATUS "Setting build type to '${default_build_type}' as none was specified.") + set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build." FORCE) + # Set the possible values of build type for cmake-gui + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Release" "MinSizeRel" "RelWithDebInfo") +endif() +set(SFML_DIR "C:/Program Files (x86)/SFML/lib/cmake/SFML") -find_package(SFML COMPONENTS graphics window REQUIRED) +find_package(SFML COMPONENTS graphics window CONFIG REQUIRED) add_executable(sorting-visualizer src/main.cpp src/Sortable.cpp src/SortAlgorithms.cpp src/SortController.cpp src/Utils.cpp) target_link_libraries(sorting-visualizer sfml-graphics sfml-window) +# Copy across .dlls for windows users +get_target_property(SFML_TYPE sfml-graphics TYPE) +if(SFML_TYPE STREQUAL "SHARED_LIBRARY") + message(STATUS "Copying sfml-graphics DLLs to ${CMAKE_CURRENT_BINARY_DIR}/$") + add_custom_command( + TARGET sorting-visualizer POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + $ + ${CMAKE_CURRENT_BINARY_DIR}/$) + + message(STATUS "Copying sfml-window DLLs to ${CMAKE_CURRENT_BINARY_DIR}/$") + add_custom_command( + TARGET sorting-visualizer POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + $ + ${CMAKE_CURRENT_BINARY_DIR}/$) + + message(STATUS "Copying sfml-system DLLs to ${CMAKE_CURRENT_BINARY_DIR}/$") + add_custom_command( + TARGET sorting-visualizer POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + $ + ${CMAKE_CURRENT_BINARY_DIR}/$) +endif() + diff --git a/README.md b/README.md index 8f3eeed..4be91c2 100644 --- a/README.md +++ b/README.md @@ -53,3 +53,5 @@ Awesome! [Here](https://github.com/alesbe/sorting-visualizer/wiki) you can find ### 🖥️ Windows / MacOS The libraries included with the project only work with gcc compiler, for now, if you want to use it on Windows or macOS, you'll need to [download sfml](https://www.sfml-dev.org/download/sfml/2.5.1/) and compile the source code located in `/src` yourself. + +Once you have compiled the source files you can set `SFML_DIR` in `CMakeLists.txt` to the path which contains SFMLConfig.cmake. This will depend on where you have installed SFML to, for instance `C:/Program Files (x86)/SFML/lib/cmake/SFML`. From the root directory of the repository run `mkdir build cd build` and then run `cmake ..` to generate make files. For a list of generators you can type`cmake -G`. For instance if you want to build for the latest version of Visual Studio run `cmake -G 'Visual Studio 17 2022' ..` from within `/build`.