Browse Source

[cmake] improve libev handling

debian
Stefan Bühler 8 years ago
parent
commit
64c505e3c7
  1. 39
      CMakeLists.txt
  2. 14
      cmake/AddTargetProperties.cmake
  3. 71
      cmake/FindLibEV.cmake

39
CMakeLists.txt

@ -2,49 +2,24 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6.0 FATAL_ERROR)
cmake_policy(VERSION 2.6.0)
SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
INCLUDE(CheckIncludeFiles)
INCLUDE(CheckLibraryExists)
INCLUDE(FindPkgConfig)
INCLUDE(AddTargetProperties)
MACRO(ADD_TARGET_PROPERTIES _target _name _properties)
SET(_properties ${ARGV})
LIST(REMOVE_AT _properties 0)
LIST(REMOVE_AT _properties 0)
GET_TARGET_PROPERTY(_old_properties ${_target} ${_name})
#MESSAGE("adding property to ${_target} ${_name}: ${_properties}")
IF(NOT _old_properties)
# in case it's NOTFOUND
SET(_old_properties)
ELSE(NOT _old_properties)
SET(_old_properties "${_old_properties} ")
ENDIF(NOT _old_properties)
SET_TARGET_PROPERTIES(${_target} PROPERTIES ${_name} "${_old_properties}${_properties}")
ENDMACRO(ADD_TARGET_PROPERTIES)
PROJECT(fcgi-cgi C)
SET(PACKAGE_VERSION 0.2.1)
IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE)
ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
# libev
CHECK_INCLUDE_FILES(ev.h HAVE_EV_H)
IF(HAVE_EV_H)
CHECK_LIBRARY_EXISTS(ev ev_time "" 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)
FIND_PACKAGE(LibEV REQUIRED)
# GLIB 2
pkg_check_modules (GLIB2 REQUIRED glib-2.0)
@ -64,12 +39,12 @@ add_executable(fcgi-cgi ${MAIN_SOURCE})
ADD_TARGET_PROPERTIES(fcgi-cgi COMPILE_FLAGS "-std=gnu99 -Wall -g -Wshadow -W -pedantic -fPIC -D_GNU_SOURCE")
# libev
TARGET_LINK_LIBRARIES(fcgi-cgi "${EV_LIBRARIES}")
TARGET_LINK_LIBRARIES(fcgi-cgi "${LIBEV_LDFLAGS}")
# GLIB 2
TARGET_LINK_LIBRARIES(fcgi-cgi "${GLIB2_LIBRARIES}")
ADD_TARGET_PROPERTIES(fcgi-cgi LINK_FLAGS "${GLIB2_LDFLAGS}")
ADD_TARGET_PROPERTIES(fcgi-cgi COMPILE_FLAGS "${GLIB2_CFLAGS_OTHER}")
ADD_TARGET_PROPERTIES(fcgi-cgi COMPILE_FLAGS "${GLIB2_CFLAGS_OTHER}" "${LIBEV_CFLAGS}")
INSTALL(TARGETS fcgi-cgi DESTINATION bin)

14
cmake/AddTargetProperties.cmake

@ -0,0 +1,14 @@
MACRO(ADD_TARGET_PROPERTIES _target _name _properties)
SET(_properties ${ARGV})
LIST(REMOVE_AT _properties 0)
LIST(REMOVE_AT _properties 0)
GET_TARGET_PROPERTY(_old_properties ${_target} ${_name})
#MESSAGE("adding property to ${_target} ${_name}: ${_properties}")
IF(NOT _old_properties)
# in case it's NOTFOUND
SET(_old_properties)
ELSE(NOT _old_properties)
SET(_old_properties "${_old_properties} ")
ENDIF(NOT _old_properties)
SET_TARGET_PROPERTIES(${_target} PROPERTIES ${_name} "${_old_properties}${_properties}")
ENDMACRO(ADD_TARGET_PROPERTIES)

71
cmake/FindLibEV.cmake

