Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Commit

Permalink
Cleanup and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Ellzey committed Sep 30, 2014
1 parent fd6d235 commit 61c7f4f
Show file tree
Hide file tree
Showing 9 changed files with 532 additions and 147 deletions.
33 changes: 17 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ set(PROJECT_MAJOR_VERSION 1)
set(PROJECT_MINOR_VERSION 2)
set(PROJECT_PATCH_VERSION 9)


add_definitions(-D_FORTIFY_SOURCE=2)
set (PROJECT_VERSION ${PROJECT_MAJOR_VERSION}.${PROJECT_MINOR_VERSION}.${PROJECT_PATCH_VERSION})
set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules)

Expand All @@ -13,9 +15,9 @@ INCLUDE (CheckIncludeFiles)
INCLUDE (CheckTypeSize)
INCLUDE (CheckCCompilerFlag)
INCLUDE (TestBigEndian)
INCLUDE (UseDebugSymbols)


CHECK_FUNCTION_EXISTS(alloca C_ALLOCA)
CHECK_FUNCTION_EXISTS(memcmp HAVE_MEMCMP)
CHECK_FUNCTION_EXISTS(strndup HAVE_STRNDUP)
CHECK_FUNCTION_EXISTS(strnlen HAVE_STRNLEN)
Expand Down Expand Up @@ -97,6 +99,7 @@ message("Build Type: ${CMAKE_BUILD_TYPE}")
message("Std CFLAGS: ${CMAKE_C_FLAGS}")
message("Dbg CFLAGS: ${CMAKE_C_FLAGS_DEBUG}")
message("Rel CFLAGS: ${CMAKE_C_FLAGS_RELEASE}")
message("RelDbg CFLAGS: ${CMAKE_C_FLAGS_RELWITHDEBINFO}")

find_package(LibEvent REQUIRED)

Expand Down Expand Up @@ -216,10 +219,6 @@ if (NOT EVHTP_DISABLE_EVTHR)
set (LIBEVHTP_SOURCES ${LIBEVHTP_SOURCES} evthr/evthr.c)
endif(NOT EVHTP_DISABLE_EVTHR)

if (NOT ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNDEBUG")
endif (NOT ${CMAKE_BUILD_TYPE} STREQUAL "Debug")

IF (WIN32)
ADD_DEFINITIONS(-DWIN32)
ADD_DEFINITIONS(-march=i486)
Expand Down Expand Up @@ -250,27 +249,27 @@ configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/evhtp-config.h.in
${CMAKE_CURRENT_BINARY_DIR}/evhtp-config.h)

add_library(libevhtp ${EVHTP_LIBTYPE} ${LIBEVHTP_SOURCES} ${ONIG_SOURCES})

set_target_properties(libevhtp PROPERTIES OUTPUT_NAME "evhtp")
target_link_libraries(libevhtp ${LIBEVHTP_EXTERNAL_LIBS})
add_library(evhtp ${EVHTP_LIBTYPE} ${LIBEVHTP_SOURCES} ${ONIG_SOURCES})
target_link_libraries(evhtp ${LIBEVHTP_EXTERNAL_LIBS})

add_executable(test EXCLUDE_FROM_ALL examples/test.c)
add_executable(test_basic EXCLUDE_FROM_ALL examples/test_basic.c)
add_executable(test_vhost EXCLUDE_FROM_ALL examples/test_vhost.c)
add_executable(test_client EXCLUDE_FROM_ALL examples/test_client.c)
add_executable(test_query EXCLUDE_FROM_ALL examples/test_query.c)

strip_debug_symbols(test_query)

if (NOT EVHTP_DISABLE_EVTHR)
add_executable(test_proxy EXCLUDE_FROM_ALL examples/test_proxy.c)
target_link_libraries(test_proxy libevhtp ${LIBEVHTP_EXTERNAL_LIBS} ${SYS_LIBS})
target_link_libraries(test_proxy evhtp ${LIBEVHTP_EXTERNAL_LIBS} ${SYS_LIBS})
endif()

target_link_libraries(test libevhtp ${LIBEVHTP_EXTERNAL_LIBS} ${SYS_LIBS})
target_link_libraries(test_basic libevhtp ${LIBEVHTP_EXTERNAL_LIBS} ${SYS_LIBS})
target_link_libraries(test_vhost libevhtp ${LIBEVHTP_EXTERNAL_LIBS} ${SYS_LIBS})
target_link_libraries(test_client libevhtp ${LIBEVHTP_EXTERNAL_LIBS} ${SYS_LIBS})
target_link_libraries(test_query libevhtp ${LIBEVHTP_EXTERNAL_LIBS} ${SYS_LIBS})
target_link_libraries(test evhtp ${LIBEVHTP_EXTERNAL_LIBS} ${SYS_LIBS})
target_link_libraries(test_basic evhtp ${LIBEVHTP_EXTERNAL_LIBS} ${SYS_LIBS})
target_link_libraries(test_vhost evhtp ${LIBEVHTP_EXTERNAL_LIBS} ${SYS_LIBS})
target_link_libraries(test_client evhtp ${LIBEVHTP_EXTERNAL_LIBS} ${SYS_LIBS})
target_link_libraries(test_query evhtp ${LIBEVHTP_EXTERNAL_LIBS} ${SYS_LIBS})

