CMakeLists.txt 2.78 KB
Newer Older
deuce's avatar
deuce committed
1 2
project (ConIOLib C)

3
cmake_minimum_required(VERSION 3.11)
deuce's avatar
deuce committed
4 5

INCLUDE (CheckFunctionExists)
6 7 8 9 10 11 12 13 14 15 16
find_package(X11)
# So on BSD, this causes the find to fail.  However, it's required for Linux
# This is because on BSD, ncursesw.h does not exist, but libraries use
# ncurses.h
set(CURSES_NEED_WIDE TRUE)
find_package(Threads REQUIRED)
if(NOT WIN32)
	find_package(Curses)
	find_package(PkgConfig)
	pkg_check_modules(SDL2 sdl2)
endif()
deuce's avatar
deuce committed
17 18

set(SOURCE
19
	allfonts.c
deuce's avatar
deuce committed
20 21
	ansi_cio.c
	ciolib.c
22
	ciolib.rc
deuce's avatar
deuce committed
23 24
	cterm.c
	mouse.c
25 26 27 28 29 30 31 32 33 34 35 36 37
	syncicon64.c
	utf8_codepages.c
	vidmodes.c
	xbr.c
)

set(HEADER
	ciolib.h
	cterm.h
	keys.h
	mouse.h
	utf8_codepages.h
	vidmodes.h
deuce's avatar
deuce committed
38 39 40
)

if(WIN32)
41
	list(APPEND SOURCE win32cio.c ciolib.rc)
deuce's avatar
deuce committed
42 43
endif()

44 45 46 47 48 49 50 51 52 53 54 55
if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows")
	if(CURSES_FOUND)
		list(APPEND SOURCE curs_cio.c)
		set(USE_CURSES_ANYWAY TRUE)
	else()
		if(${CMAKE_SYSTEM_NAME} MATCHES "(Free|Open|Net)BSD")
			list(APPEND SOURCE curs_cio.c)
			set(USE_CURSES_ANYWAY TRUE)
		else()
			message(FATAL_ERROR "ncursesw not found")
		endif()
	endif()
deuce's avatar
deuce committed
56 57 58
endif()

if(X11_FOUND)
59 60 61
	list(APPEND SOURCE x_events.c x_cio.c)
	set(NEED_BITMAP TRUE)
	set(NEED_DLOPEN TRUE)
62
	set(NEED_SCALE TRUE)
deuce's avatar
deuce committed
63 64
endif()

65
if(SDL2_INCLUDE_DIRS)
deuce's avatar
deuce committed
66
	list(APPEND SOURCE sdl_con.c)
67
	list(APPEND SOURCE sdlfuncs.c)
68
	set(NEED_SCALE TRUE)
69 70 71
	if(WIN32)
		list(APPEND SOURCE SDL_win32_main.c)
	endif()
72 73
	if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
		list(APPEND SOURCE SDLMain.m)
deuce's avatar
deuce committed
74
	endif()
75 76
	set(NEED_BITMAP TRUE)
	set(NEED_DLOPEN TRUE)
deuce's avatar
deuce committed
77 78 79 80 81 82
endif()

if(NEED_BITMAP)
	list(APPEND SOURCE bitmap_con.c)
endif()

83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
if(NEED_SCALE)
	list(APPEND SOURCE scale.c)
endif()

add_library(ciolib OBJECT ${SOURCE})
target_include_directories(ciolib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
if(CURSES_FOUND)
	if(${CMAKE_SYSTEM_NAME} MATCHES "(Free|Open|Net)BSD")
		list(APPEND SOURCE curs_cio.c)
		set(USE_CURSES_ANYWAY TRUE)
	endif()
endif()

if(X11_FOUND)
	target_include_directories(ciolib PRIVATE ${X11_INCLUDE_DIR})
98
else()
99
	target_compile_definitions(ciolib PRIVATE NO_X)
100
endif()
deuce's avatar
deuce committed
101

102 103
if(SDL2_INCLUDE_DIRS)
	target_include_directories(ciolib PUBLIC ${SDL2_INCLUDE_DIRS})
104
	set(WITH_SDL TRUE PARENT_SCOPE)
Deucе's avatar
Deucе committed
105
	target_compile_definitions(ciolib PUBLIC WITH_SDL)
deuce's avatar
deuce committed
106 107 108 109 110 111
endif()

if(NOT WIN32)
	target_link_libraries(ciolib pthread)
endif()

112 113 114 115 116 117 118 119 120 121 122
if(USE_CURSES_ANYWAY)
	if(CURSES_FOUND)
		if (CURSES_HAVE_NCURSES_NCURSES_H)
			target_compile_definitions(ciolib PRIVATE DEBIAN_HATES_YOU)
		elseif(CURSES_HAVE_NCURSES_H)
			target_compile_definitions(ciolib PRIVATE N_CURSES_LIB)
		endif()
		target_link_libraries(ciolib ${NCURSES_LIBRARIES})
	else()
		target_link_libraries(ciolib ${CURSES_NCURSES_LIBRARY})
		target_link_libraries(ciolib ${CURSES_TINFO_LIBRARY_NAME})
deuce's avatar
deuce committed
123 124 125 126 127 128 129
	endif()
endif()

CHECK_FUNCTION_EXISTS(vasprintf HAVE_VASPRINTF) 
if(HAVE_VASPRINTF)
	target_compile_definitions(ciolib PRIVATE HAVE_VASPRINTF)
endif()
130
target_link_libraries(ciolib hash encode xpdev)