diff dep/animia/CMakeLists.txt @ 202:71832ffe425a

animia: re-add kvm fd source this is all being merged from my wildly out-of-date laptop. SORRY! in other news, I edited the CI file to install the wayland client as well, so the linux CI build might finally get wayland stuff.
author Paper <paper@paper.us.eu.org>
date Tue, 02 Jan 2024 06:05:06 -0500
parents 8f6f8dd2eb23 9f3534f6b8c4
children 8a482049b968
line wrap: on
line diff
--- a/dep/animia/CMakeLists.txt	Sun Nov 19 19:13:28 2023 -0500
+++ b/dep/animia/CMakeLists.txt	Tue Jan 02 06:05:06 2024 -0500
@@ -28,23 +28,24 @@
 	check_include_file("CoreFoundation/CoreFoundation.h" HAVE_COREFOUNDATION)
 	# If you're building on OS X, you most likely do have this file, but we
 	# check anyway.
-	if (HAVE_COREFOUNDATION)
+	if(HAVE_COREFOUNDATION)
 		list(APPEND DEFINES HAVE_COREFOUNDATION)
-	endif()
+		find_library(OBJC_LIBRARY objc)
 
-	check_language(OBJCXX)
-	if(CMAKE_OBJCXX_COMPILER)
-		enable_language(OBJCXX)
-		list(APPEND SRC_FILES
-			src/win/quartz.mm
-		)
+		if(NOT OBJC_LIBRARY)
+			message(STATUS "Found CoreFoundation/CoreFoundation.h, but not the Objective-C runtime. How?")
+		endif()
+
+		list(APPEND SRC_FILES src/win/quartz.cc)
+
 		find_library(FOUNDATION_LIBRARY Foundation)
 		find_library(COREGRAPHICS_LIBRARY CoreGraphics)
 		find_library(APPKIT_LIBRARY AppKit)