add_dependencies(examples test test_basic test_vhost test_client test_proxy test_query)

Expand All @@ -282,7 +281,7 @@ if(NOT INCLUDE_INSTALL_DIR)
set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include)
endif()

install (TARGETS libevhtp DESTINATION ${LIB_INSTALL_DIR})
install (TARGETS evhtp DESTINATION ${LIB_INSTALL_DIR})
install (FILES evhtp.h DESTINATION ${INCLUDE_INSTALL_DIR})
install (FILES htparse/htparse.h DESTINATION ${INCLUDE_INSTALL_DIR})
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/evhtp-config.h DESTINATION ${INCLUDE_INSTALL_DIR})
Expand All @@ -307,3 +306,5 @@ ENDIF (WIN32)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/evhtp.pc.in
${CMAKE_CURRENT_BINARY_DIR}/evhtp.pc @ONLY)

message("CFLAGS: ${CMAKE_C_FLAGS}")
102 changes: 102 additions & 0 deletions CMakeModules/AddOptions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# - Add options without repeating them on the command line
#
# Synopsis:
#
# add_options (lang build opts)
#
# where:
#
# lang Name of the language whose compiler should receive the
# options, e.g. CXX. If a comma-separated list is received
# then the option is added for all those languages. Use the
# special value ALL_LANGUAGES for these languages: CXX, C
# and Fortran
#
# build Kind of build to which this options should apply,
# such as DEBUG and RELEASE. This can also be a comma-
# separated list. Use the special value ALL_BUILDS to apply
# to all builds.
#
# opts List of options to add. Each should be quoted.
#
# Example:
#
# add_options (CXX RELEASE "-O3" "-DNDEBUG" "-Wall")

function (add_options langs builds)
# special handling of empty language specification
if ("${langs}" STREQUAL "ALL_LANGUAGES")
set (langs CXX C Fortran)
endif ("${langs}" STREQUAL "ALL_LANGUAGES")
foreach (lang IN LISTS langs)
# prepend underscore if necessary
foreach (build IN LISTS builds)
if (NOT ("${build}" STREQUAL "ALL_BUILDS"))
set (_bld "_${build}")
string (TOUPPER "${_bld}" _bld)
else (NOT ("${build}" STREQUAL "ALL_BUILDS"))
set (_bld "")
endif (NOT ("${build}" STREQUAL "ALL_BUILDS"))
# if we want everything in the "global" flag, then simply
# ignore the build type here and go add everything to that one
if (CMAKE_NOT_USING_CONFIG_FLAGS)
set (_bld "")
endif ()
foreach (_opt IN LISTS ARGN)
set (_var "CMAKE_${lang}_FLAGS${_bld}")
#message (STATUS "Adding \"${_opt}\" to \${${_var}}")
# remove it first
string (REPLACE "${_opt}" "" _without "${${_var}}")
string (STRIP "${_without}" _without)
# we need to strip this one as well, so they are comparable
string (STRIP "${${_var}}" _stripped)
# if it wasn't there, then add it at the end
if ("${_without}" STREQUAL "${_stripped}")
# don't add any extra spaces if no options yet are set
if (NOT ${_stripped} STREQUAL "")
set (${_var} "${_stripped} ${_opt}")
else (NOT ${_stripped} STREQUAL "")
set (${_var} "${_opt}")
endif (NOT ${_stripped} STREQUAL "")
set (${_var} "${${_var}}" PARENT_SCOPE)
endif ("${_without}" STREQUAL "${_stripped}")
endforeach (_opt)
endforeach (build)
endforeach (lang)
endfunction (add_options lang build)

# set varname to flag unless user has specified something that matches regex
function (set_default_option lang varname flag regex)
# lang is either C, CXX or Fortran
if ("${lang}" STREQUAL "Fortran")
set (letter "F")
else ()
set (letter "${lang}")
endif ()
string (TOUPPER "${CMAKE_BUILD_TYPE}" _build)
if ((NOT ("$ENV{${letter}FLAGS}" MATCHES "${regex}"))
AND (NOT ("${CMAKE_${lang}_FLAGS}" MATCHES "${regex}"))
AND (NOT ("${CMAKE_${lang}_FLAGS_${_build}}" MATCHES "${regex}")))
set (${varname} ${flag} PARENT_SCOPE)
else ()
set (${varname} PARENT_SCOPE)
endif ()
endfunction (set_default_option)

# clear default options as a proxy for not using any default options
# at all. there is one *huge* problem with this: CMake runs the platform
# initialization before executing any line at all in the project and
# there seems to be no way to disable that behaviour, so we cannot really
# distinguish between a platform default and something that the user has
# passed on the command line. the best thing we can do is to all user-
# defined setting if they are something other than the platform default.
macro (no_default_options)
foreach (lang IN ITEMS C CXX Fortran)
foreach (build IN ITEMS DEBUG RELEASE MINSIZEREL RELWITHDEBINFO)
if ("${CMAKE_${lang}_FLAGS_${build}}" STREQUAL "${CMAKE_${lang}_FLAGS_${build}_INIT}")
# for some strange reason we cannot clear this flag, only set it to empty
set (CMAKE_${lang}_FLAGS_${build} "")
endif ()
endforeach (build)
endforeach (lang)
endmacro (no_default_options)
108 changes: 108 additions & 0 deletions CMakeModules/UseCompVer.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# - Get compiler version

