Skip to content

Commit cabe796

Browse files
committed
Enable static builds linked against MSVC
1 parent 217d090 commit cabe796

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

CMakeLists.txt

+19-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake")
88

99
project(Spiced)
1010

11+
if (MSVC OR MINGW)
12+
option(STATIC_SFML "Link SFML Statically" TRUE)
13+
else()
14+
option(STATIC_SFML "Link SFML Statically" FALSE)
15+
endif()
16+
17+
18+
if (STATIC_SFML)
19+
set(SFML_STATIC_LIBRARIES TRUE)
20+
endif()
21+
1122
find_package(SFML 2 REQUIRED system window graphics network audio main)
1223

1324

@@ -185,13 +196,17 @@ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LINKER_FLAGS}")
185196
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LINKER_FLAGS}")
186197
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${LINKER_FLAGS}")
187198

199+
if (STATIC_SFML)
200+
list(APPEND LIBS ${SFML_DEPENDENCIES})
201+
endif()
202+
188203
add_executable(spiced WIN32 src/main.cpp src/game.cpp src/game_event.cpp src/map.cpp src/chaiscript_stdlib.cpp src/chaiscript_bindings.cpp src/chaiscript_creator.cpp)
189-
target_link_libraries(spiced ${SFML_GRAPHICS} ${SFML_WINDOW} ${SFML_SYSTEM} ${LIBS})
190-
file(COPY sample_game DESTINATION ${CMAKE_BINARY_DIR})
204+
target_link_libraries(spiced ${SFML_LIBRARIES} ${LIBS})
205+
include_directories(${SFML_INCLUDE_DIR})
191206

192207

193-
include_directories(${SFML_INCLUDE_DIR})
194-
target_link_libraries(spiced ${SFML_LIBRARIES})
208+
file(COPY sample_game DESTINATION ${CMAKE_BINARY_DIR})
209+
195210

196211
install(TARGETS spiced RUNTIME DESTINATION bin)
197212

0 commit comments

Comments
 (0)