Skip to content

Commit 0ab08fc

Browse files
committed
Merged updates to CMake scripts.
2 parents 8e6237c + ba8c573 commit 0ab08fc

File tree

9 files changed

+158
-170
lines changed

9 files changed

+158
-170
lines changed

CMakeLists.txt

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,36 @@
55

66
cmake_minimum_required(VERSION 2.6)
77
project(CPP-NETLIB)
8-
find_package( Boost 1.45.0 )
8+
set(Boost_USE_STATIC_LIBS ON)
9+
set(Boost_USE_MULTI_THREADED ON)
10+
find_package( Boost 1.45.0 REQUIRED unit_test_framework system regex date_time thread filesystem program_options )
911
find_package( OpenSSL )
1012
find_package( Threads )
1113
set(CMAKE_VERBOSE_MAKEFILE true)
1214

1315
if (CMAKE_BUILD_TYPE MATCHES Debug)
1416
add_definitions(-DBOOST_NETWORK_DEBUG)
1517
endif()
16-
if (Boost_FOUND)
17-
set(Boost_USE_STATIC_LIBS ON)
18-
set(Boost_USE_MULTI_THREADED ON)
19-
include_directories(${Boost_INCLUDE_DIRS})
20-
endif(Boost_FOUND)
21-
if (MSVC)
22-
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
23-
endif(MSVC)
24-
if (WIN32)
25-
add_definitions(-D_WIN32_WINNT=0x0501)
26-
endif(WIN32)
27-
enable_testing()
2818

2919
if (OPENSSL_FOUND)
3020
add_definitions(-DBOOST_NETWORK_ENABLE_HTTPS)
3121
endif()
3222

33-
add_subdirectory(libs/network/src)
34-
add_subdirectory(libs/network/test)
35-
#if (NOT MSVC)
36-
# add_subdirectory(libs/mime/test)
37-
#endif(NOT MSVC)
38-
add_subdirectory(libs/network/example)
23+
if (Boost_FOUND)
24+
if (MSVC)
25+
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
26+
endif(MSVC)
27+
if (WIN32)
28+
add_definitions(-D_WIN32_WINNT=0x0501)
29+
endif(WIN32)
30+
include_directories(${Boost_INCLUDE_DIRS})
31+
enable_testing()
32+
add_subdirectory(libs/network/src)
33+
add_subdirectory(libs/network/test)
34+
if (NOT MSVC)
35+
add_subdirectory(libs/mime/test)
36+
endif(NOT MSVC)
37+
add_subdirectory(libs/network/example)
38+
endif(Boost_FOUND)
3939

40+
enable_testing()

boost/network/uri/uri_io.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44

55
# include <boost/network/uri/uri.hpp>
6-
# include <string>
76

87

