diff --git a/CMakeLists.txt b/CMakeLists.txt index 9785c2e7a..519146c14 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,12 +7,25 @@ cmake_minimum_required(VERSION 2.8) project(CPP-NETLIB) +option(BUILD_SHARED_LIBS "Build cpp-netlib as shared libraries." OFF) +option(BUILD_TESTS "Build the unit tests." ON) +option(BUILD_EXAMPLES "Build the examples using cpp-netlib." ON) + set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}) find_package( ICU ) -set(Boost_USE_STATIC_LIBS ON) +if(BUILD_SHARED_LIBS) + set(Boost_USE_STATIC_LIBS OFF) +else() + set(Boost_USE_STATIC_LIBS ON) +endif() set(Boost_USE_MULTITHREADED ON) -find_package( Boost 1.45.0 REQUIRED unit_test_framework system regex date_time thread chrono filesystem program_options ) +if(BUILD_TESTS) + set(Boost_COMPONENTS unit_test_framework system regex date_time thread chrono filesystem program_options ) +else() + set(Boost_COMPONENTS system regex date_time thread chrono filesystem program_options ) +endif() +find_package( Boost 1.51 REQUIRED ${Boost_COMPONENTS} ) find_package( OpenSSL ) find_package( Threads ) set(CMAKE_VERBOSE_MAKEFILE true) @@ -51,13 +64,27 @@ if (Boost_FOUND) add_definitions(-D_WIN32_WINNT=0x0501) endif(WIN32) include_directories(${Boost_INCLUDE_DIRS}) - enable_testing() + if(BUILD_TESTS) + enable_testing() + endif() add_subdirectory(libs/network/src) - add_subdirectory(libs/network/test) - if (NOT MSVC) - add_subdirectory(libs/mime/test) - endif(NOT MSVC) - add_subdirectory(libs/network/example) + if(BUILD_TESTS) + enable_testing() + add_subdirectory(libs/network/test) + if (NOT MSVC) + add_subdirectory(libs/mime/test) + endif(NOT MSVC) + endif() + if(BUILD_EXAMPLES) + add_subdirectory(libs/network/example) + endif() endif(Boost_FOUND) -enable_testing() +if(BUILD_TESTS) + enable_testing() +endif() + +message(STATUS "Options selected:") +message(STATUS " BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}\t(Build cpp-netlib as shared libraries: OFF, ON)") +message(STATUS " BUILD_TESTS: ${BUILD_TESTS}\t(Build the unit tests: ON, OFF)") +message(STATUS " BUILD_EXAMPLES: ${BUILD_EXAMPLES}\t(Build the examples using cpp-netlib: ON, OFF)") diff --git a/libs/mime/test/CMakeLists.txt b/libs/mime/test/CMakeLists.txt index 141b077ee..8c1ac68ae 100644 --- a/libs/mime/test/CMakeLists.txt +++ b/libs/mime/test/CMakeLists.txt @@ -1,7 +1,4 @@ include_directories(${CPP-NETLIB_SOURCE_DIR}) -find_package ( Boost 1.41.0 COMPONENTS unit_test_framework ) -set ( Boost_USE_STATIC_LIBS ON ) -set ( Boost_USE_MULTITHREADED ON ) if ( Boost_FOUND ) add_executable ( mime-roundtrip mime-roundtrip.cpp ) diff --git a/libs/network/src/CMakeLists.txt b/libs/network/src/CMakeLists.txt index a94600d55..c41f5d612 100644 --- a/libs/network/src/CMakeLists.txt +++ b/libs/network/src/CMakeLists.txt @@ -61,7 +61,7 @@ endforeach(src_file) set(CPP-NETLIB_HTTP_MESSAGE_SRCS http/request.cpp http/response.cpp) add_library(cppnetlib-http-message ${CPP-NETLIB_HTTP_MESSAGE_SRCS}) add_dependencies(cppnetlib-http-message - ${Boost_LIBRARIES} +# ${Boost_LIBRARIES} cppnetlib-message) target_link_libraries(cppnetlib-http-message ${Boost_LIBRARIES} @@ -99,7 +99,6 @@ set(CPP-NETLIB_HTTP_SERVER_SRCS ) add_library(cppnetlib-http-server ${CPP-NETLIB_HTTP_SERVER_SRCS}) add_dependencies(cppnetlib-http-server - ${Boost_LIBRARIES} cppnetlib-constants cppnetlib-uri cppnetlib-message @@ -108,6 +107,7 @@ add_dependencies(cppnetlib-http-server cppnetlib-http-message cppnetlib-http-message-wrappers cppnetlib-http-server-parsers + cppnetlib-utils-thread_pool ) target_link_libraries(cppnetlib-http-server ${Boost_LIBRARIES} @@ -119,6 +119,7 @@ target_link_libraries(cppnetlib-http-server cppnetlib-http-message cppnetlib-http-message-wrappers cppnetlib-http-server-parsers + cppnetlib-utils-thread_pool ) foreach (src_file ${CPP-NETLIB_HTTP_SERVER_SRCS}) if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU) @@ -150,7 +151,6 @@ set(CPP-NETLIB_HTTP_CLIENT_SRCS http/client.cpp) add_library(cppnetlib-http-client ${CPP-NETLIB_HTTP_CLIENT_SRCS}) add_dependencies(cppnetlib-http-client - ${Boost_LIBRARIES} cppnetlib-constants cppnetlib-uri cppnetlib-message diff --git a/libs/network/test/CMakeLists.txt b/libs/network/test/CMakeLists.txt index c482ac85b..6baf32d47 100644 --- a/libs/network/test/CMakeLists.txt +++ b/libs/network/test/CMakeLists.txt @@ -5,6 +5,10 @@ include_directories(${CPP-NETLIB_SOURCE_DIR}/include) +if(BUILD_SHARED_LIBS) + add_definitions(-DBUILD_SHARED_LIBS) +endif() + add_subdirectory(uri) add_subdirectory(http) diff --git a/libs/network/test/http/client_constructor_test.cpp b/libs/network/test/http/client_constructor_test.cpp index 327e7f5a2..e1f789cee 100644 --- a/libs/network/test/http/client_constructor_test.cpp +++ b/libs/network/test/http/client_constructor_test.cpp @@ -5,6 +5,9 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) +#ifdef BUILD_SHARED_LIBS +# define BOOST_TEST_DYN_LINK +#endif #define BOOST_TEST_MODULE HTTP 1.0 Client Constructor Test #include #include diff --git a/libs/network/test/http/client_get_different_port_test.cpp b/libs/network/test/http/client_get_different_port_test.cpp index f2f7ef9ed..3d929e356 100644 --- a/libs/network/test/http/client_get_different_port_test.cpp +++ b/libs/network/test/http/client_get_different_port_test.cpp @@ -5,6 +5,9 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) +#ifdef BUILD_SHARED_LIBS +# define BOOST_TEST_DYN_LINK +#endif #define BOOST_TEST_MODULE HTTP Client Get Different Port Test #include #include diff --git a/libs/network/test/http/client_get_streaming_test.cpp b/libs/network/test/http/client_get_streaming_test.cpp index fba0d83d1..92c2a0668 100644 --- a/libs/network/test/http/client_get_streaming_test.cpp +++ b/libs/network/test/http/client_get_streaming_test.cpp @@ -4,6 +4,9 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) +#ifdef BUILD_SHARED_LIBS +# define BOOST_TEST_DYN_LINK +#endif #define BOOST_TEST_MODULE HTTP 1.1 Get Streaming Test #include #include diff --git a/libs/network/test/http/client_get_test.cpp b/libs/network/test/http/client_get_test.cpp index f60bc1ba3..6bd1dac36 100644 --- a/libs/network/test/http/client_get_test.cpp +++ b/libs/network/test/http/client_get_test.cpp @@ -4,6 +4,9 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) +#ifdef BUILD_SHARED_LIBS +# define BOOST_TEST_DYN_LINK +#endif #define BOOST_TEST_MODULE HTTP 1.0 Get Test #include #include diff --git a/libs/network/test/http/client_get_timeout_test.cpp b/libs/network/test/http/client_get_timeout_test.cpp index 7529b4491..d8cfb768d 100644 --- a/libs/network/test/http/client_get_timeout_test.cpp +++ b/libs/network/test/http/client_get_timeout_test.cpp @@ -5,6 +5,9 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) +#ifdef BUILD_SHARED_LIBS +# define BOOST_TEST_DYN_LINK +#endif #define BOOST_TEST_MODULE HTTP Client Get Timeout Test #include #include diff --git a/libs/network/test/http/request_base_test.cpp b/libs/network/test/http/request_base_test.cpp index fd8ebbf7a..354a6debe 100644 --- a/libs/network/test/http/request_base_test.cpp +++ b/libs/network/test/http/request_base_test.cpp @@ -4,6 +4,9 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) +#ifdef BUILD_SHARED_LIBS +# define BOOST_TEST_DYN_LINK +#endif #define BOOST_TEST_MODULE HTTP Request Storage Base Test #include #include diff --git a/libs/network/test/http/request_linearize_test.cpp b/libs/network/test/http/request_linearize_test.cpp index 4aa93ade0..336f4c1d1 100644 --- a/libs/network/test/http/request_linearize_test.cpp +++ b/libs/network/test/http/request_linearize_test.cpp @@ -5,6 +5,9 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) +#ifdef BUILD_SHARED_LIBS +# define BOOST_TEST_DYN_LINK +#endif #define BOOST_TEST_MODULE HTTP Request Linearize Test #include #include diff --git a/libs/network/test/http/request_test.cpp b/libs/network/test/http/request_test.cpp index 59763e3f9..632ae9a07 100644 --- a/libs/network/test/http/request_test.cpp +++ b/libs/network/test/http/request_test.cpp @@ -4,6 +4,9 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) +#ifdef BUILD_SHARED_LIBS +# define BOOST_TEST_DYN_LINK +#endif #define BOOST_TEST_MODULE HTTP Request Test #include #include diff --git a/libs/network/test/http/response_test.cpp b/libs/network/test/http/response_test.cpp index bd2c176a6..4e93db284 100644 --- a/libs/network/test/http/response_test.cpp +++ b/libs/network/test/http/response_test.cpp @@ -4,6 +4,9 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) +#ifdef BUILD_SHARED_LIBS +# define BOOST_TEST_DYN_LINK +#endif #define BOOST_TEST_MODULE HTTP Client Response Test #include #include diff --git a/libs/network/test/http/server_async_run_stop_concurrency.cpp b/libs/network/test/http/server_async_run_stop_concurrency.cpp index d602ad94d..70d2602e1 100644 --- a/libs/network/test/http/server_async_run_stop_concurrency.cpp +++ b/libs/network/test/http/server_async_run_stop_concurrency.cpp @@ -1,3 +1,7 @@ +#ifdef BUILD_SHARED_LIBS +# define BOOST_TEST_DYN_LINK +# define BOOST_TEST_NO_MAIN +#endif #define BOOST_TEST_MODULE HTTP Asynchronous Server Tests #include diff --git a/libs/network/test/http/server_constructor_test.cpp b/libs/network/test/http/server_constructor_test.cpp index a45179ba5..35907a634 100644 --- a/libs/network/test/http/server_constructor_test.cpp +++ b/libs/network/test/http/server_constructor_test.cpp @@ -5,6 +5,9 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) +#ifdef BUILD_SHARED_LIBS +# define BOOST_TEST_DYN_LINK +#endif #define BOOST_TEST_MODULE HTTP Server Construtor Tests #include diff --git a/libs/network/test/message_test.cpp b/libs/network/test/message_test.cpp index 3ec45e1d4..63b958c9c 100644 --- a/libs/network/test/message_test.cpp +++ b/libs/network/test/message_test.cpp @@ -5,6 +5,9 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) +#ifdef BUILD_SHARED_LIBS +# define BOOST_TEST_DYN_LINK +#endif #define BOOST_TEST_MODULE message test #include #include diff --git a/libs/network/test/message_transform_test.cpp b/libs/network/test/message_transform_test.cpp index 3a5d21e71..b021b4ecf 100644 --- a/libs/network/test/message_transform_test.cpp +++ b/libs/network/test/message_transform_test.cpp @@ -5,6 +5,9 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) +#ifdef BUILD_SHARED_LIBS +# define BOOST_TEST_DYN_LINK +#endif #define BOOST_TEST_MODULE message test #include #include diff --git a/libs/network/test/uri/relative_uri_test.cpp b/libs/network/test/uri/relative_uri_test.cpp index 08ebbfd47..d7855fe50 100644 --- a/libs/network/test/uri/relative_uri_test.cpp +++ b/libs/network/test/uri/relative_uri_test.cpp @@ -4,6 +4,9 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) +#ifdef BUILD_SHARED_LIBS +# define BOOST_TEST_DYN_LINK +#endif #define BOOST_TEST_MODULE Relative URL Test #include #include diff --git a/libs/network/test/uri/scheme_tests.cpp b/libs/network/test/uri/scheme_tests.cpp index 42df85482..fa4c01dca 100644 --- a/libs/network/test/uri/scheme_tests.cpp +++ b/libs/network/test/uri/scheme_tests.cpp @@ -3,6 +3,9 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) +#ifdef BUILD_SHARED_LIBS +# define BOOST_TEST_DYN_LINK +#endif #define BOOST_TEST_MODULE URI Scheme Test #include #include diff --git a/libs/network/test/uri/uri_builder_stream_test.cpp b/libs/network/test/uri/uri_builder_stream_test.cpp index 73ab0dbb5..beb6c5376 100644 --- a/libs/network/test/uri/uri_builder_stream_test.cpp +++ b/libs/network/test/uri/uri_builder_stream_test.cpp @@ -4,6 +4,9 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) +#ifdef BUILD_SHARED_LIBS +# define BOOST_TEST_DYN_LINK +#endif #define BOOST_TEST_MODULE URI builder stream test #include #include diff --git a/libs/network/test/uri/uri_builder_test.cpp b/libs/network/test/uri/uri_builder_test.cpp index e04a0c3c4..605c63fd3 100644 --- a/libs/network/test/uri/uri_builder_test.cpp +++ b/libs/network/test/uri/uri_builder_test.cpp @@ -4,6 +4,9 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) +#ifdef BUILD_SHARED_LIBS +# define BOOST_TEST_DYN_LINK +#endif #define BOOST_TEST_MODULE URI builder test #include #include diff --git a/libs/network/test/uri/uri_encoding_test.cpp b/libs/network/test/uri/uri_encoding_test.cpp index 6a2b4fa98..eba1079f0 100644 --- a/libs/network/test/uri/uri_encoding_test.cpp +++ b/libs/network/test/uri/uri_encoding_test.cpp @@ -4,6 +4,9 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) +#ifdef BUILD_SHARED_LIBS +# define BOOST_TEST_DYN_LINK +#endif #define BOOST_TEST_MODULE URI encoding test #include #include diff --git a/libs/network/test/uri/uri_test.cpp b/libs/network/test/uri/uri_test.cpp index 360ee0be0..9b9202015 100644 --- a/libs/network/test/uri/uri_test.cpp +++ b/libs/network/test/uri/uri_test.cpp @@ -4,6 +4,9 @@ // (See accompanying file LICENSE_1_0.txt of copy at // http://www.boost.org/LICENSE_1_0.txt) +#ifdef BUILD_SHARED_LIBS +# define BOOST_TEST_DYN_LINK +#endif #define BOOST_TEST_MODULE URI Test #include #include diff --git a/libs/network/test/utils_thread_pool.cpp b/libs/network/test/utils_thread_pool.cpp index 7bbb75ef5..8a615fb5e 100644 --- a/libs/network/test/utils_thread_pool.cpp +++ b/libs/network/test/utils_thread_pool.cpp @@ -5,6 +5,9 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) +#ifdef BUILD_SHARED_LIBS +# define BOOST_TEST_DYN_LINK +#endif #define BOOST_TEST_MODULE utils thread pool test #include #include