aboutsummaryrefslogtreecommitdiff
path: root/src/CMakeLists.txt
blob: fb56aa7711f95b4a27fa4c79251c7e357fabfd46 (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
INCLUDE(CheckIncludeFiles)
INCLUDE(CheckFunctionExists)
INCLUDE(CheckVariableExists)
INCLUDE(CheckTypeSize)
INCLUDE(CheckLibraryExists)
INCLUDE(CMakeDetermineCCompiler)
INCLUDE(FindThreads)
INCLUDE(CPack)
INCLUDE(FindPkgConfig)

INCLUDE(LighttpdMacros)
FIND_PACKAGE(Ragel REQUIRED)
cmake_policy(SET CMP0005 OLD)

OPTION(BUILD_STATIC "build a static fcgi-debug")

IF(CMAKE_COMPILER_IS_GNUCC)
	OPTION(BUILD_EXTRA_WARNINGS "extra warnings")

	IF(BUILD_EXTRA_WARNINGS)
		SET(WARN_FLAGS "-g -O2 -g2 -Wall -Wmissing-declarations -Wdeclaration-after-statement -Wcast-align -Winline -Wsign-compare -Wnested-externs -Wpointer-arith -Wformat-security")
		# -Wl,--as-needed
		# -Werror -Wbad-function-cast -Wmissing-prototypes
	ELSE(BUILD_EXTRA_WARNINGS)
		SET(WARN_FLAGS "")
	ENDIF(BUILD_EXTRA_WARNINGS)
ENDIF(CMAKE_COMPILER_IS_GNUCC)

ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGE_FILES)

# libev
CHECK_INCLUDE_FILES(ev.h HAVE_EV_H)
IF(HAVE_EV_H)
	CHECK_LIBRARY_EXISTS(ev ev_loop "" HAVE_LIBEV)
	IF(HAVE_LIBEV)
		SET(EV_LIBRARIES ev)
		SET(EV_STATIC_LIBRARIES ev;m)
		CHECK_LIBRARY_EXISTS(rt clock_gettime "" NEED_RT)
		IF(NEED_RT)
			SET(EV_STATIC_LIBRARIES ${EV_STATIC_LIBRARIES} rt)
		ENDIF(NEED_RT)
	ELSE(HAVE_LIBEV)
		MESSAGE(FATAL_ERROR "Couldn't find lib ev")
	ENDIF(HAVE_LIBEV)
ELSE(HAVE_EV_H)
	MESSAGE(FATAL_ERROR "Couldn't find <ev.h>")
ENDIF(HAVE_EV_H)

# glib/gthread
pkg_check_modules(GLIB REQUIRED glib-2.0>=2.12)

ADD_DEFINITIONS(
  -DPACKAGE_NAME="\\"${CMAKE_PROJECT_NAME}\\""
  -DPACKAGE_VERSION="\\"${CPACK_PACKAGE_VERSION}\\""
  )

## Write out config.h
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)

ADD_DEFINITIONS(-DHAVE_CONFIG_H)

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})

RAGEL_PARSER(parse-fastcgi.rl)

ADD_EXECUTABLE(fcgi-debug
	fcgi-debug.c
	connection.c
	tools.c
	stream.c
	log.c

	debug-fastcgi.c
	parse-fastcgi.c
)

IF(BUILD_STATIC)
	ADD_TARGET_PROPERTIES(fcgi-debug LINK_FLAGS -static)

	TARGET_USE_PACKAGE(fcgi-debug
		"${EV_STATIC_LIBARARY_DIRS}"
		"${EV_STATIC_LIBRARIES}"
		"${EV_STATIC_LDFLAGS_OTHERS}"
		"${EV_STATIC_CFLAGS}"
	)

	TARGET_USE_PACKAGE(fcgi-debug
		"${GLIB_STATIC_LIBARARY_DIRS}"
		"${GLIB_STATIC_LIBRARIES}"
		"${GLIB_STATIC_LDFLAGS_OTHERS}"
		"${GLIB_STATIC_CFLAGS}"
	)
ELSE(BUILD_STATIC)
	TARGET_USE_PACKAGE(fcgi-debug
		"${EV_LIBARARY_DIRS}"
		"${EV_LIBRARIES}"
		"${EV_LDFLAGS_OTHERS}"
		"${EV_CFLAGS}"
	)

	TARGET_USE_PACKAGE(fcgi-debug
		"${GLIB_LIBARARY_DIRS}"
		"${GLIB_LIBRARIES}"
		"${GLIB_LDFLAGS_OTHERS}"
		"${GLIB_CFLAGS}"
	)
ENDIF(BUILD_STATIC)

IF(CMAKE_COMPILER_IS_GNUCC)
  SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wall -g -Wshadow -W -pedantic ${WARN_FLAGS}")
  SET(CMAKE_C_FLAGS_RELEASE        "${CMAKE_C_FLAGS_RELEASE}     -O2")
  SET(CMAKE_C_FLAGS_DEBUG          "${CMAKE_C_FLAGS_DEBUG}       -O0")
  SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_WITHDEBINFO} -O2")
  ADD_DEFINITIONS(-D_GNU_SOURCE)
ENDIF(CMAKE_COMPILER_IS_GNUCC)

#SET_TARGET_PROPERTIES(fcgi-debug PROPERTIES CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})

INSTALL(TARGETS fcgi-debug
	RUNTIME DESTINATION bin
	)