-		list(APPEND LIBRARIES ${FOUNDATION_LIBRARY} ${COREGRAPHICS_LIBRARY} ${APPKIT_LIBRARY})
-	else() # NOT CMAKE_OBJCXX_COMPILER
-		message(WARNING "An Objective-C++ compiler couldn't be found! Window enumeration support will not be compiled.")
-	endif() # CMAKE_OBJCXX_COMPILER
+		list(APPEND LIBRARIES ${FOUNDATION_LIBRARY} ${COREGRAPHICS_LIBRARY} ${APPKIT_LIBRARY} ${OBJC_LIBRARY})
+	else() # NOT HAVE_COREFOUNDATION
+		message(STATUS "You don't have Core Foundation. How? What kind of voodoo magic did you do to cause this?")
+		message(WARNING "LaunchServices support will not be compiled.")
+	endif() # HAVE_COREFOUNDATION
 elseif(WIN32)
 	list(APPEND DEFINES WIN32)
 	list(APPEND SRC_FILES
@@ -59,9 +60,7 @@
 
 	if(LINUX)
 		list(APPEND DEFINES LINUX)
-		list(APPEND SRC_FILES
-			src/fd/proc.cc
-		)
+		list(APPEND SRC_FILES src/fd/proc.cc)
 	elseif(LIBUTIL_LIBRARY) # FreeBSD's libutil
 		get_filename_component(LIBUTIL_DIR ${LIBUTIL_LIBRARY} DIRECTORY)
 
@@ -74,30 +73,35 @@
 			list(APPEND SRC_FILES src/fd/libutil.cc)
 		endif() # LIBUTIL_GOOD
 	elseif(LIBKVM_LIBRARY) # OpenBSD kvm
-		include(CheckSymbolExists)
-		# Check if we can get open files by PID
-		check_symbol_exists(KERN_FILE_BYPID "kvm.h" HAVE_BYPID)
+		list(APPEND LIBRARIES ${LIBKVM_LIBRARY})
+		list(APPEND DEFINES LIBKVM)
+		list(APPEND SRC_FILES src/fd/kvm.cc)
+
+		get_filename_component(LIBKVM_DIR ${LIBKVM_LIBRARY} DIRECTORY)
 
-		if(HAVE_BYPID)
-			list(APPEND LIBRARIES ${LIBKVM_LIBRARY})
-			list(APPEND DEFINES LIBKVM)
-			list(APPEND SRC_FILES src/fd/kvm.cc)
-		endif() # LIBUTIL_GOOD
+		include(CheckLibraryExists)
+		check_library_exists(kvm kvm_getfiles ${LIBKVM_DIR} LIBKVM_HAS_GETFILES)
+
+		if(LIBKVM_HAS_GETFILES)
+			list(APPEND DEFINES HAVE_KVM_GETFILES)
+		endif() # LIBKVM_HAS_GETFILES
 	endif() # LINUX
 
 	# X11
-	find_package(X11 COMPONENTS X11)
+	find_package(X11 COMPONENTS X11 XRes)
+
 	if(X11_FOUND)
+		# Getting PIDs from windows...
+		if (X11_XRes_FOUND)
+			list(APPEND DEFINES HAVE_XRES)
+		else() # NOT X11_XRes_FOUND
+			message(WARNING "libXRes could not be found! Finding PIDs in X11 windows may not work correctly!")
+		endif() # X11_XRes_FOUND
+
 		list(APPEND DEFINES X11)
-		list(APPEND SRC_FILES
-			src/win/x11.cc
-		)
-		list(APPEND INCLUDE_DIRS
-			${X11_INCLUDE_DIRS}
-		)
-		list(APPEND LIBRARIES
-			${X11_LIBRARIES}
-		)
+		list(APPEND SRC_FILES src/win/x11.cc)
+		list(APPEND INCLUDE_DIRS ${X11_INCLUDE_DIRS})
+		list(APPEND LIBRARIES ${X11_LIBRARIES}) # This will include Xres, I think..
 	else() # NOT X11_FOUND
 		# For some systems, i.e. Debian, FindX11 fails to find X11, so we have
 		# to use pkg_config as a fallback
@@ -105,19 +109,40 @@
 		if(PKG_CONFIG_FOUND)
 			pkg_check_modules(X11 x11)
 			if(X11_FOUND)
+				# Check for XRes the hard way
+				find_path(X11_XRes_HEADER "X11/extensions/XRes.h" PATHS ${X11_INCLUDE_DIRS})
+				find_library(X11_XRes_LIB XRes PATHS ${X11_LIBRARY_DIRS})
+
+				if(X11_XRes_HEADER AND X11_XRes_LIB)
+					# TODO: We should REALLY check for XResQueryClientIds here...
+					list(APPEND DEFINES HAVE_XRES)
+					list(APPEND LIBRARIES ${X11_XRes_LIB})
+				else()
+					message(WARNING "libXRes could not be found! Finding PIDs in X11 windows may not work correctly!")
+				endif()
+
 				list(APPEND DEFINES X11)
-				list(APPEND SRC_FILES
-					src/win/x11.cc
-				)
-				list(APPEND INCLUDE_DIRS
-					${X11_INCLUDE_DIRS}
-				)
-				list(APPEND LIBRARIES
-					${X11_LINK_LIBRARIES}
-				)
+				list(APPEND SRC_FILES src/win/x11.cc)
+				list(APPEND INCLUDE_DIRS ${X11_INCLUDE_DIRS})
+				list(APPEND LIBRARIES ${X11_LINK_LIBRARIES})
 			endif() # X11_FOUND
 		endif() # PKG_CONFIG_FOUND
 	endif() # X11_FOUND
+
+	find_package(PkgConfig)
+	if(PKG_CONFIG_FOUND)
+		pkg_check_modules(WAYLAND wayland-client)
+		if(WAYLAND_FOUND)
+			enable_language(C)
+			list(APPEND DEFINES WAYLAND)
+			list(APPEND SRC_FILES
+				src/win/wayland.cc
+				src/win/wayland/ext-foreign-toplevel-list-v1.c
+			)
+			list(APPEND INCLUDE_DIRS ${WAYLAND_INCLUDE_DIRS})
+			list(APPEND LIBRARIES ${WAYLAND_LINK_LIBRARIES})
+		endif() # WAYLAND_FOUND
+	endif() # PKG_CONFIG_FOUND
 endif() # WIN32 AND APPLE
 
 add_library(animia SHARED ${SRC_FILES})
@@ -126,6 +151,6 @@
 	CXX_STANDARD 17
 )
 
-target_compile_definitions(animia PUBLIC ${DEFINES})
+target_compile_definitions(animia PRIVATE ${DEFINES})
 target_include_directories(animia PUBLIC include PRIVATE ${INCLUDE_DIRS})
 target_link_libraries(animia PUBLIC ${LIBRARIES})