CMakeLists.txt 4.61 KB
Newer Older
1 2
project (XPDev C)

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

INCLUDE (CheckIncludeFiles)
6 7 8 9 10
INCLUDE (CheckFunctionExists)
INCLUDE (FindThreads)
INCLUDE (FindSDL)
INCLUDE (FindX11)
INCLUDE (FindPkgConfig)
deuce's avatar
deuce committed
11

12
option(SDL_AUDIO				"Set to OFF to disable SDL for audio output" ON)
deuce's avatar
deuce committed
13

14
set(SOURCE
deuce's avatar
deuce committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
    conwrap.c
    dat_file.c
    datewrap.c
    dirwrap.c
    filewrap.c
    genwrap.c
    ini_file.c
    link_list.c
    msg_queue.c
    multisock.c
    semwrap.c
    netwrap.c
    sockwrap.c
    semfile.c
    str_list.c
    strwrap.c
    threadwrap.c
    xp_dl.c
    xpbeep.c
    xpdatetime.c
    xpmap.c
    xpprintf.c
)

39 40
if(NOT WIN32)
	list(APPEND SOURCE xpevent.c)
41
    list(APPEND SOURCE xpsem.c)
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
endif()

if(SDL_AUDIO)
	if(SDL_FOUND)
		list(APPEND SOURCE sdlfuncs.c)
		if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
			list(APPEND SOURCE SDLMain.m)
		endif()
		if(WIN32)
			list(APPEND SOURCE SDL_win32_main.c)
		endif()
	endif()
endif()

add_library(xpdev SHARED ${SOURCE})

CHECK_INCLUDE_FILES(inttypes.h HAS_INTTYPES_H)
deuce's avatar
deuce committed
59 60 61 62 63 64 65 66
if(HAS_INTTYPES_H)
    target_compile_definitions(xpdev PUBLIC HAS_INTTYPES_H)
endif()

CHECK_INCLUDE_FILES(sys/soundcard.h HAS_SYS_SOUNDCARD_H) 
CHECK_INCLUDE_FILES(soundcard.h HAS_SOUNDCARD_H) 
CHECK_INCLUDE_FILES(linux/inttypes.h HAS_LINUX_SOUNDCARD_H) 
if(HAS_SYS_SOUNDCARD_H)
67
    target_compile_definitions(xpdev PRIVATE SOUNDCARD_H_IN=1)
deuce's avatar
deuce committed
68
elseif(HAS_SOUNDCARD_H)
69
    target_compile_definitions(xpdev PRIVATE SOUNDCARD_H_IN=2)
deuce's avatar
deuce committed
70
elseif(HAS_LINUX_SOUNDCARD_H)
71
    target_compile_definitions(xpdev PRIVATE SOUNDCARD_H_IN=3)
deuce's avatar
deuce committed
72 73 74 75
endif()

CHECK_INCLUDE_FILES(dev/speaker/speaker.h HAS_DEV_SPEAKER_SPEAKER_H)
if(HAS_DEV_SPEAKER_SPEAKER_H)
76
	target_compile_definitions(xpdev PRIVATE HAS_DEV_SPEAKER_SPEAKER_H)
deuce's avatar
deuce committed
77 78 79
endif()
CHECK_INCLUDE_FILES(dev/machine/speaker.h HAS_DEV_MACHINE_SPEAKER_H)
if(HAS_DEV_MACHINE_SPEAKER_H)
80
	target_compile_definitions(xpdev PRIVATE HAS_DEV_MACHINE_SPEAKER_H)
deuce's avatar
deuce committed
81 82 83
endif()
CHECK_INCLUDE_FILES(dev/speaker/spkr.h HAS_DEV_MACHINE_SPKR_H)
if(HAS_DEV_MACHINE_SPKR_H)
84
	target_compile_definitions(xpdev PRIVATE HAS_DEV_MACHINE_SPKR_H)
deuce's avatar
deuce committed
85 86
endif()

87 88 89 90
target_compile_definitions(xpdev PRIVATE WRAPPER_EXPORTS)
if(WIN32)
	target_link_libraries(xpdev Iphlpapi Ws2_32 Winmm)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Haiku")
deuce's avatar
deuce committed
91 92 93
	target_link_libraries(xpdev m)
	target_link_libraries(xpdev network)
elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
deuce's avatar
deuce committed
94
	target_link_libraries(xpdev ossaudio)
deuce's avatar
deuce committed
95
elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
deuce's avatar
deuce committed
96
	target_link_libraries(xpdev ossaudio)
