Skip to content

Commit 20a563d

Browse files
committed
Add small CMake improvements
- Use spaces instead of tabs - Use GLOB_RECURSE to find all source files
1 parent fe508bc commit 20a563d

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

CMakeLists.txt

+15-12
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,32 @@ project(CMakeSFMLProject LANGUAGES CXX)
66
option(CMAKESFMLPROJECT_STATIC_LIBS "Link SFML libraries statically?" OFF)
77
option(CMAKESFMLPROJECT_STATIC_STD_LIBS "Use statically linked standard/runtime libraries? This option must match the one used for SFML." OFF)
88

9+
# Find all source files
10+
file(GLOB_RECURSE SOURCE_FILES CONFIGURE_DEPENDS ${PROJECT_SOURCE_DIR}/src/*.cpp ${PROJECT_SOURCE_DIR}/src/*.hpp)
11+
912
# Tell CMake to build a executable
10-
add_executable(${PROJECT_NAME} src/main.cpp)
13+
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
1114

1215
# CMake SFML Project uses C++17 features
1316
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
1417
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_EXTENSIONS NO CXX_STANDARD_REQUIRED YES)
1518

1619
# Make sure that the runtime library gets linked statically
1720
if(CMAKESFMLPROJECT_STATIC_STD_LIBS)
18-
if(NOT CMAKESFMLPROJECT_STATIC_LIBS)
19-
message("\n-> If you check CMAKESFMLPROJECT_STATIC_STD_LIBS, you also need to check CMAKESFMLPROJECT_STATIC_LIBS.")
20-
message("-> It would lead to multiple runtime environments which results in undefined behavior.\n")
21-
elseif(WIN32 AND MSVC)
22-
set_property(TARGET ${PROJECT_NAME} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
23-
elseif(CMAKE_COMPILER_IS_GNUCXX)
24-
# Note: Doesn't work for TDM compiler, since it's compiling the runtime libs statically by default
25-
target_compile_options(${PROJECT_NAME} PRIVATE -static)
26-
endif()
21+
if(NOT CMAKESFMLPROJECT_STATIC_LIBS)
22+
message("\n-> If you check CMAKESFMLPROJECT_STATIC_STD_LIBS, you also need to check CMAKESFMLPROJECT_STATIC_LIBS.")
23+
message("-> It would lead to multiple runtime environments which results in undefined behavior.\n")
24+
elseif(WIN32 AND MSVC)
25+
set_property(TARGET ${PROJECT_NAME} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
26+
elseif(CMAKE_COMPILER_IS_GNUCXX)
27+
# Note: Doesn't work for TDM compiler, since it's compiling the runtime libs statically by default
28+
target_compile_options(${PROJECT_NAME} PRIVATE -static)
29+
endif()
2730
endif()
2831

2932
# Request static SFML libraries when building statically
3033
if(CMAKESFMLPROJECT_STATIC_LIBS)
31-
set(SFML_STATIC_LIBRARIES TRUE)
34+
set(SFML_STATIC_LIBRARIES TRUE)
3235
endif()
3336

3437
# Find SFML
@@ -39,4 +42,4 @@ target_link_libraries(${PROJECT_NAME} sfml-graphics)
3942

4043
# Install executable
4144
install(TARGETS ${PROJECT_NAME}
42-
RUNTIME DESTINATION .)
45+
RUNTIME DESTINATION .)

0 commit comments

Comments
 (0)