@ -0,0 +1,71 @@
SET(LIBEV_PATH "" CACHE PATH "Base path for include/ev.h and lib/libev*")
SET(LIBEV_INCLUDE_PATH "" CACHE PATH "Include path for ev.h")
SET(LIBEV_LIBDIR "" CACHE PATH "Path containing libev")
IF(LIBEV_PATH)
SET(LIBEV_INCLUDE_PATH "${LIBEV_PATH}/include" CACHE PATH "Include path for ev.h" FORCE)
SET(LIBEV_LIBDIR "${LIBEV_PATH}/lib" CACHE PATH "Path containing libev" FORCE)
ENDIF(LIBEV_PATH)
IF(LIBEV_INCLUDE_PATH)
INCLUDE_DIRECTORIES(${LIBEV_INCLUDE_PATH})
ENDIF(LIBEV_INCLUDE_PATH)
# Use cached result
IF(NOT LIBEV_FOUND)
UNSET(HAVE_EV_H)
UNSET(HAVE_LIBEV)
UNSET(HAVE_EV_H CACHE)
UNSET(HAVE_LIBEV CACHE)
UNSET(LIBEV_CFLAGS)
UNSET(LIBEV_LDFLAGS)
IF(LIBEV_INCLUDE_PATH OR LIBEV_LIBDIR)
SET(CMAKE_REQUIRED_INCLUDES ${LIBEV_INCLUDE_PATH})
# MESSAGE(STATUS "Looking for ev.h in ${CMAKE_REQUIRED_INCLUDES}")
CHECK_INCLUDE_FILES(ev.h HAVE_EV_H)
IF(HAVE_EV_H)
# MESSAGE(STATUS "Looking for lib ev in ${LIBEV_LIBDIR}")
CHECK_LIBRARY_EXISTS(ev ev_time "${LIBEV_LIBDIR}" HAVE_LIBEV)
IF(HAVE_LIBEV)
SET(LIBEV_LIBRARIES ev CACHE INTERNAL "")
SET(LIBEV_CFLAGS "" CACHE INTERNAL "")
SET(LIBEV_LDFLAGS "-L${LIBEV_LIBDIR} -lev" CACHE INTERNAL "")
SET(LIBEV_FOUND TRUE CACHE INTERNAL "Found libev" FORCE)
ELSE(HAVE_LIBEV)
MESSAGE(STATUS "Couldn't find lib ev in ${LIBEV_LIBDIR}")
ENDIF(HAVE_LIBEV)
ELSE(HAVE_EV_H)
MESSAGE(STATUS "Couldn't find <ev.h> in ${LIBEV_INCLUDE_PATH}")
ENDIF(HAVE_EV_H)
ELSE(LIBEV_INCLUDE_PATH OR LIBEV_LIBDIR)
pkg_check_modules(LIBEV libev)
IF(NOT LIBEV_FOUND)
# MESSAGE(STATUS "Looking for ev.h in ${CMAKE_REQUIRED_INCLUDES}")
CHECK_INCLUDE_FILES(ev.h HAVE_EV_H)
IF(HAVE_EV_H)
# MESSAGE(STATUS "Looking for lib ev")
CHECK_LIBRARY_EXISTS(ev ev_time "" HAVE_LIBEV)
IF(HAVE_LIBEV)
SET(LIBEV_CFLAGS "" CACHE INTERNAL "")
SET(LIBEV_LDFLAGS "-lev" CACHE INTERNAL "")
SET(LIBEV_FOUND TRUE CACHE INTERNAL "Found libev" FORCE)
ELSE(HAVE_LIBEV)
MESSAGE(STATUS "Couldn't find lib ev")
ENDIF(HAVE_LIBEV)
ELSE(HAVE_EV_H)
MESSAGE(STATUS "Couldn't find <ev.h>")
ENDIF(HAVE_EV_H)
ENDIF(NOT LIBEV_FOUND)
ENDIF(LIBEV_INCLUDE_PATH OR LIBEV_LIBDIR)
ENDIF(NOT LIBEV_FOUND)
IF(NOT LIBEV_FOUND)
IF(LibEV_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find libev")
ENDIF(LibEV_FIND_REQUIRED)
ENDIF(NOT LIBEV_FOUND)
MARK_AS_ADVANCED(LIBEV_PATH LIBEV_INCLUDE_PATH LIBEV_LIBDIR)
Loading…
Cancel
Save