Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CMakeLists.txt « overlay_gl - github.com/mumble-voip/mumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4beb157b3587001afc3780b42ab16f63a5725989 (plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# Copyright 2020-2022 The Mumble Developers. All rights reserved.
# Use of this source code is governed by a BSD-style license
# that can be found in the LICENSE file at the root of the
# Mumble source tree or at <https://www.mumble.info/LICENSE>.

# Overlay payload for UNIX-like systems.

include(CheckIncludeFile)

if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64")
	if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD")
		option(overlay-xcompile "Build 32 bit overlay library, necessary for the overlay to work with 32 bit processes." ON)
	endif()
endif()

add_library(overlay_gl SHARED "overlay.c")

set_target_properties(overlay_gl
	PROPERTIES
		LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
		OUTPUT_NAME "mumbleoverlay"
		VERSION ${CMAKE_PROJECT_VERSION}
)

if(NOT APPLE)
	find_pkg(gl REQUIRED)
	target_include_directories(overlay_gl PRIVATE ${gl_INCLUDE_DIRS})

	target_link_options(overlay_gl BEFORE
		PRIVATE
			"-Wl,-z,lazy"
	)

	set_target_properties(overlay_gl
		PROPERTIES
			COMPILE_DEFINITIONS
				"TARGET_UNIX"
	)

	if(overlay-xcompile)
		# Just check for this header file while using a 32bit target as a really small and incomplete check whether g++-multilib seems to be
		# installed. If we don't find it, we can assume it's not there but if we do find it, we still don't know. Thus we still print the
		# message about the 32bit target potentially failing due to missing g++-multilib.
		CHECK_INCLUDE_FILE("sys/cdefs.h" FOUND_CDEFS "-m32")
		if(NOT FOUND_CDEFS)
			message(FATAL_ERROR "Can't find the 32bit version of sys/cdefs.h - did you install g++-multilib?")
		else()
			message(STATUS "\nIf the 32 bit overlay library fails to compile, make sure the requirements are installed (\"g++-multilib\" package on Debian-based distributions).\n")
		endif()

		set_target_properties(overlay_gl
			PROPERTIES
				OUTPUT_NAME "mumbleoverlay.x86_64"
		)

		add_library(overlay_gl_x86 SHARED "overlay.c")

		target_compile_definitions(overlay_gl_x86
			PRIVATE
				"TARGET_UNIX"
		)

		target_compile_options(overlay_gl_x86
			PRIVATE
				"-m32"
		)

		# Linking the overlay library with '-z now' requires all target processes to have libGL symbols in them at load time.
		# If it doesn't, the program will not start at all.
		#
		# Instead, explicitly use '-z lazy' to defer libGL symbol resolution until first use, which is never for non-libGL users.
		target_link_options(overlay_gl_x86 BEFORE
			PRIVATE
				"-m32"
				"-Wl,-z,lazy"
		)

		set_target_properties(overlay_gl_x86
			PROPERTIES
				LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
				OUTPUT_NAME "mumbleoverlay.x86"
				VERSION ${CMAKE_PROJECT_VERSION}
		)
	endif()

	if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
		target_link_libraries(overlay_gl
			PRIVATE
				"-ldl"
				"-lrt"
		)

		if(TARGET overlay_gl_x86)
			target_link_libraries(overlay_gl_x86
				PRIVATE
					"-ldl"
					"-lrt"
			)
			# install 32bit overlay library
			install(TARGETS overlay_gl_x86 LIBRARY DESTINATION "${MUMBLE_INSTALL_LIBDIR}")
		endif()
	endif()
else()
	add_subdirectory("${3RDPARTY_DIR}/mach-override-build" "${CMAKE_CURRENT_BINARY_DIR}/mach-override")

	find_library(LIB_COREFOUNDATION "CoreFoundation")

	target_compile_definitions(overlay_gl
		PRIVATE
			"TARGET_MAC"
	)
	target_compile_options(overlay_gl
		PRIVATE
			"-ObjC"
	)
	target_sources(overlay_gl
		PRIVATE
			"avail_mac.h"
			"overlay_gl.plist"
	)
	target_link_libraries(overlay_gl
		PRIVATE
			"-undefined dynamic_lookup" # Defer libGL symbol resolution until first use, which is never for non-libGL users.
			mach-override
			${LIB_COREFOUNDATION}
	)
endif()

# install native overlay library
install(TARGETS overlay_gl LIBRARY DESTINATION "${MUMBLE_INSTALL_LIBDIR}")

# install overlay script
install(PROGRAMS "${CMAKE_SOURCE_DIR}/scripts/mumble-overlay" DESTINATION "${MUMBLE_INSTALL_SCRIPTDIR}")

# install overlay man-files
install(FILES "${CMAKE_SOURCE_DIR}/man/mumble-overlay.1" DESTINATION "${MUMBLE_INSTALL_MANDIR}" COMPONENT doc)