aboutsummaryrefslogtreecommitdiff
path: root/src/scripts/CMakeLists.txt
blob: 771f32d54f38c1e1343a391511dcd05774740a41 (about) (plain) (blame)
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
#
# InspIRCd -- Internet Relay Chat Daemon
#
#   Copyright (C) 2026 Sadie Powell <sadie@witchery.services>
#
# This file is part of InspIRCd.  InspIRCd is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

if(CMAKE_CURRENT_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
	message(FATAL_ERROR "You must run CMake using the CMakeLists.txt in the root directory!")
endif()

function(configure_script FILE DIR TYPE)
	file(STRINGS "${FILE}.in" LINES)
	foreach(FILE_LINE IN LISTS LINES)
		if(FILE_LINE MATCHES "^([\t ]*)%([a-z]+) +([^ ]+) *(.*)\r?$")
			if(CMAKE_MATCH_2 STREQUAL "ifdef" AND ${${CMAKE_MATCH_3}})
				string(APPEND PROCESSED_LINES "${CMAKE_MATCH_1}${CMAKE_MATCH_4}\n")
			elseif(CMAKE_MATCH_2 STREQUAL "ifndef" AND NOT ${${CMAKE_MATCH_3}})
				string(APPEND PROCESSED_LINES "${CMAKE_MATCH_1}${CMAKE_MATCH_4}\n")
			endif()
		else()
			string(APPEND PROCESSED_LINES "${FILE_LINE}\n")
		endif()
	endforeach()

	file(CONFIGURE
		CONTENT "${PROCESSED_LINES}"
		OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FILE}"
		@ONLY
	)
	install_owned(
		${TYPE} "${CMAKE_CURRENT_BINARY_DIR}/${FILE}"
		DESTINATION ${DIR}
		${ARGN}
	)
endfunction()

configure_script("help.txt" ${CONFIG_DIR} FILES)

if(NOT WIN32)
	configure_script("deploy-tls.sh"       ${SCRIPT_DIR} PROGRAMS)
	configure_script("inspircd"            ${SCRIPT_DIR} PROGRAMS)
	configure_script("inspircd-test-tls.1" ${MANUAL_DIR} FILES)
	configure_script("inspircd.1"          ${MANUAL_DIR} FILES)
	configure_script("logrotate"           ${SCRIPT_DIR} FILES)
	if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
		configure_script("org.inspircd.plist" ${SCRIPT_DIR} FILES)
	elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
		configure_script("apparmor"         ${SCRIPT_DIR} FILES)
		configure_script("inspircd.openrc"  ${SCRIPT_DIR} PROGRAMS)
		configure_script("inspircd.service" ${SCRIPT_DIR} FILES)
	endif()
endif()