Repository navigation
Expand file tree
/
Copy pathCMakelists.txt
More file actions
65 lines (50 loc) · 1.62 KB
/
Copy pathCMakelists.txt
File metadata and controls
65 lines (50 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(Sand C)
# Set the C standard to C99
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED True)
# Set release mode
set(CMAKE_BUILD_TYPE Release)
# Optimization flags
if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
add_compile_options(-O3 -march=native -flto)
endif()
# Include directories
include_directories(
${PROJECT_SOURCE_DIR}/include
"C:/CSFML/include"
)
# Library directories
link_directories("C:/CSFML/lib/gcc")
# Find all .c source files in the 'src' directory
file(GLOB_RECURSE SRC_FILES "${PROJECT_SOURCE_DIR}/src/*.c")
# If 'src' directory doesn't exist, search in the current directory
if(NOT SRC_FILES)
file(GLOB_RECURSE SRC_FILES "${PROJECT_SOURCE_DIR}/*.c")
endif()
# Create executable
add_executable(${PROJECT_NAME} ${SRC_FILES})
# Link libraries
target_link_libraries(${PROJECT_NAME}
"C:/CSFML/lib/gcc/libcsfml-graphics.a"
"C:/CSFML/lib/gcc/libcsfml-audio.a"
"C:/CSFML/lib/gcc/libcsfml-system.a"
"C:/CSFML/lib/gcc/libcsfml-window.a"
m # Math library
)
# Optionally, you can add custom commands to display messages similar to the Makefile
add_custom_target(header
COMMAND ${CMAKE_COMMAND} -E echo "Building files..."
COMMENT "Header"
)
add_custom_target(done
COMMAND ${CMAKE_COMMAND} -E echo "Build successful!"
COMMENT "Done"
)
# Copy the binary to the root directory
# For windows, add the .exe extension
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${PROJECT_NAME}> ${PROJECT_SOURCE_DIR}/${PROJECT_NAME}.exe
)
add_dependencies(${PROJECT_NAME} header done)