# probe the GCC version, returns empty string if GCC is not compiler
function (get_gcc_version language ver_name)
if(CMAKE_${language}_COMPILER_ID STREQUAL GNU)
# exec_program is deprecated, but execute_process does't work :-(
exec_program (${CMAKE_${language}_COMPILER}
ARGS ${CMAKE_${language}_COMPILER_ARG1} -dumpversion
OUTPUT_VARIABLE _version
)
set (${ver_name} ${_version} PARENT_SCOPE)
else (CMAKE_${language}_COMPILER_ID STREQUAL GNU)
set (${ver_name} "" PARENT_SCOPE)
endif (CMAKE_${language}_COMPILER_ID STREQUAL GNU)
endfunction (get_gcc_version ver_name)

# less reliable, but includes the patch number
function (get_gcc_patch language ver_name)
if(CMAKE_${language}_COMPILER_ID STREQUAL GNU)
# exec_program is deprecated, but execute_process does't work :-(
exec_program (${CMAKE_${language}_COMPILER}
ARGS ${CMAKE_${language}_COMPILER_ARG1} --version
OUTPUT_VARIABLE _version
)
# split multi-line string into list
if (WIN32)
string (REPLACE "\r\n" ";" _version "${_version}")
else (WIN32)
string (REPLACE "\n" ";" _version "${_version}")
endif (WIN32)
# only keep first line
list (GET _version 0 _version)
# extract version number from it (this is the fragile part)
string (REGEX REPLACE "^[^\\(]+(\\([^\\)]*\\))?[\ \t]*([0-9]+\\.[0-9]+\\.[0-9]+)(.*\\(.*\\))?" "\\2" _version "${_version}")
# return this to the caller
set (${ver_name} ${_version} PARENT_SCOPE)
else (CMAKE_${language}_COMPILER_ID STREQUAL GNU)
set (${ver_name} "" PARENT_SCOPE)
endif (CMAKE_${language}_COMPILER_ID STREQUAL GNU)
endfunction (get_gcc_patch language ver_name)

function (compiler_info)
if (CMAKE_COMPILER_IS_GNUCXX)
get_gcc_patch (CXX version)
message (STATUS "GNU C++ compiler version: ${version}")
endif (CMAKE_COMPILER_IS_GNUCXX)
endfunction (compiler_info)

function (get_ld_version ver_name)
# run linker to get the version number. interestingly, this option works
# (for our purposes) on all major platforms (Linux, Mac OS X and Windows);
# it returns the program version although it may have ended in error
exec_program (${CMAKE_LINKER}
ARGS "-v"
OUTPUT_VARIABLE _version
)

# keep only first line, even on Mac OS X there is no line end
list (GET _version 0 _version)

# format of the version string is platform-specific
if (NOT WIN32)
if (APPLE)
string (REGEX REPLACE ".*, from Apple (.*\)" "\\1" _version "${_version}")
else (APPLE)
# assuming some GNU toolchain now
string (REGEX REPLACE "GNU ([a-zA-Z0-9_]*) (version|\\(.*\\)) ([^\\ ]*).*" "\\1 \\3" _version "${_version}")
endif (APPLE)
endif (NOT WIN32)

# return the string to the caller
set (${ver_name} "${_version}" PARENT_SCOPE)
endfunction (get_ld_version ver_name)

function (linker_info)
get_ld_version (version)
message (STATUS "Linker: ${version}")
endfunction (linker_info)

# sets CXX_COMPAT_GCC if we have either GCC or Clang
macro (is_compiler_gcc_compatible)
# is the C++ compiler clang++?
string (TOUPPER "${CMAKE_CXX_COMPILER_ID}" _comp_id)
if (_comp_id MATCHES "CLANG")
set (CMAKE_COMPILER_IS_CLANGXX TRUE)
else ()
set (CMAKE_COMPILER_IS_CLANGXX FALSE)
endif ()
# is the C++ compiler g++ or clang++?
if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX)
set (CXX_COMPAT_GCC TRUE)
else ()
set (CXX_COMPAT_GCC FALSE)
endif ()
# is the C compiler clang?
string (TOUPPER "${CMAKE_C_COMPILER_ID}" _comp_id)
if (_comp_id MATCHES "CLANG")
set (CMAKE_COMPILER_IS_CLANG TRUE)
else ()
set (CMAKE_COMPILER_IS_CLANG FALSE)
endif ()
# is the C compiler gcc or clang?
if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
set (C_COMPAT_GCC TRUE)
else ()
set (C_COMPAT_GCC FALSE)
endif ()
endmacro (is_compiler_gcc_compatible)
Loading

0 comments on commit 61c7f4f

Please sign in to comment.