diff --git a/CMakeLists.txt b/CMakeLists.txt index 7037f6d..c9d03e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required (VERSION 3.10.0) set(CMAKE_CXX_STANDARD 14) @@ -6,15 +6,28 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/bin) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/lib) +# Read version from file VERSION +FILE(READ "VERSION" project_VERSION) +STRING(STRIP "${project_VERSION}" project_VERSION) + +SET(LICENSE "MIT") +cmake_policy(SET CMP0022 NEW) + +PROJECT(HTTPClient VERSION ${project_VERSION} LANGUAGES CXX) + if(NOT MSVC) add_definitions(-DLINUX) else() add_definitions(-DWINDOWS) endif() +option(SKIP_TESTS_BUILD "Skip tests build" ON) + include_directories(HTTP) add_subdirectory(HTTP) + +if(NOT SKIP_TESTS_BUILD) add_subdirectory(TestHTTP) include(CTest) @@ -28,3 +41,4 @@ IF (NOT TEST_INI_FILE) ENDIF() add_test (NAME HttpClientTest COMMAND test_httpclient ${TEST_INI_FILE}) +endif(NOT SKIP_TESTS_BUILD) diff --git a/HTTP/CMakeLists.txt b/HTTP/CMakeLists.txt index 985dbbe..2a03e89 100644 --- a/HTTP/CMakeLists.txt +++ b/HTTP/CMakeLists.txt @@ -1,9 +1,8 @@ -cmake_minimum_required(VERSION 2.6) - -project(HTTPClient) IF(MSVC OR NOT CMAKE_BUILD_TYPE MATCHES Coverage) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) + # Locate libcURL find_package(CURL REQUIRED) include_directories(${CURL_INCLUDE_DIRS}) @@ -11,4 +10,6 @@ include_directories(${CURL_INCLUDE_DIRS}) file(GLOB_RECURSE source_files ./*) add_library(httpclient STATIC ${source_files}) +install(TARGETS httpclient) + ENDIF() diff --git a/README.md b/README.md index ec07ae4..c4b60f0 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ Compilation has been tested with: Underlying libraries: - [libcurl](http://curl.haxx.se/libcurl/) +Windows Users : vcpkg (Microsoft C++ Library Manager) can be used to easily install libcurl and generate the Visual Studio solution with CMake. With vcpkg, no need to manually copy the DLL in the output directory, vcpkg handles all that ! Look at "Building under Windows via Visual Studio" section, for instructions. + ## Usage Create an object and provide to its constructor a callable object (for log printing) having this signature : @@ -170,11 +172,6 @@ The unit test "TestDownloadFile" demonstrates how to use a progress function to ## Thread Safety -A mutex is used to increment/decrement atomically the count of CHTTPClient objects. - -`curl_global_init` is called when the count of CHTTPClient objects equals to zero (when instanciating the first object). -`curl_global_cleanup` is called when the count of CHTTPClient objects become zero (when all CHTTPClient objects are destroyed). - Do not share CHTTPClient objects across threads as this would mean accessing libcurl handles from multiple threads at the same time which is not allowed. @@ -232,7 +229,35 @@ To directly run the unit test binary, you must indicate the path of the INI conf ### Building under Windows via Visual Studio -This can be enhanced in future... +1. New Procedure (with vcpkg) : + +Install [vcpkg](https://github.com/microsoft/vcpkg) then install libcurl (use 'x86-windows' for the 32-bit version) : +```Shell +.\vcpkg install curl curl[openssl] --triplet=x64-windows +``` + +If you have a french Visual Studio version, don't forget to install the english language pack (vcpkg will tell you this anyway). + +Download and install the latest version of CMake : https://cmake.org/download/ (e.g. Windows win64-x64 Installer) + +Open CMake (cmake-gui) + +In "Where is the source code", put the httpclient-cpp path (e.g. C:/Users/Amine/Documents/Work/PROJECTS/GitHub/httpclient-cpp), where the main CMakeLists.txt file exist. + +In "Where to build binaries", paste the directory where you want to build the project (e.g. C:/Users/Amine/Documents/Work/PROJECTS/GitHub/httpclient_build) + +Click on "Configure". + +Select your Visual Studio version (if it isn't already set). +In "Optional platform for generator", you can leave it empty (x64 by default) or choose another value. + +Click on the radio button "Specify toolchain file for cross-compiling, then hit the "Next" button. + +In "Specify the toolchain file", browse to vcpkg toolchain file (vcpkg/scripts/buildsystems/vcpkg.cmake) and select it. + +Press "Finish", wait until CMake configures the project then hit "Generate" to create the Visual Studio solution (library and unit test binary). + +2. Old Procedure (without vcpkg) : First of all, build libcurl using this fork of build-libcurl-windows : https://github.com/ribtoks/build-libcurl-windows @@ -376,3 +401,9 @@ Try to preserve the existing coding style (Hungarian notation, indentation etc.. If you compile the test program with the preprocessor macro DEBUG_CURL, to enable curl debug informations, the static library used must also be compiled with that macro. Don't forget to mention a path where to store log files in the INI file if you want to use that feature in the unit test program (curl_logs_folder under [local]) + +### File names format when compiling with Visual Studio (Windows users) + +It is assumed that the FTP server is supporting UTF-8. You must feed the FTP client API with paths/file names encoded in UTF-8 and NOT in ANSI (Windows-1252 on Western/U.S. systems but iy can represent certain other Windows code pages on other systems, ANSI is just an extension for ASCII). Look at the unit tests for examples (look for the preprocessor macro WINDOWS to find them quickly). + +If you limit to ASCII characters, you don't need to convert your ANSI strings to UTF-8. diff --git a/TestHTTP/CMakeLists.txt b/TestHTTP/CMakeLists.txt index 0eadc39..7e18db8 100644 --- a/TestHTTP/CMakeLists.txt +++ b/TestHTTP/CMakeLists.txt @@ -1,7 +1,3 @@ -cmake_minimum_required(VERSION 2.6) - -project(TestHTTPClient) - # Code coverage setup IF(CMAKE_BUILD_TYPE MATCHES Coverage) INCLUDE(CodeCoverage.cmake) @@ -13,43 +9,9 @@ ENDIF(CMAKE_BUILD_TYPE MATCHES Coverage) find_package(CURL REQUIRED) include_directories(${CURL_INCLUDE_DIRS}) -# For Windows -# https://crascit.com/2015/07/25/cmake-gtest/ -if (MSVC) - # Download and unpack googletest at configure time - configure_file(CMakeLists.txt.in "${CMAKE_BINARY_DIR}/googletest-download/CMakeLists.txt") - execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" . - WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/googletest-download" ) - execute_process(COMMAND "${CMAKE_COMMAND}" --build . - WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/googletest-download" ) - - # Prevent GoogleTest from overriding our compiler/linker options - # when building with Visual Studio - set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) - - # Add googletest directly to our build. This adds - # the following targets: gtest, gtest_main, gmock - # and gmock_main - add_subdirectory("${CMAKE_BINARY_DIR}/googletest-src" - "${CMAKE_BINARY_DIR}/googletest-build") - - # The gtest/gmock targets carry header search path - # dependencies automatically when using CMake 2.8.11 or - # later. Otherwise we have to add them here ourselves. - if(CMAKE_VERSION VERSION_LESS 2.8.11) - include_directories("${gtest_SOURCE_DIR}/include" - "${gmock_SOURCE_DIR}/include") - endif() - - # Now simply link your own targets against gtest, gmock, - # etc. as appropriate -endif() - # Locate GTest -if(NOT MSVC) - find_package(GTest REQUIRED) - include_directories(${GTEST_INCLUDE_DIRS}) -endif() +find_package(GTest REQUIRED) +include_directories(${GTEST_INCLUDE_DIRS}) # useless but test before removing it include_directories(../HTTP) include_directories(./simpleini) @@ -87,7 +49,7 @@ add_executable(test_httpclient main.cpp test_utils.cpp) if(NOT MSVC) target_link_libraries(test_httpclient httpclient ${GTEST_LIBRARIES} pthread curl) else() - target_link_libraries(test_httpclient httpclient gtest ${CURL_LIBRARIES}) + target_link_libraries(test_httpclient httpclient ${GTEST_LIBRARIES} ${CURL_LIBRARIES}) endif() ENDIF() diff --git a/TestHTTP/CMakeLists.txt.in b/TestHTTP/CMakeLists.txt.in deleted file mode 100644 index e700161..0000000 --- a/TestHTTP/CMakeLists.txt.in +++ /dev/null @@ -1,15 +0,0 @@ -cmake_minimum_required(VERSION 2.8.2) - -project(googletest-download-for-windows NONE) - -include(ExternalProject) -ExternalProject_Add(googletest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG master - SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src" - BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build" - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - TEST_COMMAND "" -) diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..6e8bf73 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.1.0