Improve CMakeLists.txt

Signed-off-by: Jianhui Zhao <jianhuizhao329@gmail.com>
main
Jianhui Zhao 2017-12-30 12:24:00 +08:00
parent b54576e32f
commit c1da233ab0
6 changed files with 60 additions and 19 deletions

6
.gitignore vendored
View File

@ -55,3 +55,9 @@ server-cert.pem
server-key.pem
build/
CMakeFiles
CMakeCache.txt
cmake_install.cmake
Makefile
helloworld

View File

@ -1,17 +1,9 @@
cmake_minimum_required(VERSION 2.8)
project(libuhttp C)
project(libuhttpd C)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/")
#set(CMAKE_VERBOSE_MAKEFILE ON)
add_definitions(-O -Wall -Werror --std=gnu99 -D_GNU_SOURCE -Wno-misleading-indentation)
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/src/
${CMAKE_CURRENT_BINARY_DIR}/src/
)
add_subdirectory(src)
add_subdirectory(example)

View File

@ -1,8 +1,8 @@
# - Try to find libubox
# Once done this will define
# LIBUBOX_FOUND - System has libubox
# LIBUBOX_INCLUDE_DIRS - The libubox include directories
# LIBUBOX_LIBRARIES - The libraries needed to use libubox
# LIBUBOX_INCLUDE_DIR - The libubox include directories
# LIBUBOX_LIBRARY - The libraries needed to use libubox
find_path(LIBUBOX_INCLUDE_DIR uloop.h PATH_SUFFIXES libubox)
find_library(LIBUBOX_LIBRARY ubox PATH_SUFFIXES lib64)
@ -14,9 +14,4 @@ find_package_handle_standard_args(Libubox REQUIRED_VARS
LIBUBOX_LIBRARY LIBUBOX_INCLUDE_DIR
VERSION_VAR LIBUBOX_VERSION)
if(LIBUBOX_FOUND)
set(LIBUBOX_LIBRARIES ${LIBUBOX_LIBRARY})
set(LIBUBOX_INCLUDE_DIRS ${LIBUBOX_INCLUDE_DIR})
endif()
mark_as_advanced(LIBUBOX_INCLUDE_DIR LIBUBOX_LIBRARY)

View File

@ -0,0 +1,29 @@
# - Try to find libuhttpd
# Once done this will define
# LIBUHTTPD_FOUND - System has libuhttpd
# LIBUHTTPD_INCLUDE_DIR - The libuhttpd include directories
# LIBUHTTPD_LIBRARY - The libraries needed to use libuhttpd
find_path(LIBUHTTPD_INCLUDE_DIR uhttpd.h PATH_SUFFIXES uhttpd)
find_library(LIBUHTTPD_LIBRARY uhttpd PATH_SUFFIXES lib64)
if(LIBUHTTPD_INCLUDE_DIR)
file(STRINGS "${LIBUHTTPD_INCLUDE_DIR}/uhttpd.h"
LIBUHTTPD_VERSION_MAJOR REGEX "^#define[ \t]+UHTTPD_VERSION_MAJOR[ \t]+[0-9]+")
file(STRINGS "${LIBUHTTPD_INCLUDE_DIR}/uhttpd.h"
LIBUHTTPD_VERSION_MINOR REGEX "^#define[ \t]+UHTTPD_VERSION_MINOR[ \t]+[0-9]+")
string(REGEX REPLACE "[^0-9]+" "" LIBUHTTPD_VERSION_MAJOR "${LIBUHTTPD_VERSION_MAJOR}")
string(REGEX REPLACE "[^0-9]+" "" LIBUHTTPD_VERSION_MINOR "${LIBUHTTPD_VERSION_MINOR}")
set(LIBUHTTPD_VERSION "${LIBUHTTPD_VERSION_MAJOR}.${LIBUHTTPD_VERSION_MINOR}")
unset(LIBUHTTPD_VERSION_MINOR)
unset(LIBUHTTPD_VERSION_MAJOR)
endif()
include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set LIBUHTTPD_FOUND to TRUE
# if all listed variables are TRUE and the requested version matches.
find_package_handle_standard_args(Libuhttpd REQUIRED_VARS
LIBUHTTPD_LIBRARY LIBUHTTPD_INCLUDE_DIR
VERSION_VAR LIBUHTTPD_VERSION)
mark_as_advanced(LIBUHTTPD_INCLUDE_DIR LIBUHTTPD_LIBRARY)

View File

@ -1,2 +1,17 @@
cmake_minimum_required(VERSION 2.8)
project(libuhttpd-example C)
#set(CMAKE_VERBOSE_MAKEFILE ON)
list(APPEND CMAKE_MODULE_PATH "../cmake/Modules/")
add_definitions(-O -Wall -Werror --std=gnu99 -D_GNU_SOURCE -Wno-misleading-indentation)
find_package(Libuhttpd REQUIRED)
find_package(Libubox REQUIRED)
include_directories(${LIBUHTTPD_INCLUDE_DIR})
add_executable(helloworld helloworld.c)
target_link_libraries(helloworld uhttpd)
target_link_libraries(helloworld ${LIBUHTTPD_LIBRARY} ${LIBUBOX_LIBRARY})

View File

@ -1,3 +1,6 @@
add_definitions(-O -Wall -Werror --std=gnu99 -D_GNU_SOURCE -Wno-misleading-indentation)
# The version number.
set(UHTTPD_VERSION_MAJOR 1)
set(UHTTPD_VERSION_MINOR 0)
@ -6,8 +9,9 @@ set(UHTTPD_VERSION_PATCH 1)
# Check the third party Libraries
find_package(Libubox REQUIRED)
include_directories(${LIBUBOX_INCLUDE_DIR} ${LUA_INCLUDE_DIR})
set(EXTRA_LIBS ${LIBUBOX_LIBRARIES} ${LUA_LIBRARIES} dl)
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${LIBUBOX_INCLUDE_DIR})
set(EXTRA_LIBS ${LIBUBOX_LIBRARY} dl)
set(SOURCE_FILES uhttpd.c client.c log.c utils.c file.c action.c)
set(UHTTPD_DEBUG_CONFIG 0)