Merged master
[xonotic/xonotic-data.pk3dir.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.8.11)
2 list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
3 project(xonotic-data LANGUAGES ASM)
4
5 include_directories(qcsrc)
6
7 add_definitions(-DXONOTIC=1)
8 add_definitions(-DNDEBUG=1)
9 add_definitions(-DENABLE_EFFECTINFO=0)
10 add_definitions(-DENABLE_DEBUGDRAW=0)
11 add_definitions(-DENABLE_DEBUGTRACE=0)
12
13 find_package(Git REQUIRED)
14 if (DEFINED ENV{VERSION})
15     set(GIT_DESC "$ENV{VERSION}")
16 else ()
17     execute_process(
18             COMMAND ${GIT_EXECUTABLE} describe --tags --dirty=~
19             WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
20             OUTPUT_VARIABLE GIT_DESC
21             OUTPUT_STRIP_TRAILING_WHITESPACE
22     )
23 endif ()
24 add_definitions(-DWATERMARK=\"${GIT_DESC}\")
25
26 set_source_files_properties(
27         qcsrc/client/progs.inc
28         qcsrc/server/progs.inc
29         qcsrc/menu/progs.inc
30         PROPERTIES
31         LANGUAGE ASM
32         HEADER_FILE_ONLY FALSE
33 )
34
35 add_executable(csprogs qcsrc/client/progs.inc)
36 target_compile_definitions(csprogs PRIVATE -DGAMEQC -DCSQC)
37 if (TARGET gmqcc)
38     add_dependencies(csprogs gmqcc)
39 endif ()
40
41 add_executable(progs qcsrc/server/progs.inc)
42 target_compile_definitions(progs PRIVATE -DGAMEQC -DSVQC)
43 if (TARGET gmqcc)
44     add_dependencies(progs gmqcc)
45 endif ()
46
47 add_executable(menu qcsrc/menu/progs.inc)
48 target_compile_definitions(menu PRIVATE -DMENUQC)
49 if (TARGET gmqcc)
50     add_dependencies(menu gmqcc)
51 endif ()
52
53 function(set_prelude target prelude)
54     get_target_property(MY_PROJECT_SOURCES target SOURCES)
55     foreach (source IN LISTS MY_PROJECT_SOURCES)
56         set_property(
57                 SOURCE ${source}
58                 APPEND PROPERTY COMPILE_FLAGS
59                 "-include ${PROJECT_SOURCE_DIR}/${prelude}"
60         )
61     endforeach ()
62 endfunction()
63 # set_prelude(csprogs qcsrc/lib/_all.inc)
64
65 function(copy prog)
66     add_custom_command(TARGET ${prog} POST_BUILD
67             COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE_DIR:${prog}>/${prog}.dat" "${prog}.dat"
68             COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE_DIR:${prog}>/${prog}.lno" "${prog}.lno"
69             WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
70             VERBATIM)
71 endfunction()
72 copy(csprogs)
73 copy(progs)
74 copy(menu)
75
76 function(pack prog)
77     add_custom_target(${prog}.pk3
78             DEPENDS ${prog}-${GIT_DESC}.pk3
79             )
80     add_custom_command(OUTPUT ${prog}-${GIT_DESC}.pk3
81             DEPENDS ${prog}
82             COMMAND ${CMAKE_COMMAND} -E echo "http://xonotic.org" > "${prog}-${GIT_DESC}.txt"
83             COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE_DIR:${prog}>/${prog}.dat" "${prog}-${GIT_DESC}.dat"
84             COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE_DIR:${prog}>/${prog}.lno" "${prog}-${GIT_DESC}.lno"
85             COMMAND ${CMAKE_COMMAND} -E tar "cfv" "${prog}-${GIT_DESC}.pk3" --format=zip
86             "${prog}-${GIT_DESC}.txt"
87             "${prog}-${GIT_DESC}.dat"
88             "${prog}-${GIT_DESC}.lno"
89             VERBATIM
90             )
91 endfunction()
92 pack(csprogs)