view dep/animia/CMakeLists.txt @ 187:9613d72b097e

*: multiple performance improvements like marking `static const` when it makes sense... date: change old stupid heap-based method to a structure which should make copying the thing actually make a copy. also many performance-based changes, like removing the std::tie dependency and forward-declaring nlohmann json *: replace every instance of QString::fromUtf8 to Strings::ToQString. the main difference is that our function will always convert exactly what is in the string, while some other times it would only convert up to the nearest NUL byte
author Paper <mrpapersonic@gmail.com>
date Wed, 06 Dec 2023 13:43:54 -0500
parents c413e475f496
children 649786bae914
line wrap: on
line source

cmake_minimum_required(VERSION 3.16)
project(animia LANGUAGES CXX)
set(SRC_FILES
	# any non-platform-specific files go here
	src/animia.cc
	src/player.cc
	src/util.cc
	src/strategist.cc
	src/fd.cc
	src/win.cc
)

include(CheckLanguage)

set(LIBRARIES)
set(INCLUDE_DIRS)
set(DEFINES)

if(APPLE)
	list(APPEND DEFINES MACOSX)
	list(APPEND SRC_FILES
		# xnu stuff
		src/fd/xnu.cc
		src/util/osx.cc
	)

	include(CheckIncludeFile)
	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)
		list(APPEND DEFINES HAVE_COREFOUNDATION)

		find_library(FOUNDATION_LIBRARY Foundation)
		list(APPEND LIBRARIES ${FOUNDATION_LIBRARY})
	else()
		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()

	check_language(OBJCXX)
	if(CMAKE_OBJCXX_COMPILER)
		enable_language(OBJCXX)
		list(APPEND SRC_FILES
			src/win/quartz.mm
		)

		# we likely already have Foundation at this point.
		find_library(COREGRAPHICS_LIBRARY CoreGraphics)
		find_library(APPKIT_LIBRARY AppKit)
		list(APPEND LIBRARIES ${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
elseif(WIN32)
	list(APPEND DEFINES WIN32)
	list(APPEND SRC_FILES
		# win32
		src/fd/win32.cc
		src/win/win32.cc
		src/util/win32.cc
	)
else() # NOT WIN32 AND NOT APPLE
	find_library(LIBUTIL_LIBRARY util)
	find_library(LIBKVM_LIBRARY kvm)

	if(LINUX)
		list(APPEND DEFINES LINUX)
		list(APPEND SRC_FILES
			src/fd/proc.cc
		)
	elseif(LIBUTIL_LIBRARY) # FreeBSD's libutil
		get_filename_component(LIBUTIL_DIR ${LIBUTIL_LIBRARY} DIRECTORY)

		include(CheckLibraryExists)
		check_library_exists(util kinfo_getfile ${LIBUTIL_DIR} LIBUTIL_GOOD)

		if(LIBUTIL_GOOD)
			list(APPEND LIBRARIES ${LIBUTIL_LIBRARY})
			list(APPEND DEFINES LIBUTIL)
			list(APPEND SRC_FILES src/fd/libutil.cc)
		endif() # LIBUTIL_GOOD
	elseif(LIBKVM_LIBRARY) # BSD libkvm
		get_filename_component(LIBKVM_DIR ${LIBKVM_LIBRARY} DIRECTORY)

		include(CheckLibraryExists)
		check_library_exists(kvm kvm_getprocs ${LIBKVM_DIR} LIBKVM_GOOD)

		if(LIBKVM_GOOD)
			list(APPEND LIBRARIES ${LIBKVM_LIBRARY})
			list(APPEND DEFINES LIBKVM)
			list(APPEND SRC_FILES src/fd/libkvm.cc)
		endif() # LIBUTIL_GOOD
	endif() # LINUX

	# X11
	find_package(X11 COMPONENTS X11)
	if(X11_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}
		)
	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
		find_package(PkgConfig)
		if(PKG_CONFIG_FOUND)
			pkg_check_modules(X11 x11)
			if(X11_FOUND)
				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}
				)
			endif() # X11_FOUND
		endif() # PKG_CONFIG_FOUND
	endif() # X11_FOUND
endif() # WIN32 AND APPLE

add_library(animia SHARED ${SRC_FILES})
set_target_properties(animia PROPERTIES
	PUBLIC_HEADER include/animia.h
	CXX_STANDARD 17
)

target_compile_definitions(animia PUBLIC ${DEFINES})
target_include_directories(animia PRIVATE include PUBLIC ${INCLUDE_DIRS})
target_link_libraries(animia PUBLIC ${LIBRARIES})