-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
166 lines (138 loc) · 4.89 KB
/
CMakeLists.txt
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
cmake_minimum_required(VERSION 2.8)
# *******************************************
# ************* CMake Content ***************
# *******************************************
# This CMake create a workspace containing the following projects
#
# Programs
# - pthread_lab
# IDE dependent config
if(${CMAKE_GENERATOR} MATCHES "Visual Studio.*")
MESSAGE("Add definition for ${CMAKE_GENERATOR}")
add_definitions( -D_CRT_SECURE_NO_WARNINGS )
add_definitions( -DHAVE_STRUCT_TIMESPEC )
endif()
# Add definition for relative path into project
add_definitions( -DPROJECT_ROOT_PATH="${CMAKE_CURRENT_SOURCE_DIR}")
# Guard for linux users
if(NOT WIN32)
MESSAGE(WARNING "This CMake project has not been tested on Linux.")
endif()
project(pthread_lab)
set(LIBS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib)
# Set to 1 to activate debug compilation (0 for release)
if(NOT ${CMAKE_GENERATOR} MATCHES "Visual Studio.*")
set(DEBUG 0)
if(${DEBUG})
MESSAGE("Generate Debug project")
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Debug)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -pg -Wall")
else()
MESSAGE("Generate Release project")
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Release)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wall")
endif()
else()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
endif()
if(WIN32)
set(LIBS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib)
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/lib/cmake_modules/")
# *******************************************
# ************** SDL2 LIBRARY ***************
# *******************************************
# Set variables before finding SDL Library
# Helps to find where SDL libraries are saved (win32 only)
if(WIN32)
# find the SDL2-x.y.z folder in the lib directory.
file(GLOB SDL2DIR "${LIBS_DIR}/SDL2-[\\.|0-9]*")
set(ENV{SDL2DIR} ${SDL2DIR})
endif()
Find_Package (SDL2 REQUIRED )
if(NOT SDL2_FOUND)
MESSAGE(FATAL_ERROR "SDL not found !")
endif()
if (WIN32)
file(GLOB
SDL2_DLL
${SDL2DIR}/bin/*.dll
${SDL2DIR}/lib/*.dll
)
MESSAGE("Copy SDL DLLs into ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
if(NOT ${CMAKE_GENERATOR} MATCHES "Visual Studio.*")
file(COPY ${SDL2_DLL} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
else()
file(COPY ${SDL2_DLL} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Debug)
file(COPY ${SDL2_DLL} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Release)
endif()
endif()
# *******************************************
# ************ SDL2TTF LIBRARY **************
# ******************************************
# Set variables before finding SDL2TTF Library
# Helps to find where SDL2TTF libraries are saved (win32 only)
if(WIN32)
# find the SDL2_ttf-x.y.z folder in the lib directory.
file(GLOB SDL2TTFDIR "${LIBS_DIR}/SDL2_ttf-[\\.|0-9]*")
set(ENV{SDL2TTFDIR} ${SDL2TTFDIR})
endif()
Find_Package (SDL2TTF REQUIRED )
if(NOT SDL2TTF_FOUND)
MESSAGE(FATAL_ERROR "SDL2TTF not found !")
endif()
if (WIN32)
file(GLOB
SDL2TTF_DLL
${SDL2TTFDIR}/bin/*.dll
${SDL2TTFDIR}/lib/*.dll
)
MESSAGE("Copy SDL2_ttf DLLs into ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
if(NOT ${CMAKE_GENERATOR} MATCHES "Visual Studio.*")
file(COPY ${SDL2TTF_DLL} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
else()
file(COPY ${SDL2TTF_DLL} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Debug)
file(COPY ${SDL2TTF_DLL} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Release)
endif()
endif()
# *******************************************
# ************ Pthread LIBRARY **************
# *******************************************
if (WIN32)
set(THREADS_USE_PTHREADS_WIN32 true)
# pthread included AFTER Sdl to avoid unnecessary warnings
file(GLOB PTHREADDIR "${LIBS_DIR}/pthread-[\\.|0-9]*")
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${PTHREADDIR})
Find_Package ( THREADS REQUIRED )
endif()
if(NOT THREADS_FOUND)
MESSAGE(FATAL_ERROR "Pthread not found !")
endif()
if (WIN32)
file(GLOB
PTHREADS_DLL
${CMAKE_PREFIX_PATH}/lib/*.dll
)
MESSAGE("Copy Pthreads DLLs into ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
if(NOT ${CMAKE_GENERATOR} MATCHES "Visual Studio.*")
file(COPY ${PTHREADS_DLL} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
else()
file(COPY ${PTHREADS_DLL} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Debug)
file(COPY ${PTHREADS_DLL} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Release)
endif()
endif()
# *******************************************
# ************ pthread_lab.exe *************
# *******************************************
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include ${SDL2_INCLUDE_DIR} ${SDL2TTF_INCLUDE_DIR} ${THREADS_PTHREADS_INCLUDE_DIR})
file(
GLOB_RECURSE
source_files
./src/*.c
./include/*.h
)
add_executable( pthread_lab ${source_files} ${header_files})
target_link_libraries(pthread_lab ${SDL2_LIBRARY} ${SDL2TTF_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
set(CMAKE_C_FLAGS "-std=c99")