From 6134edc96ef3952936570ec5c3fae79e1ad8a0f8 Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Fri, 20 Oct 2017 16:04:46 +0200 Subject: [PATCH 1/5] Make the CURL dependency optional, through the PLANETBLUPI_HTTP_VERSION_CHECK CMake option --- CMakeLists.txt | 26 +++++++++++++++++++++++--- src/blupi.cxx | 10 +++++++++- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a0a456..06bd22e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,8 @@ set (PB_PRODUCT_NAME "Planet Blupi") set (PB_PACKAGE_NAME "planetblupi") set (PB_DESCRIPTION "Planet Blupi - A delerious spell-binding game") +option(PLANETBLUPI_HTTP_VERSION_CHECK "Run a version check over HTTP (with CURL)" OFF) + configure_file ( "${PROJECT_SOURCE_DIR}/src/config.h.in" "${PROJECT_BINARY_DIR}/include/config.h" @@ -115,7 +117,10 @@ find_package (PkgConfig REQUIRED) pkg_search_module (SDL2 REQUIRED sdl2) pkg_search_module (SDL2_MIXER REQUIRED SDL2_mixer) pkg_search_module (SDL2_IMAGE REQUIRED SDL2_image) -pkg_search_module (CURL REQUIRED libcurl) +if(${PLANETBLUPI_HTTP_VERSION_CHECK}) + pkg_search_module (CURL REQUIRED libcurl) + add_definitions(-DUSE_CURL) +endif() if ("${STATIC_BUILD}") pkg_search_module (PNG REQUIRED libpng) @@ -131,7 +136,9 @@ if ("${STATIC_BUILD}") pkg_search_module (PULSE REQUIRED libpulse) endif () - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCURL_STATICLIB") + if(${PLANETBLUPI_HTTP_VERSION_CHECK}) + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCURL_STATICLIB") + endif () endif () ########################### @@ -147,7 +154,6 @@ if ("${STATIC_BUILD}") ${SDL2_STATIC_LIBRARIES} ${SDL2_MIXER_STATIC_LIBRARIES} ${SDL2_IMAGE_STATIC_LIBRARIES} - ${CURL_STATIC_LIBRARIES} ${SDLKitchensink_STATIC_LIBRARIES} ${PNG_STATIC_LIBRARIES} ${AVCODEC_STATIC_LIBRARIES} @@ -157,6 +163,13 @@ if ("${STATIC_BUILD}") ${SWRESAMPLE_STATIC_LIBRARIES} ) + if(${PLANETBLUPI_HTTP_VERSION_CHECK}) + set (planetblupi_DEPS + ${planetblupi_DEPS} + ${CURL_STATIC_LIBRARIES} + ) + endif () + if (UNIX AND NOT APPLE) list (APPEND planetblupi_DEPS ${ALSA_STATIC_LIBRARIES} @@ -173,6 +186,13 @@ else () ${SDLKitchensink_LIBRARIES} pthread ) + + if(${PLANETBLUPI_HTTP_VERSION_CHECK}) + set (planetblupi_DEPS + ${planetblupi_DEPS} + ${CURL_LIBRARIES} + ) + endif () endif () target_link_libraries (planetblupi PUBLIC ${planetblupi_DEPS}) diff --git a/src/blupi.cxx b/src/blupi.cxx index 13cc9b4..a2dd7e2 100644 --- a/src/blupi.cxx +++ b/src/blupi.cxx @@ -30,7 +30,9 @@ #include #include -#include +#ifdef USE_CURL + #include +#endif #include "json/json.hpp" @@ -81,11 +83,13 @@ bool g_bTermInit = false; // initialisation en cours Uint32 g_lastPhase = 999; static bool g_pause; +#ifdef USE_CURL struct url_data { CURLcode status; char * buffer; size_t size; }; +#endif template static void @@ -462,6 +466,7 @@ static size_t updateCallback (void * ptr, size_t size, size_t nmemb, void * data) { size_t realsize = size * nmemb; +#ifdef USE_CURL url_data * mem = static_cast (data); mem->buffer = @@ -472,6 +477,7 @@ updateCallback (void * ptr, size_t size, size_t nmemb, void * data) mem->size += realsize; mem->buffer[mem->size] = 0; } +#endif return realsize; } @@ -479,6 +485,7 @@ updateCallback (void * ptr, size_t size, size_t nmemb, void * data) static void CheckForUpdates () { +#ifdef USE_CURL url_data chunk; chunk.buffer = nullptr; /* we expect realloc(NULL, size) to work */ @@ -515,6 +522,7 @@ CheckForUpdates () free (chunk.buffer); curl_easy_cleanup (curl); +#endif } static int From 433768147bbe86d24dfe9e3b3fbe34ffd2be2b0d Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Fri, 20 Oct 2017 17:40:31 +0200 Subject: [PATCH 2/5] Follow coding rules (space before bracket) Prefer BP over PLANETBLUPI. --- CMakeLists.txt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 06bd22e..38932c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ set (PB_PRODUCT_NAME "Planet Blupi") set (PB_PACKAGE_NAME "planetblupi") set (PB_DESCRIPTION "Planet Blupi - A delerious spell-binding game") -option(PLANETBLUPI_HTTP_VERSION_CHECK "Run a version check over HTTP (with CURL)" OFF) +option (PB_HTTP_VERSION_CHECK "Run a version check over HTTP (with CURL)" OFF) configure_file ( "${PROJECT_SOURCE_DIR}/src/config.h.in" @@ -117,10 +117,10 @@ find_package (PkgConfig REQUIRED) pkg_search_module (SDL2 REQUIRED sdl2) pkg_search_module (SDL2_MIXER REQUIRED SDL2_mixer) pkg_search_module (SDL2_IMAGE REQUIRED SDL2_image) -if(${PLANETBLUPI_HTTP_VERSION_CHECK}) +if (${PB_HTTP_VERSION_CHECK}) pkg_search_module (CURL REQUIRED libcurl) - add_definitions(-DUSE_CURL) -endif() + add_definitions (-DUSE_CURL) +endif () if ("${STATIC_BUILD}") pkg_search_module (PNG REQUIRED libpng) @@ -136,7 +136,7 @@ if ("${STATIC_BUILD}") pkg_search_module (PULSE REQUIRED libpulse) endif () - if(${PLANETBLUPI_HTTP_VERSION_CHECK}) + if (${PB_HTTP_VERSION_CHECK}) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCURL_STATICLIB") endif () endif () @@ -163,7 +163,7 @@ if ("${STATIC_BUILD}") ${SWRESAMPLE_STATIC_LIBRARIES} ) - if(${PLANETBLUPI_HTTP_VERSION_CHECK}) + if (${PB_HTTP_VERSION_CHECK}) set (planetblupi_DEPS ${planetblupi_DEPS} ${CURL_STATIC_LIBRARIES} @@ -187,7 +187,7 @@ else () pthread ) - if(${PLANETBLUPI_HTTP_VERSION_CHECK}) + if (${PB_HTTP_VERSION_CHECK}) set (planetblupi_DEPS ${planetblupi_DEPS} ${CURL_LIBRARIES} From cce3961fc8413e5d58ae068425e2ef2dad5b0319 Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Fri, 20 Oct 2017 17:41:40 +0200 Subject: [PATCH 3/5] CMake: use list(APPEND) instead of set --- CMakeLists.txt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 38932c9..de2ddee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -164,8 +164,7 @@ if ("${STATIC_BUILD}") ) if (${PB_HTTP_VERSION_CHECK}) - set (planetblupi_DEPS - ${planetblupi_DEPS} + list (APPEND planetblupi_DEPS ${CURL_STATIC_LIBRARIES} ) endif () @@ -188,8 +187,7 @@ else () ) if (${PB_HTTP_VERSION_CHECK}) - set (planetblupi_DEPS - ${planetblupi_DEPS} + list (APPEND planetblupi_DEPS ${CURL_LIBRARIES} ) endif () From a7018dbc5019be06fe10916deaeec9d700fce17d Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Fri, 20 Oct 2017 17:42:42 +0200 Subject: [PATCH 4/5] Fix warning of unused function --- src/blupi.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/blupi.cxx b/src/blupi.cxx index a2dd7e2..1bdf367 100644 --- a/src/blupi.cxx +++ b/src/blupi.cxx @@ -462,11 +462,11 @@ InitFail (const char * msg) FinishObjects (); } +#ifdef USE_CURL static size_t updateCallback (void * ptr, size_t size, size_t nmemb, void * data) { size_t realsize = size * nmemb; -#ifdef USE_CURL url_data * mem = static_cast (data); mem->buffer = @@ -477,10 +477,10 @@ updateCallback (void * ptr, size_t size, size_t nmemb, void * data) mem->size += realsize; mem->buffer[mem->size] = 0; } -#endif return realsize; } +#endif /* USE_CURL */ static void CheckForUpdates () From b523641b869e3097ce7cd19ab457d273c3b8c8b7 Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Fri, 20 Oct 2017 17:43:05 +0200 Subject: [PATCH 5/5] Cosmetics --- src/blupi.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/blupi.cxx b/src/blupi.cxx index 1bdf367..3f8c4c8 100644 --- a/src/blupi.cxx +++ b/src/blupi.cxx @@ -31,8 +31,8 @@ #include #include #ifdef USE_CURL - #include -#endif +#include +#endif /* USE_CURL */ #include "json/json.hpp" @@ -522,7 +522,7 @@ CheckForUpdates () free (chunk.buffer); curl_easy_cleanup (curl); -#endif +#endif /* USE_CURL */ } static int