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