-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathCMakeLists.txt
137 lines (106 loc) · 4.73 KB
/
CMakeLists.txt
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
cmake_minimum_required(VERSION 3.3.2)
if (APPLE)
cmake_policy(SET CMP0042 NEW)
endif()
if(UNIX AND NOT APPLE)
set(FCGIFUNC_LINUX TRUE)
else(UNIX AND NOT APPLE)
set(FCGIFUNC_MACOSX TRUE)
set(FCGIFUNC_CMAKE_MACOSX_RPATH 1)
endif (UNIX AND NOT APPLE)
set(PROJ_FCGIFUNC ffunc)
project(ffunc
VERSION 2.1
LANGUAGES C)
# Some tweak parameters
SET(PWD ${CMAKE_CURRENT_SOURCE_DIR})
IF (NOT DEFINED CMAKE_INSTALL_BINDIR)
SET(CMAKE_INSTALL_BINDIR /usr/local/bin)
ENDIF (NOT DEFINED CMAKE_INSTALL_BINDIR)
IF (NOT DEFINED CMAKE_INSTALL_LIBDIR)
SET(CMAKE_INSTALL_LIBDIR /usr/local/lib)
ENDIF (NOT DEFINED CMAKE_INSTALL_LIBDIR)
IF (NOT DEFINED CMAKE_INSTALL_INCLUDEDIR)
SET(CMAKE_INSTALL_INCLUDEDIR /usr/local/include)
ENDIF(NOT DEFINED CMAKE_INSTALL_INCLUDEDIR)
MESSAGE(STATUS "ffunc LIBRARY DIRECTORY located at ${CMAKE_INSTALL_LIBDIR}")
message(STATUS "Current SOURCES DIRECTORY located at ${CMAKE_CURRENT_SOURCE_DIR}")
message(STATUS "Current Binary DIRECTORY located at ${CMAKE_CURRENT_BINARY_DIR}")
SET(LIBPATH /usr/lib /usr/local/lib)
include_directories(include /usr/local/include)
add_definitions(-D_XOPEN_SOURCE)
# add_definitions(-DFDYMEMDETECT=true)
# for static libary find first priority
# find_library(FCGI_LIB NAMES libfcgi.a PATHS ${LIBPATH})
# for dynamic library find second priority
find_library(FCGI_LIB NAMES fcgi PATHS ${LIBPATH})
if(FCGI_LIB)
message(STATUS "fcgi found at ${FCGI_LIB}. fcgi support is compiled in.")
add_definitions(-DFCGI=true)
else(FCGI_LIB)
message( FATAL_ERROR "fcgi not found. Please install fcgi")
endif(FCGI_LIB)
find_library(THREAD_LIB NAMES pthread PATHS ${LIBPATH})
if(THREAD_LIB)
else(THREAD_LIB)
message( FATAL_ERROR "pthread not found. Please install pthread")
endif(THREAD_LIB)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wstrict-prototypes -Wmissing-prototypes")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wshadow -Wpointer-arith -Wcast-qual")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wsign-compare -Iinclude -std=c11 -pedantic")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
# Not need to export dynamic symbol out, -rdyanmic only for user application
# SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "-rdynamic") # LDFLAGS=
# gcc -fPIC -pie -o libffunc.so src/ffunc_core.c src/ffunc_pool.c -Iinclude -Wl,-E -Wl,--whole-archive -lfcgi -latomic -ldl -Wl,--no-whole-archive
if(UNIX AND NOT APPLE)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pie -Wl,-E")
else(UNIX AND NOT APPLE)
add_definitions(-DFCGIFUNC_MACOSX=true)
endif(UNIX AND NOT APPLE)
# uninstall target
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
SET (SRCS ffunc.c)
SET (HDRS ffunc.h)
add_library(${PROJ_FCGIFUNC}.static STATIC ${HDRS} ${SRCS})
set_target_properties(${PROJ_FCGIFUNC}.static PROPERTIES OUTPUT_NAME ${PROJ_FCGIFUNC})
add_library(${PROJ_FCGIFUNC} SHARED ${HDRS} ${SRCS})
link_directories(/usr/local/lib /usr/lib)
# target_link_libraries(ffunc ${PROJ_FCGIFUNC})
# target_link_libraries(ffunc fcgi dl)
if(UNIX AND NOT APPLE)
# target_link_libraries(${PROJ_FCGIFUNC} ${LIB_DL}) #static link to fcgi
target_link_libraries(${PROJ_FCGIFUNC} fcgi dl pthread) #dynamic link to -ldl
# target_link_libraries(${PROJ_FCGIFUNC}.static ${LIB_DL}) #static link
target_link_libraries(${PROJ_FCGIFUNC}.static fcgi dl pthread) #dynamic link to -ldl
else(UNIX AND NOT APPLE)
# target_link_libraries(${PROJ_FCGIFUNC} ${LIB_DL}) #static link to fcgi
target_link_libraries(${PROJ_FCGIFUNC} fcgi dl pthread) #dynamic link to -ldl
# target_link_libraries(${PROJ_FCGIFUNC}.static ${LIB_DL}) #static link
target_link_libraries(${PROJ_FCGIFUNC}.static fcgi dl pthread) #dynamic link to -ldl
endif(UNIX AND NOT APPLE)
install(TARGETS ${PROJ_FCGIFUNC} EXPORT ${PROJ_FCGIFUNC}
ARCHIVE DESTINATION lib${LIB_SUFFIX}
LIBRARY DESTINATION lib${LIB_SUFFIX}
# RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(TARGETS ${PROJ_FCGIFUNC}.static EXPORT ${PROJ_FCGIFUNC}
ARCHIVE DESTINATION lib${LIB_SUFFIX}
LIBRARY DESTINATION lib${LIB_SUFFIX}
# RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(FILES ffunc.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# install(TARGETS ffunc EXPORT ffunc DESTINATION ${CMAKE_INSTALL_BINDIR})
install(CODE "execute_process(COMMAND ldconfig)")
# IF (${CMAKE_BUILD_TYPE} MATCHES "Debug")
# add_definitions(-D__DEBUG__)
# SET(CMAKE_C_FLAGS "-Wall -O0 -fPIC ${CMAKE_C_FLAGS}")
# SET(CMAKE_CXX_FLAGS "-Wall -O0 -fPIC ${CMAKE_CXX_FLAGS}")
# ELSE (${CMAKE_BUILD_TYPE} MATCHES "Debug")
# SET(CMAKE_C_FLAGS "-Wall -O2 -fPIC ${CMAKE_C_FLAGS}")
# SET(CMAKE_CXX_FLAGS "-Wall -O2 -fPIC ${CMAKE_CXX_FLAGS}")
# ENDIF (${CMAKE_BUILD_TYPE} MATCHES "Debug")