deuce's avatar
deuce committed
97
elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
deuce's avatar
deuce committed
98
	target_link_libraries(xpdev socket)
deuce's avatar
deuce committed
99
elseif(CMAKE_SYSTEM_NAME STREQUAL "OS X")
deuce's avatar
deuce committed
100
	target_link_libraries(xpdev)
deuce's avatar
deuce committed
101
elseif(CMAKE_SYSTEM_NAME STREQUAL "QNX")
deuce's avatar
deuce committed
102
	target_link_libraries(xpdev)
deuce's avatar
deuce committed
103
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
deuce's avatar
deuce committed
104
	target_link_libraries(xpdev)
deuce's avatar
deuce committed
105 106 107
elseif(WIN32)
	target_link_libraries(xpdev ws2_32 winmm)
endif()
deuce's avatar
deuce committed
108
target_link_libraries(xpdev ${CMAKE_THREAD_LIBS_INIT})
deuce's avatar
deuce committed
109 110

if(EXISTS /dev/urandom)
111
	target_compile_definitions(xpdev PRIVATE HAS_DEV_URANDOM URANDOM_DEV="/dev/urandom")
deuce's avatar
deuce committed
112 113
endif()
if(EXISTS /dev/random)
114
	target_compile_definitions(xpdev PRIVATE HAS_DEV_RANDOM RANDOM_DEV="/dev/random")
deuce's avatar
deuce committed
115 116 117 118
endif()

CHECK_FUNCTION_EXISTS(random HAS_RANDOM_FUNC) 
if(HAS_RANDOM_FUNC)
119
	target_compile_definitions(xpdev PRIVATE HAS_RANDOM_FUNC)
deuce's avatar
deuce committed
120 121 122 123
endif()

CHECK_FUNCTION_EXISTS(srandomdev HAS_SRANDOMDEV_FUNC)
if(HAS_SRANDOMDEV_FUNC)
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
	target_compile_definitions(xpdev PRIVATE HAS_SRANDOMDEV_FUNC)
endif()

if(SDL_AUDIO)
	if(SDL_FOUND)
		target_include_directories(xpdev PRIVATE ${SDL_INCLUDE_DIR})
		target_compile_definitions(xpdev PRIVATE ${WITH_SDL_AUDIO})
	endif()
endif()

if(X11_FOUND)
	target_include_directories(xpdev PRIVATE X11_INCLUDE_DIR)
endif()

pkg_check_modules(PORTAUDIO2 portaudio-2.0)
if(PORTAUDIO2_FOUND)
	set(PORTAUDIO_FOUND TRUE)
	set(PORTAUDIO_LIBS PORTAUDIO2_LIBS)
	set(PORTAUDIO_CFLAGS PORTAUDIO2_CFLAGS)
else()
144
	find_path(PORTAUDIO_INCLUDEDIR portaudio.h)
145
	if(PORTAUDIO_INCLUDEDIR)
146
		set(PORTAUDIO_FOUND TRUE)
147 148 149 150 151 152 153 154 155 156
	endif()
endif()

if(PORTAUDIO_FOUND)
	target_include_directories(xpdev PRIVATE ${PORTAUDIO_INCLUDEDIR})
endif()

CHECK_INCLUDE_FILES(alsa/asoundlib.h USE_ALSA_SOUND)
if(HAS_INTTYPES_H)
    target_compile_definitions(xpdev PRIVATE USE_ALSA_SOUND)
deuce's avatar
deuce committed
157
endif()
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187

set(INSTALL_HEADERS
	conwrap.h
	dat_file.h
	datewrap.h
	dirwrap.h
	eventwrap.h
	filewrap.h
	gen_defs.h
	genwrap.h
	ini_file.h
	link_list.h
	msg_queue.h
	multisock.h
	netwrap.h
	semfile.h
	semwrap.h
	sockwrap.h
	str_list.h
	strwrap.h
	threadwrap.h
	wrapdll.h
	xp_dl.h
	xp_syslog.h
	xpbeep.h
	xpdatetime.h
	xpendian.h
	xpmap.h
	xpprintf.h
)
188 189 190 191
if(NOT WIN32)
	list(APPEND INSTALL_HEADERS xpevent.h)
    list(APPEND INSTALL_HEADERS xpsem.h)
endif()
192 193 194

install(TARGETS xpdev DESTINATION bin)
install(FILES ${INSTALL_HEADERS} DESTINATION include/xpdev)