5ef6db722ad01d876772623932376593297cf8d0
[xonotic/xonotic-data.pk3dir.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
2 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
3 project(xonotic-data ASM)
4
5 set(checks qc-checks)
6 add_custom_target(${checks})
7
8 # depend on qcc
9 if (TARGET gmqcc)
10     add_dependencies(${checks} gmqcc)
11 endif ()
12
13 add_dependencies(${checks} data-check-cvars)
14 add_custom_target(data-check-cvars
15         COMMENT "checking cvars"
16         WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
17         VERBATIM COMMAND ${CMAKE_COMMAND} -E
18         env "CMAKE=1"
19         "${PROJECT_SOURCE_DIR}/check-cvars.sh"
20         )
21
22 add_dependencies(${checks} qc-genmod)
23 add_custom_target(qc-genmod
24         COMMENT "genmod.sh"
25         WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/qcsrc"
26         VERBATIM COMMAND ./tools/genmod.sh
27         )
28
29 add_dependencies(${checks} qc-headerstyle)
30 add_custom_target(qc-headerstyle
31         COMMENT "headerstyle.sh"
32         WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/qcsrc"
33         VERBATIM COMMAND ${CMAKE_COMMAND} -E
34         env "VERBOSE=0"
35         ./tools/headerstyle.sh
36         )
37
38 add_dependencies(${checks} qc-whitespace)
39 add_custom_target(qc-whitespace
40         COMMENT "whitespace.sh"
41         WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/qcsrc"
42         VERBATIM COMMAND ./tools/whitespace.sh
43         )
44
45 include_directories(qcsrc)
46
47 add_definitions(-DXONOTIC=1)
48 add_definitions(-DNDEBUG=1)
49 add_definitions(-DENABLE_EFFECTINFO=0)
50 add_definitions(-DENABLE_DEBUGDRAW=0)
51 add_definitions(-DENABLE_DEBUGTRACE=0)
52
53 if (DEFINED ENV{VERSION})
54     set(GIT_DESC "$ENV{VERSION}")
55 else ()
56     find_package(Git REQUIRED)
57     execute_process(
58             COMMAND ${GIT_EXECUTABLE} describe --tags --dirty=~
59             WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
60             OUTPUT_VARIABLE GIT_DESC
61             OUTPUT_STRIP_TRAILING_WHITESPACE
62     )
63 endif ()
64 add_definitions(-DWATERMARK=\"${GIT_DESC}\")
65
66 set_source_files_properties(
67         qcsrc/client/progs.inc
68         qcsrc/server/progs.inc
69         qcsrc/menu/progs.inc
70         PROPERTIES
71         LANGUAGE ASM
72         HEADER_FILE_ONLY FALSE
73 )
74
75 add_executable(csprogs qcsrc/client/progs.inc)
76 add_dependencies(csprogs ${checks})
77 target_compile_definitions(csprogs PRIVATE -DGAMEQC -DCSQC)
78
79 add_executable(progs qcsrc/server/progs.inc)
80 add_dependencies(progs ${checks})
81 target_compile_definitions(progs PRIVATE -DGAMEQC -DSVQC)
82
83 add_executable(menu qcsrc/menu/progs.inc)
84 add_dependencies(menu ${checks})
85 target_compile_definitions(menu PRIVATE -DMENUQC)
86
87 function(set_prelude target prelude)
88     get_target_property(MY_PROJECT_SOURCES target SOURCES)
89     foreach (source IN LISTS MY_PROJECT_SOURCES)
90         set_property(
91                 SOURCE ${source}
92                 APPEND PROPERTY COMPILE_FLAGS
93                 "-include ${PROJECT_SOURCE_DIR}/${prelude}"
94         )
95     endforeach ()
96 endfunction()
97 # set_prelude(csprogs qcsrc/lib/_all.inc)
98
99 function(copy prog)
100     add_custom_command(TARGET ${prog} POST_BUILD
101             COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE_DIR:${prog}>/${prog}.dat" "${prog}.dat"
102             COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE_DIR:${prog}>/${prog}.lno" "${prog}.lno"
103             WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
104             VERBATIM)
105 endfunction()
106 copy(csprogs)
107 copy(progs)
108 copy(menu)
109
110 function(pack prog)
111     add_custom_target(${prog}.pk3
112             DEPENDS ${prog}-${GIT_DESC}.pk3
113             )
114     add_custom_command(OUTPUT ${prog}-${GIT_DESC}.pk3
115             DEPENDS ${prog}
116             COMMAND ${CMAKE_COMMAND} -E echo "http://xonotic.org" > "${prog}-${GIT_DESC}.txt"
117             COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE_DIR:${prog}>/${prog}.dat" "${prog}-${GIT_DESC}.dat"
118             COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE_DIR:${prog}>/${prog}.lno" "${prog}-${GIT_DESC}.lno"
119             COMMAND ${CMAKE_COMMAND} -E tar "cfv" "${prog}-${GIT_DESC}.pk3" --format=zip
120             "${prog}-${GIT_DESC}.txt"
121             "${prog}-${GIT_DESC}.dat"
122             "${prog}-${GIT_DESC}.lno"
123             VERBATIM
124             )
125 endfunction()
126 pack(csprogs)