You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
3.2 KiB

  1. INCLUDE(CheckCSourceCompiles)
  2. INCLUDE(CheckIncludeFiles)
  3. INCLUDE(CheckFunctionExists)
  4. INCLUDE(CheckVariableExists)
  5. INCLUDE(CheckTypeSize)
  6. INCLUDE(CMakeDetermineCCompiler)
  7. OPTION(BUILD_EXTRA_WARNINGS "extra warnings")
  8. # default to ON
  9. set(CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "Default value for ``POSITION_INDEPENDENT_CODE`` of targets.")
  10. IF(BUILD_EXTRA_WARNINGS)
  11. SET(WARN_CFLAGS "-g -O2 -g2 -Wall -Wmissing-declarations -Wdeclaration-after-statement -Wcast-align -Wsign-compare -Wnested-externs -Wpointer-arith -Wmissing-prototypes -Wshadow -Wno-pointer-sign -D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security")
  12. SET(WARN_LDFLAGS "-g -O2 -g2 -Wall -Wl,--as-needed -Wl,--no-undefined")
  13. # -Werror
  14. ELSE(BUILD_EXTRA_WARNINGS)
  15. SET(WARN_CFLAGS "")
  16. SET(WARN_LDFLAGS "")
  17. ENDIF(BUILD_EXTRA_WARNINGS)
  18. IF(CMAKE_COMPILER_IS_GNUCC)
  19. SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wall -g -Wshadow -W -pedantic")
  20. SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2")
  21. SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")
  22. SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_WITHDEBINFO} -O2")
  23. ADD_DEFINITIONS(-D_GNU_SOURCE)
  24. ENDIF(CMAKE_COMPILER_IS_GNUCC)
  25. # awk '/#include <(.*)>/ { h = substr($2,2,length($2)-2); h2=toupper(h); gsub("\\.|\\/", "_", h2); printf "%s%s%s%s%s", "CHECK_INCLUDE_FILES(", h, " HAVE_", h2, ")\n" }' spawn-fcgi.c | sort
  26. CHECK_INCLUDE_FILES(arpa/inet.h HAVE_ARPA_INET_H)
  27. CHECK_INCLUDE_FILES(errno.h HAVE_ERRNO_H)
  28. CHECK_INCLUDE_FILES(fcntl.h HAVE_FCNTL_H)
  29. CHECK_INCLUDE_FILES(getopt.h HAVE_GETOPT_H)
  30. CHECK_INCLUDE_FILES(grp.h HAVE_GRP_H)
  31. CHECK_INCLUDE_FILES(netdb.h HAVE_NETDB_H)
  32. CHECK_INCLUDE_FILES(netinet/in.h HAVE_NETINET_IN_H)
  33. CHECK_INCLUDE_FILES(netinet/tcp.h HAVE_NETINET_TCP_H)
  34. CHECK_INCLUDE_FILES(pwd.h HAVE_PWD_H)
  35. CHECK_INCLUDE_FILES(stdio.h HAVE_STDIO_H)
  36. CHECK_INCLUDE_FILES(stdlib.h HAVE_STDLIB_H)
  37. CHECK_INCLUDE_FILES(string.h HAVE_STRING_H)
  38. CHECK_INCLUDE_FILES(sys/ioctl.h HAVE_SYS_IOCTL_H)
  39. CHECK_INCLUDE_FILES(sys/socket.h HAVE_SYS_SOCKET_H)
  40. CHECK_INCLUDE_FILES(sys/stat.h HAVE_SYS_STAT_H)
  41. CHECK_INCLUDE_FILES(sys/time.h HAVE_SYS_TIME_H)
  42. CHECK_INCLUDE_FILES(sys/types.h HAVE_SYS_TYPES_H)
  43. CHECK_INCLUDE_FILES(sys/un.h HAVE_SYS_UN_H)
  44. CHECK_INCLUDE_FILES(sys/wait.h HAVE_SYS_WAIT_H)
  45. CHECK_INCLUDE_FILES(unistd.h HAVE_UNISTD_H)
  46. CHECK_INCLUDE_FILES(winsock2.h HAVE_WINSOCK2_H)
  47. CHECK_FUNCTION_EXISTS(issetugid HAVE_ISSETUGID)
  48. CHECK_FUNCTION_EXISTS(inet_pton HAVE_INET_PTON)
  49. CHECK_C_SOURCE_COMPILES("
  50. #include <sys/types.h>
  51. #include <sys/socket.h>
  52. #include <netinet/in.h>
  53. int main() {
  54. struct sockaddr_in6 s; struct in6_addr t=in6addr_any; int i=AF_INET6; s; t.s6_addr[0] = 0;
  55. return 0;
  56. }" HAVE_IPV6)
  57. SET(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
  58. CHECK_TYPE_SIZE(socklen_t HAVE_SOCKLEN_T)
  59. SET(CMAKE_EXTRA_INCLUDE_FILES)
  60. ## Write out config.h
  61. CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
  62. ADD_DEFINITIONS(-DHAVE_CONFIG_H)
  63. INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
  64. ADD_EXECUTABLE(spawn-fcgi spawn-fcgi.c)
  65. SET_TARGET_PROPERTIES(spawn-fcgi PROPERTIES COMPILE_FLAGS ${WARN_CFLAGS})
  66. TARGET_LINK_LIBRARIES(spawn-fcgi ${WARN_LDFLAGS})
  67. INSTALL(TARGETS spawn-fcgi DESTINATION bin)