Skip to content

Commit 90519bd

Browse files
committed
push
0 parents  commit 90519bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+11816
-0
lines changed

.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
3+
root = true
4+
5+
[*]
6+
end_of_line = lf
7+
indent_size = 2
8+
indent_style = space
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
12+
[*.{def,rc}]
13+
indent_size = 4
14+
indent_style = tab

.gitattributes

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
* text=auto
2+
*.c whitespace=trailing-space, tabwidth=2, tab-in-indent
3+
*.cpp whitespace=trailing-space, tabwidth=2, tab-in-indent
4+
*.h whitespace=trailing-space, tabwidth=2, tab-in-indent
5+
*.hpp whitespace=trailing-space, tabwidth=2, tab-in-indent
6+
*.py whitespace=trailing-space, tabwidth=2, tab-in-indent

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
*~
2+
*.bak
3+
*.swp
4+
5+
.vs
6+
.vscode
7+
CMakeSettings.json
8+
CMakeLists.txt.user*
9+
*.kdev4
10+
11+
/build
12+
/scripts/__pycache__
13+
/scripts/*.pyc
14+
/scripts/*.pyd
15+
/scripts/cidl_lextab.py
16+
/scripts/cidl_parser.out
17+
/scripts/cidl_parsetab.py

CMakeLists.txt

Lines changed: 348 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,348 @@
1+
project(sampgdk)
2+
3+
cmake_minimum_required(VERSION 2.8.12)
4+
cmake_policy(SET CMP0022 NEW)
5+
6+
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
7+
8+
option(SAMPGDK_STATIC "Build static library instead" OFF)
9+
option(SAMPGDK_BUILD_PLUGINS "Build example plugins" OFF)
10+
option(SAMPGDK_BUILD_AMALGAMATION "Build amalgamation" OFF)
11+
option(SAMPGDK_BUILD_DOCS "Build Doxygen documentation" ON)
12+
13+
set(SAMPGDK_VERSION_MAJOR 4)
14+
set(SAMPGDK_VERSION_MINOR 6)
15+
set(SAMPGDK_VERSION_PATCH 4)
16+
17+
set(SAMPGDK_VERSION ${SAMPGDK_VERSION_MAJOR})
18+
set(SAMPGDK_VERSION ${SAMPGDK_VERSION}.${SAMPGDK_VERSION_MINOR})
19+
set(SAMPGDK_VERSION ${SAMPGDK_VERSION}.${SAMPGDK_VERSION_PATCH})
20+
set(SAMPGDK_VERSION ${SAMPGDK_VERSION}${SAMPGDK_VERSION_SUFFIX})
21+
22+
math(EXPR SAMPGDK_VERSION_ID "${SAMPGDK_VERSION_MAJOR} << 24 |
23+
${SAMPGDK_VERSION_MINOR} << 16 |
24+
${SAMPGDK_VERSION_PATCH} << 8")
25+
26+
if(NOT (MSVC_IDE AND MSVC_VERSION LESS 1600))
27+
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
28+
endif()
29+
30+
find_package(SAMPSDK REQUIRED)
31+
find_package(PythonInterp 2.7 REQUIRED)
32+
33+
include_directories(
34+
${SAMPSDK_INCLUDE_DIR}
35+
${SAMPSDK_INCLUDE_DIR}/amx
36+
${PROJECT_SOURCE_DIR}/include
37+
${PROJECT_BINARY_DIR}/include
38+
${PROJECT_SOURCE_DIR}/lib/sampgdk
39+
)
40+
41+
macro(sampgdk_add_subproject name)
42+
add_subdirectory(${name})
43+
file(RELATIVE_PATH folder ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
44+
set_property(TARGET ${name} PROPERTY FOLDER ${folder})
45+
endmacro()
46+
47+
macro(sampgdk_get_property name var)
48+
get_property(${var} DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY ${name})
49+
endmacro()
50+
51+
macro(sampgdk_set_property name value)
52+
set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY ${name} ${value})
53+
endmacro()
54+
55+
macro(sampgdk_append_property name value)
56+
set_property(DIRECTORY ${PROJECT_SOURCE_DIR} APPEND PROPERTY ${name} ${value})
57+
endmacro()
58+
59+
macro(sampgdk_add_sources)
60+
foreach(file ${ARGN})
61+
if(NOT IS_ABSOLUTE ${file})
62+
sampgdk_append_property(SAMPGDK_SOURCES
63+
${CMAKE_CURRENT_SOURCE_DIR}/${file})
64+
else()
65+
sampgdk_append_property(SAMPGDK_SOURCES ${file})
66+
endif()
67+
endforeach()
68+
endmacro()
69+
70+
macro(sampgdk_get_sources var)
71+
sampgdk_get_property(SAMPGDK_SOURCES ${var})
72+
endmacro()
73+
74+
macro(sampgdk_add_headers)
75+
foreach(file ${ARGN})
76+
if(NOT IS_ABSOLUTE ${file})
77+
sampgdk_append_property(SAMPGDK_HEADERS
78+
${CMAKE_CURRENT_SOURCE_DIR}/${file})
79+
else()
80+
sampgdk_append_property(SAMPGDK_HEADERS ${file})
81+
endif()
82+
endforeach()
83+
endmacro()
84+
85+
macro(sampgdk_get_headers var)
86+
sampgdk_get_property(SAMPGDK_HEADERS ${var})
87+
endmacro()
88+
89+
macro(sampgdk_add_libraries)
90+
foreach(library ${ARGN})
91+
sampgdk_append_property(SAMPGDK_LIBRARIES ${library})
92+
endforeach()
93+
endmacro()
94+
95+
macro(sampgdk_get_libraries var)
96+
sampgdk_get_property(SAMPGDK_LIBRARIES ${var})
97+
endmacro()
98+
99+
macro(sampgdk_add_api_gen module_name idl_file api_file)
100+
add_custom_command(
101+
OUTPUT ${api_file}
102+
COMMAND ${PYTHON_EXECUTABLE}
103+
${CMAKE_CURRENT_BINARY_DIR}/scripts/python_wrapper.py
104+
${PROJECT_SOURCE_DIR}/scripts/generate_code.py
105+
--module=${module_name}
106+
--idl=${idl_file}
107+
--api=${api_file}
108+
DEPENDS ${idl_file} ${PROJECT_SOURCE_DIR}/scripts/generate_code.py)
109+
sampgdk_add_sources(${api_file})
110+
endmacro()
111+
112+
macro(sampgdk_add_source_gen module_name idl_file source_file)
113+
add_custom_command(
114+
OUTPUT ${source_file}
115+
COMMAND ${PYTHON_EXECUTABLE}
116+
${CMAKE_CURRENT_BINARY_DIR}/scripts/python_wrapper.py
117+
${PROJECT_SOURCE_DIR}/scripts/generate_code.py
118+
--module=${module_name}
119+
--idl=${idl_file}
120+
--source=${source_file}
121+
DEPENDS ${idl_file} ${PROJECT_SOURCE_DIR}/scripts/generate_code.py)
122+
sampgdk_add_sources(${source_file})
123+
endmacro()
124+
125+
macro(sampgdk_add_header_gen module_name idl_file header_file)
126+
add_custom_command(
127+
OUTPUT ${header_file}
128+
COMMAND ${PYTHON_EXECUTABLE}
129+
${CMAKE_CURRENT_BINARY_DIR}/scripts/python_wrapper.py
130+
${PROJECT_SOURCE_DIR}/scripts/generate_code.py
131+
--module=${module_name}
132+
--idl=${idl_file}
133+
--header=${header_file}
134+
DEPENDS ${idl_file} ${PROJECT_SOURCE_DIR}/scripts/generate_code.py)
135+
sampgdk_add_headers(${header_file})
136+
endmacro()
137+
138+
macro(sampgdk_add_init_gen target list_file source_file)
139+
add_custom_target(
140+
${target}
141+
COMMAND ${PYTHON_EXECUTABLE}
142+
${PROJECT_SOURCE_DIR}/scripts/generate_init.py
143+
--list=${list_file}
144+
--source=${source_file}
145+
DEPENDS ${list_file} ${PROJECT_SOURCE_DIR}/scripts/generate_init.py)
146+
sampgdk_add_sources(${source_file})
147+
endmacro()
148+
149+
macro(sampgdk_add_exports_gen format output_file)
150+
add_custom_command(
151+
OUTPUT ${output_file}
152+
COMMAND ${PYTHON_EXECUTABLE}
153+
${PROJECT_SOURCE_DIR}/scripts/generate_exports.py
154+
--format=${format}
155+
--output=${output_file}
156+
${ARGN}
157+
DEPENDS ${ARGN} ${PROJECT_SOURCE_DIR}/scripts/generate_exports.py)
158+
endmacro()
159+
160+
add_subdirectory(cmake)
161+
if(SAMPGDK_BUILD_DOCS)
162+
add_subdirectory(doc)
163+
endif()
164+
add_subdirectory(include)
165+
add_subdirectory(lib)
166+
if(SAMPGDK_BUILD_PLUGINS)
167+
add_subdirectory(plugins)
168+
endif()
169+
add_subdirectory(scripts)
170+
171+
sampgdk_get_sources(SAMPGDK_SOURCES)
172+
173+
foreach(file IN LISTS SAMPGDK_SOURCES)
174+
get_filename_component(extension ${file} EXT)
175+
176+
if(extension STREQUAL ".idl")
177+
file(RELATIVE_PATH path ${PROJECT_SOURCE_DIR}/lib/sampgdk ${file})
178+
179+
get_filename_component(dir ${path} PATH)
180+
get_filename_component(name ${file} NAME_WE)
181+
182+
sampgdk_add_api_gen(${name} ${file}
183+
${PROJECT_BINARY_DIR}/lib/sampgdk/${dir}/${name}.api)
184+
sampgdk_add_source_gen(${name} ${file}
185+
${PROJECT_BINARY_DIR}/lib/sampgdk/${dir}/${name}.c)
186+
sampgdk_add_header_gen(${name} ${file}
187+
${PROJECT_BINARY_DIR}/include/sampgdk/${dir}/${name}.h)
188+
189+
list(APPEND SAMPGDK_IDLS ${file})
190+
endif()
191+
endforeach()
192+
193+
sampgdk_get_sources(SAMPGDK_SOURCES)
194+
195+
foreach(file IN LISTS SAMPGDK_SOURCES)
196+
get_filename_component(extension ${file} EXT)
197+
if(extension STREQUAL ".api")
198+
list(APPEND SAMPGDK_APIS ${file})
199+
endif()
200+
endforeach()
201+
202+
sampgdk_get_property(SAMPGDK_DEF_FILE SAMPGDK_DEF_FILE)
203+
if(SAMPGDK_DEF_FILE)
204+
sampgdk_add_exports_gen("def" ${SAMPGDK_DEF_FILE} ${SAMPGDK_APIS})
205+
endif()
206+
207+
sampgdk_get_property(SAMPGDK_SYM_FILE SAMPGDK_SYM_FILE)
208+
if(SAMPGDK_SYM_FILE)
209+
sampgdk_add_exports_gen("list" ${SAMPGDK_SYM_FILE} ${SAMPGDK_APIS})
210+
endif()
211+
212+
sampgdk_get_sources(SAMPGDK_SOURCES)
213+
sampgdk_get_headers(SAMPGDK_HEADERS)
214+
215+
list(REMOVE_ITEM SAMPGDK_SOURCES ${SAMPGDK_IDLS})
216+
217+
if(SAMPGDK_STATIC)
218+
add_library(sampgdk STATIC ${SAMPGDK_HEADERS} ${SAMPGDK_SOURCES})
219+
else()
220+
add_library(sampgdk SHARED ${SAMPGDK_HEADERS} ${SAMPGDK_SOURCES})
221+
endif()
222+
223+
get_target_property(SAMPGDK_OUTPUT_NAME sampgdk OUTPUT_NAME)
224+
225+
if(NOT SAMPGDK_OUTPUT_NAME)
226+
set(SAMPGDK_OUTPUT_NAME sampgdk)
227+
endif()
228+
229+
if(WIN32)
230+
set(SAMPGDK_OUTPUT_NAME ${SAMPGDK_OUTPUT_NAME}${SAMPGDK_VERSION_MAJOR})
231+
if(SAMPGDK_STATIC)
232+
set(SAMPGDK_OUTPUT_NAME ${SAMPGDK_OUTPUT_NAME}s)
233+
endif()
234+
endif()
235+
236+
set_target_properties(sampgdk PROPERTIES
237+
VERSION ${SAMPGDK_VERSION}
238+
SOVERSION ${SAMPGDK_VERSION_MAJOR}
239+
DEFINE_SYMBOL IN_SAMPGDK
240+
OUTPUT_NAME ${SAMPGDK_OUTPUT_NAME}
241+
DEBUG_POSTFIX d
242+
)
243+
244+
if(SAMPGDK_STATIC)
245+
target_compile_definitions(sampgdk PUBLIC SAMPGDK_STATIC)
246+
endif()
247+
248+
if(WIN32)
249+
target_compile_definitions(sampgdk PRIVATE WIN32_LEAN_AND_MEAN)
250+
elseif(UNIX)
251+
target_compile_definitions(sampgdk PRIVATE _GNU_SOURCE)
252+
endif()
253+
254+
if(MSVC)
255+
target_compile_definitions(sampgdk PRIVATE _CRT_SECURE_NO_WARNINGS)
256+
endif()
257+
258+
if(UNIX)
259+
target_compile_options(sampgdk PRIVATE -m32 -fvisibility=hidden)
260+
if(NOT SAMPGDK_STATIC)
261+
target_link_libraries(sampgdk PRIVATE
262+
-m32 -Wl,--no-undefined,--retain-symbols-file=${SAMPGDK_SYM_FILE})
263+
endif()
264+
endif()
265+
266+
if(UNIX)
267+
sampgdk_add_libraries(${CMAKE_DL_LIBS} rt)
268+
endif()
269+
270+
sampgdk_get_libraries(SAMPGDK_LIBRARIES)
271+
272+
if(SAMPGDK_STATIC)
273+
target_link_libraries(sampgdk INTERFACE ${SAMPGDK_LIBRARIES})
274+
else()
275+
target_link_libraries(sampgdk PRIVATE ${SAMPGDK_LIBRARIES})
276+
endif()
277+
278+
if(SAMPGDK_BUILD_AMALGAMATION)
279+
foreach(file IN LISTS SAMPGDK_SOURCES)
280+
if (file MATCHES ".*\\.c" OR file MATCHES ".*\\.h")
281+
list(APPEND SAMPGDK_AMALGAMATE_FLAGS --source "${file}")
282+
endif()
283+
endforeach()
284+
foreach(file IN LISTS SAMPGDK_HEADERS)
285+
if (file MATCHES ".*\\.h")
286+
list(APPEND SAMPGDK_AMALGAMATE_FLAGS --header "${file}")
287+
endif()
288+
endforeach()
289+
290+
add_custom_target(sampgdk_amalgamate ALL
291+
COMMAND ${PYTHON_EXECUTABLE}
292+
${PROJECT_SOURCE_DIR}/scripts/amalgamate.py
293+
--include-dir ${PROJECT_SOURCE_DIR}/include
294+
--include-dir ${PROJECT_BINARY_DIR}/include
295+
--include-dir ${PROJECT_SOURCE_DIR}/lib/sampgdk
296+
--output-source ${PROJECT_BINARY_DIR}/lib/sampgdk/sampgdk.c
297+
--output-header ${PROJECT_BINARY_DIR}/lib/sampgdk/sampgdk.h
298+
--source-preamble ${PROJECT_SOURCE_DIR}/lib/sampgdk/sampgdk.c
299+
--header-preamble ${PROJECT_SOURCE_DIR}/lib/sampgdk/sampgdk.h
300+
${SAMPGDK_AMALGAMATE_FLAGS}
301+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
302+
COMMENT "Generating amalgamation")
303+
add_dependencies(sampgdk_amalgamate sampgdk)
304+
305+
add_custom_target(sampgdk_amalgamate_package ALL
306+
COMMAND ${PYTHON_EXECUTABLE}
307+
${PROJECT_SOURCE_DIR}/scripts/zip.py
308+
${PROJECT_BINARY_DIR}/sampgdk-${SAMPGDK_VERSION}-amalgamation.zip
309+
${PROJECT_BINARY_DIR}/lib/sampgdk/sampgdk.c
310+
${PROJECT_BINARY_DIR}/lib/sampgdk/sampgdk.h
311+
${PROJECT_SOURCE_DIR}/doc/how-to-use-amalgamation.txt
312+
COMMENT "Packaging amalgamation files")
313+
add_dependencies(sampgdk_amalgamate_package sampgdk_amalgamate)
314+
endif()
315+
316+
add_dependencies(sampgdk sampgdk_init)
317+
318+
foreach(header IN LISTS SAMPGDK_HEADERS)
319+
get_filename_component(path ${header} PATH)
320+
get_filename_component(abs_path ${path} ABSOLUTE)
321+
322+
string(FIND ${abs_path} ${PROJECT_BINARY_DIR} pos)
323+
if(pos LESS 0)
324+
file(RELATIVE_PATH dir ${PROJECT_SOURCE_DIR} ${abs_path})
325+
else()
326+
file(RELATIVE_PATH dir ${PROJECT_BINARY_DIR} ${abs_path})
327+
endif()
328+
329+
install(FILES ${header} DESTINATION ${dir} COMPONENT dev)
330+
endforeach()
331+
332+
install(TARGETS sampgdk RUNTIME DESTINATION bin COMPONENT bin
333+
ARCHIVE DESTINATION lib COMPONENT dev
334+
LIBRARY DESTINATION lib COMPONENT bin)
335+
336+
if(WIN32)
337+
set(CPACK_PACKAGE_FILE_NAME sampgdk-${SAMPGDK_VERSION}-win32)
338+
set(CPACK_GENERATOR ZIP)
339+
elseif(UNIX)
340+
set(CPACK_PACKAGE_FILE_NAME sampgdk-${SAMPGDK_VERSION}-linux)
341+
set(CPACK_GENERATOR TGZ)
342+
endif()
343+
344+
if(SAMPGDK_STATIC)
345+
set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_FILE_NAME}-static)
346+
endif()
347+
348+
include(CPack)

0 commit comments

Comments
 (0)