98
namespace boost {
109
namespace network {
1110
namespace uri {
11+
1212
inline
1313
std::ostream &operator << (std::ostream &os, const uri &uri_) {
1414
return os << uri_.string();

libs/network/example/CMakeLists.txt

Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,61 +4,59 @@
44
# http://www.boost.org/LICENSE_1_0.txt)
55

66
include_directories(${CPP-NETLIB_SOURCE_DIR})
7-
find_package( Boost 1.45.0 COMPONENTS program_options system regex date_time thread filesystem )
8-
find_package( OpenSSL )
9-
find_package( Threads )
10-
11-
if (Boost_FOUND)
12-
set(Boost_USE_STATIC_LIBS ON)
13-
set(Boost_USE_MULTITHREADED ON)
14-
endif (Boost_FOUND)
15-
167
if (OPENSSL_FOUND)
178
include_directories(${OPENSSL_INCLUDE_DIR})
189
endif (OPENSSL_FOUND)
1910

20-
if (Boost_FOUND)
21-
add_executable(http_client http_client.cpp)
22-
add_dependencies(http_client cppnetlib-uri)
23-
target_link_libraries(http_client ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cppnetlib-uri cppnetlib-client-connections)
24-
set_target_properties(http_client PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
25-
if (OPENSSL_FOUND)
26-
target_link_libraries(http_client ${OPENSSL_LIBRARIES})
27-
endif (OPENSSL_FOUND)
28-
29-
add_executable(simple_wget simple_wget.cpp)
30-
add_dependencies(simple_wget cppnetlib-uri)
31-
target_link_libraries(simple_wget ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cppnetlib-uri cppnetlib-client-connections)
32-
set_target_properties(simple_wget PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
33-
if (OPENSSL_FOUND)
34-
target_link_libraries(simple_wget ${OPENSSL_LIBRARIES})
35-
endif (OPENSSL_FOUND)
36-
37-
add_executable(one_liner http/one_liner.cpp)
38-
target_link_libraries(one_liner ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cppnetlib-uri cppnetlib-client-connections)
39-
set_target_properties(one_liner PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
40-
if (OPENSSL_FOUND)
41-
target_link_libraries(one_liner ${OPENSSL_LIBRARIES})
42-
endif (OPENSSL_FOUND)
43-
44-
add_executable(hello_world_server http/hello_world_server.cpp)
45-
target_link_libraries(hello_world_server ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} )
46-
set_target_properties(hello_world_server PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
11+
add_executable(http_client http_client.cpp)
12+
add_executable(simple_wget simple_wget.cpp)
13+
add_executable(hello_world_server http/hello_world_server.cpp)
14+
add_executable(fileserver http/fileserver.cpp)
15+
add_executable(uri uri.cpp)
16+
add_dependencies(http_client cppnetlib-uri cppnetlib-client-connections)
17+
add_dependencies(simple_wget cppnetlib-uri cppnetlib-client-connections)
18+
add_dependencies(uri cppnetlib-uri)
19+
set(BOOST_CLIENT_LIBS
20+
${Boost_PROGRAM_OPTIONS_LIBRARY}
21+
${Boost_THREAD_LIBRARY}
22+
${Boost_SYSTEM_LIBRARY})
23+
24+
set(BOOST_SERVER_LIBS
25+
${Boost_THREAD_LIBRARY}
26+
${Boost_SYSTEM_LIBRARY}
27+
${Boost_PROGRAM_OPTIONS_LIBRARY})
28+
29+
target_link_libraries(http_client
30+
${BOOST_CLIENT_LIBS}
31+
${CMAKE_THREAD_LIBS_INIT}
32+
cppnetlib-uri
33+
cppnetlib-client-connections)
34+
35+
target_link_libraries(simple_wget
36+
${BOOST_CLIENT_LIBS}
37+
${CMAKE_THREAD_LIBS_INIT}
38+
cppnetlib-uri
39+
cppnetlib-client-connections)
40+
41+
target_link_libraries(hello_world_server
42+
${BOOST_SERVER_LIBS}
43+
${CMAKE_THREAD_LIBS_INIT})
4744

48-
if (UNIX)
49-
add_executable(fileserver http/fileserver.cpp)
50-
target_link_libraries(fileserver ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cppnetlib-server-parsers)
51-
set_target_properties(fileserver PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
52-
endif (UNIX)
53-
54-
add_executable(uri uri.cpp)
55-
add_dependencies(uri cppnetlib-uri)
56-
target_link_libraries(uri cppnetlib-uri)
57-
set_target_properties(uri PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
58-
59-
add_executable(uri_builder uri_builder.cpp)
60-
add_dependencies(uri_builder cppnetlib-uri)
61-
target_link_libraries(uri_builder cppnetlib-uri)
62-
set_target_properties(uri_builder PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
45+
if (OPENSSL_FOUND)
46+
target_link_libraries(http_client ${OPENSSL_LIBRARIES})
47+
target_link_libraries(simple_wget ${OPENSSL_LIBRARIES})
48+
target_link_libraries(hello_world_server ${OPENSSL_LIBRARIES})
49+
endif (OPENSSL_FOUND)
6350

64-
endif()
51+
target_link_libraries(fileserver
52+
${BOOST_SERVER_LIBS}
53+
${Boost_FILESYSTEM_LIBRARY}
54+
${CMAKE_THREAD_LIBS_INIT}
55+
cppnetlib-server-parsers)
56+
57+
target_link_libraries(uri cppnetlib-uri)
58+
set_target_properties(http_client PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
59+
set_target_properties(simple_wget PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
60+
set_target_properties(hello_world_server PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
61+
set_target_properties(fileserver PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
62+
set_target_properties(uri PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)

libs/network/example/http_client.cpp

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,21 @@
1111
*/
1212
#include <boost/program_options.hpp>
1313
#include <boost/network/protocol/http.hpp>
14-
#include <boost/function_output_iterator.hpp>
1514
#include <string>
15+
#include <utility>
1616
#include <iostream>
1717

1818
namespace po = boost::program_options;
19-
using namespace std;
20-
21-
struct header_printer {
22-
std::ostream & os;
23-
header_printer(std::ostream & os_) : os(os_) {}
24-
template <class Pair>
25-
void operator()(Pair const & p) {
26-
os << p.first << ": " << p.second << endl;
27-
}
28-
};
2919

3020
int main(int argc, char * argv[]) {
21+
using namespace boost::network;
3122
po::options_description options("Allowed options");
32-
string output_filename, source;
23+
std::string output_filename, source;
3324
bool show_headers;
3425
options.add_options()
3526
("help,h", "produce help message")
3627
("headers,H", "print headers")
37-
("source,s", po::value<string>(&source), "source URL")
28+
("source,s", po::value<std::string>(&source), "source URL")
3829
;
3930

4031
po::positional_options_description positional_options;
@@ -44,47 +35,47 @@ int main(int argc, char * argv[]) {
4435
po::store(po::command_line_parser(argc, argv).options(options).positional(positional_options).run(),
4536
vm);
4637
po::notify(vm);
47-
} catch(exception & e) {
48-
cout << "Error: " << e.what() << endl;
49-
cout << options << endl;
38+
} catch(std::exception & e) {
39+
std::cout << "Error: " << e.what() << std::endl;
40+
std::cout << options << std::endl;
5041
return EXIT_FAILURE;
5142
};
5243

5344
if (vm.count("help")) {
54-
cout << options << endl;
45+
std::cout << options << std::endl;
5546
return EXIT_SUCCESS;
5647
};
5748

5849
if (vm.count("source") < 1) {
59-
cout << "Error: Source URL required." << endl;
60-
cout << options << endl;
50+
std::cout << "Error: Source URL required." << std::endl;
51+
std::cout << options << std::endl;
6152
return EXIT_FAILURE;
6253
};
6354

6455
show_headers = vm.count("headers") ? true : false ;
6556

66-
using namespace boost::network;
6757

6858
typedef http::basic_client<http::tags::http_async_8bit_tcp_resolve, 1, 0>
6959
http_client;
70-
60+
7161
http_client::request request(source);
7262
http_client::string_type destination_ = host(request);
73-
63+
7464
request << ::boost::network::header("Connection", "close");
7565
http_client client(http::_follow_redirects=true);
7666
http_client::response response = client.get(request);
7767

7868
if (show_headers) {
7969
headers_range<http_client::response>::type headers_ = response.headers();
80-
std::copy(headers_.begin(), headers_.end(),
81-
boost::make_function_output_iterator(header_printer(cout)));
82-
cout << endl;
70+
typedef std::pair<std::string, std::string> header_type;
71+
BOOST_FOREACH(header_type const & header, headers_) {
72+
std::cout << header.first << ": " << header.second << std::endl;
73+
}
74+
std::cout << std::endl;
8375
};
84-
76+
8577
body_range<http_client::response>::type body_ = body(response).range();
86-
boost::copy(body_, std::ostream_iterator<char_<http_client::request::tag>::type>(cout));
87-
78+
boost::copy(body_, std::ostream_iterator<char_<http_client::request::tag>::type>(std::cout));
8879
return EXIT_SUCCESS;
8980
}
9081
//]

libs/network/src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88

99
include_directories(${CPP-NETLIB_SOURCE_DIR})
10+
1011
set(CPP-NETLIB_URI_SRCS uri/parse.cpp)
1112
add_library(cppnetlib-uri ${CPP-NETLIB_URI_SRCS})
1213

libs/network/test/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
# http://www.boost.org/LICENSE_1_0.txt)
55

66
include_directories(${CPP-NETLIB_SOURCE_DIR})
7-
find_package( Boost 1.45.0 COMPONENTS unit_test_framework system regex date_time thread filesystem )
8-
set(Boost_USE_STATIC_LIBS ON)
9-
set(Boost_USE_MULTITHREADED ON)
107

118
add_subdirectory(uri)
129
add_subdirectory(http)
@@ -29,7 +26,8 @@ if (Boost_FOUND)
2926
endif()
3027
set_target_properties(cpp-netlib-${test}
3128
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/tests)
32-
add_test(cpp-netlib-${test} ${CPP-NETLIB_BINARY_DIR}/tests/cpp-netlib-${test})
29+
add_test(cpp-netlib-${test}
30+
${CPP-NETLIB_BINARY_DIR}/tests/cpp-netlib-${test})
3331
endforeach (test)
3432

3533
endif()

0 commit comments

Comments
 (0)