Skip to content

Commit 7c536ce

Browse files
authored
Merge pull request #36 from Blargian/windows_build
Update CmakeLists.txt for building on windows and add some informatio…
2 parents 3286000 + 1c898e1 commit 7c536ce

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

CMakeLists.txt

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,45 @@
11
cmake_minimum_required(VERSION 3.22)
22
project(sorting-visualizer)
33

4-
set(SFML_DIR "lib/SFML-2.5.1/lib/cmake/SFML")
4+
set(default_build_type "Release")
5+
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
6+
message( STATUS "Setting build type to '${default_build_type}' as none was specified.")
7+
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build." FORCE)
8+
# Set the possible values of build type for cmake-gui
9+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
10+
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
11+
endif()
512

13+
set(SFML_DIR "C:/Program Files (x86)/SFML/lib/cmake/SFML")
614

7-
find_package(SFML COMPONENTS graphics window REQUIRED)
15+
find_package(SFML COMPONENTS graphics window CONFIG REQUIRED)
816

917
add_executable(sorting-visualizer src/main.cpp src/Sortable.cpp src/SortAlgorithms.cpp src/SortController.cpp src/Utils.cpp)
1018

1119
target_link_libraries(sorting-visualizer sfml-graphics sfml-window)
1220

21+
# Copy across .dlls for windows users
22+
get_target_property(SFML_TYPE sfml-graphics TYPE)
23+
if(SFML_TYPE STREQUAL "SHARED_LIBRARY")
24+
message(STATUS "Copying sfml-graphics DLLs to ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>")
25+
add_custom_command(
26+
TARGET sorting-visualizer POST_BUILD
27+
COMMAND ${CMAKE_COMMAND} -E copy
28+
$<TARGET_FILE:sfml-graphics>
29+
${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>)
30+
31+
message(STATUS "Copying sfml-window DLLs to ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>")
32+
add_custom_command(
33+
TARGET sorting-visualizer POST_BUILD
34+
COMMAND ${CMAKE_COMMAND} -E copy
35+
$<TARGET_FILE:sfml-window>
36+
${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>)
37+
38+
message(STATUS "Copying sfml-system DLLs to ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>")
39+
add_custom_command(
40+
TARGET sorting-visualizer POST_BUILD
41+
COMMAND ${CMAKE_COMMAND} -E copy
42+
$<TARGET_FILE:sfml-system>
43+
${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>)
44+
endif()
45+

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,5 @@ Awesome! [Here](https://github.com/alesbe/sorting-visualizer/wiki) you can find
5353

5454
### 🖥️ Windows / MacOS
5555
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.
56+
57+
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`.

0 commit comments

Comments
 (0)