Add config.h.in which produces the config.h on CMake configure.
This commit is contained in:
+13
-37
@@ -8,12 +8,10 @@ endif()
|
||||
|
||||
project(webcc)
|
||||
|
||||
option(WEBCC_ENABLE_LOG "Enable logging?" ON)
|
||||
option(WEBCC_ENABLE_SOAP "Enable SOAP support (need pugixml)?" ON)
|
||||
option(WEBCC_ENABLE_SSL "Enable SSL/HTTPS support (need OpenSSL)?" OFF)
|
||||
option(WEBCC_ENABLE_INSTALL "Enable to install library and headers with CMake?" OFF)
|
||||
option(WEBCC_BUILD_UNITTEST "Build unit test?" ON)
|
||||
option(WEBCC_BUILD_EXAMPLE "Build examples?" ON)
|
||||
option(WEBCC_ENABLE_UNITTEST "Build unit test?" ON)
|
||||
option(WEBCC_ENABLE_EXAMPLES "Build examples?" ON)
|
||||
|
||||
if(WIN32)
|
||||
option(WEBCC_ENABLE_VLD "Enable VLD (Visual Leak Detector)?" OFF)
|
||||
@@ -22,36 +20,10 @@ if(WIN32)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(WEBCC_LOG_LEVEL "VERB" CACHE STRING "Log level (VERB, INFO, WARN, ERRO or FATA)")
|
||||
set(WEBCC_ENABLE_LOG 1 CACHE STRING "Enable logging? (0:OFF, 1:ON)")
|
||||
set(WEBCC_LOG_LEVEL 2 CACHE STRING "Log level (0:VERB, 1:INFO, 2:WARN, 3:ERRO or 4:FATA)")
|
||||
|
||||
if(WEBCC_ENABLE_LOG)
|
||||
add_definitions(-DWEBCC_ENABLE_LOG)
|
||||
|
||||
message(STATUS "WEBCC_LOG_LEVEL: ${WEBCC_LOG_LEVEL}")
|
||||
|
||||
# Add definition of WEBCC_LOG_LEVEL according variable WEBCC_LOG_LEVEL.
|
||||
if(WEBCC_LOG_LEVEL MATCHES "^VERB$")
|
||||
add_definitions(-DWEBCC_LOG_LEVEL=0)
|
||||
elseif(WEBCC_LOG_LEVEL MATCHES "^INFO$")
|
||||
add_definitions(-DWEBCC_LOG_LEVEL=1)
|
||||
elseif(WEBCC_LOG_LEVEL MATCHES "^WARN$")
|
||||
add_definitions(-DWEBCC_LOG_LEVEL=2)
|
||||
elseif(WEBCC_LOG_LEVEL MATCHES "^ERRO$")
|
||||
add_definitions(-DWEBCC_LOG_LEVEL=3)
|
||||
elseif(WEBCC_LOG_LEVEL MATCHES "^FATA$")
|
||||
add_definitions(-DWEBCC_LOG_LEVEL=4)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(WEBCC_ENABLE_SOAP)
|
||||
add_definitions(-DWEBCC_ENABLE_SOAP)
|
||||
endif()
|
||||
|
||||
if(WEBCC_ENABLE_SSL)
|
||||
add_definitions(-DWEBCC_ENABLE_SSL)
|
||||
endif()
|
||||
|
||||
if(WEBCC_BUILD_UNITTEST)
|
||||
if(WEBCC_ENABLE_UNITTEST)
|
||||
enable_testing()
|
||||
endif()
|
||||
|
||||
@@ -121,8 +93,12 @@ if(WEBCC_ENABLE_SSL)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# For including its own headers as "webcc/http_client.h".
|
||||
include_directories(${PROJECT_SOURCE_DIR})
|
||||
include_directories(
|
||||
# For including its own headers as "webcc/http_client.h".
|
||||
${PROJECT_SOURCE_DIR}
|
||||
# For including config.h as "webcc/config.h".
|
||||
${PROJECT_BINARY_DIR}
|
||||
)
|
||||
|
||||
set(THIRD_PARTY_DIR ${PROJECT_SOURCE_DIR}/third_party)
|
||||
|
||||
@@ -141,7 +117,7 @@ endif()
|
||||
|
||||
add_subdirectory(webcc)
|
||||
|
||||
if(WEBCC_BUILD_EXAMPLE)
|
||||
if(WEBCC_ENABLE_EXAMPLES)
|
||||
add_subdirectory(example/http_hello_client)
|
||||
add_subdirectory(example/http_hello_async_client)
|
||||
|
||||
@@ -167,7 +143,7 @@ if(WEBCC_BUILD_EXAMPLE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(WEBCC_BUILD_UNITTEST)
|
||||
if(WEBCC_ENABLE_UNITTEST)
|
||||
add_subdirectory(third_party/src/gtest)
|
||||
add_subdirectory(unittest)
|
||||
endif()
|
||||
|
||||
+8
-10
@@ -1,14 +1,12 @@
|
||||
# Unit test
|
||||
if(WEBCC_BUILD_UNITTEST)
|
||||
set(UT_SRCS
|
||||
rest_service_manager_test.cc
|
||||
)
|
||||
set(UT_SRCS
|
||||
rest_service_manager_test.cc
|
||||
)
|
||||
|
||||
set(UT_TARGET_NAME webcc_unittest)
|
||||
set(UT_TARGET_NAME webcc_unittest)
|
||||
|
||||
add_executable(${UT_TARGET_NAME} ${UT_SRCS})
|
||||
target_link_libraries(${UT_TARGET_NAME} webcc pugixml gtest ${Boost_LIBRARIES})
|
||||
target_link_libraries(${UT_TARGET_NAME} "${CMAKE_THREAD_LIBS_INIT}")
|
||||
add_executable(${UT_TARGET_NAME} ${UT_SRCS})
|
||||
target_link_libraries(${UT_TARGET_NAME} webcc pugixml gtest ${Boost_LIBRARIES})
|
||||
target_link_libraries(${UT_TARGET_NAME} "${CMAKE_THREAD_LIBS_INIT}")
|
||||
|
||||
add_test(${UT_TARGET_NAME} ${UT_TARGET_NAME})
|
||||
endif()
|
||||
add_test(${UT_TARGET_NAME} ${UT_TARGET_NAME})
|
||||
|
||||
@@ -12,15 +12,12 @@ class TestRestService : public webcc::RestService {
|
||||
TEST(RestServiceManager, URL_RegexBasic) {
|
||||
webcc::RestServiceManager service_manager;
|
||||
|
||||
{
|
||||
webcc::RestServicePtr service = std::make_shared<TestRestService>();
|
||||
|
||||
service_manager.AddService(service, "/instances/(\\d+)", true);
|
||||
}
|
||||
service_manager.AddService(std::make_shared<TestRestService>(),
|
||||
"/instance/(\\d+)", true);
|
||||
|
||||
std::vector<std::string> sub_matches;
|
||||
|
||||
std::string url = "/instances/12345";
|
||||
std::string url = "/instance/12345";
|
||||
webcc::RestServicePtr service = service_manager.GetService(url, &sub_matches);
|
||||
|
||||
EXPECT_TRUE(!!service);
|
||||
@@ -28,7 +25,33 @@ TEST(RestServiceManager, URL_RegexBasic) {
|
||||
EXPECT_EQ(1, sub_matches.size());
|
||||
EXPECT_EQ("12345", sub_matches[0]);
|
||||
|
||||
url = "/instances/abcde";
|
||||
url = "/instance/abcde";
|
||||
sub_matches.clear();
|
||||
service = service_manager.GetService(url, &sub_matches);
|
||||
|
||||
EXPECT_FALSE(!!service);
|
||||
}
|
||||
|
||||
TEST(RestServiceManager, URL_RegexMultiple) {
|
||||
webcc::RestServiceManager service_manager;
|
||||
|
||||
service_manager.AddService(std::make_shared<TestRestService>(),
|
||||
"/study/(\\d+)/series/(\\d+)/instance/(\\d+)",
|
||||
true);
|
||||
|
||||
std::vector<std::string> sub_matches;
|
||||
|
||||
std::string url = "/study/1/series/2/instance/3";
|
||||
webcc::RestServicePtr service = service_manager.GetService(url, &sub_matches);
|
||||
|
||||
EXPECT_TRUE(!!service);
|
||||
|
||||
EXPECT_EQ(3, sub_matches.size());
|
||||
EXPECT_EQ("1", sub_matches[0]);
|
||||
EXPECT_EQ("2", sub_matches[1]);
|
||||
EXPECT_EQ("3", sub_matches[2]);
|
||||
|
||||
url = "/study/a/series/b/instance/c";
|
||||
sub_matches.clear();
|
||||
service = service_manager.GetService(url, &sub_matches);
|
||||
|
||||
@@ -38,10 +61,8 @@ TEST(RestServiceManager, URL_RegexBasic) {
|
||||
TEST(RestServiceManager, URL_NonRegex) {
|
||||
webcc::RestServiceManager service_manager;
|
||||
|
||||
{
|
||||
webcc::RestServicePtr service = std::make_shared<TestRestService>();
|
||||
service_manager.AddService(service, "/instances", false);
|
||||
}
|
||||
service_manager.AddService(std::make_shared<TestRestService>(), "/instances",
|
||||
false);
|
||||
|
||||
std::vector<std::string> sub_matches;
|
||||
std::string url = "/instances";
|
||||
|
||||
+10
-7
@@ -5,6 +5,11 @@ if(MSVC)
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
|
||||
configure_file(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/config.h.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/config.h"
|
||||
)
|
||||
|
||||
# Adhere to GNU filesystem layout conventions.
|
||||
include(GNUInstallDirs)
|
||||
|
||||
@@ -102,10 +107,8 @@ set(TARGET webcc)
|
||||
|
||||
add_library(${TARGET} STATIC ${HEADERS} ${SOURCES})
|
||||
|
||||
if(WEBCC_ENABLE_INSTALL)
|
||||
# Install lib and header files.
|
||||
# On Linux, if CMAKE_INSTALL_PREFIX is ~, the lib (libwebcc.a) will be installed
|
||||
# to ~/lib and header files will be installed to ~/include.
|
||||
install(TARGETS ${TARGET} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
install(FILES ${HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/webcc)
|
||||
endif()
|
||||
# Install lib and header files.
|
||||
# On Linux, if CMAKE_INSTALL_PREFIX is ~, the lib (libwebcc.a) will be installed
|
||||
# to ~/lib and header files will be installed to ~/include.
|
||||
install(TARGETS ${TARGET} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
install(FILES ${HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/webcc)
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef WEBCC_CONFIG_H_
|
||||
#define WEBCC_CONFIG_H_
|
||||
|
||||
// Compile configurations.
|
||||
|
||||
#define WEBCC_ENABLE_LOG @WEBCC_ENABLE_LOG@
|
||||
|
||||
#if WEBCC_ENABLE_LOG
|
||||
#define WEBCC_LOG_LEVEL @WEBCC_LOG_LEVEL@
|
||||
#endif
|
||||
|
||||
#endif // WEBCC_CONFIG_H_
|
||||
+3
-2
@@ -3,6 +3,9 @@
|
||||
|
||||
// Simple console logger.
|
||||
|
||||
// This file was generated from "config.h.in" by CMake.
|
||||
#include "webcc/config.h"
|
||||
|
||||
#if WEBCC_ENABLE_LOG
|
||||
|
||||
#include <cstring> // for strrchr()
|
||||
@@ -16,8 +19,6 @@
|
||||
#define WEBCC_FATA 4
|
||||
|
||||
// Default log level.
|
||||
// You have to define a proper log level in CMakeLists.txt, e.g.,
|
||||
// add_definitions(-DWEBCC_LOG_LEVEL=2)
|
||||
#ifndef WEBCC_LOG_LEVEL
|
||||
#define WEBCC_LOG_LEVEL WEBCC_WARN
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user