From cb0eb27e06d93f315f8cea8b7657b6cae58226a7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Claes=20N=C3=A4st=C3=A9n?= <pekdon@gmail.com>
Date: Wed, 2 Sep 2020 08:29:56 +0200
Subject: [PATCH] Support building with CMake

Preparing for OS X support with a build system that is available in
homebrew and helps with abstracting platform differences.
Correct link libararies are missing and missing resource compilation.

libgps not supported at all on Windows (if such a port is to be
made in the future) and unavailable in homebrew. Allow compilation
without it as florb is very usable without it.
---
 CMake/config.h.in                      |   6 ++
 CMakeLists.txt                         |  36 +++++++++
 src/CMakeLists.txt                     | 100 +++++++++++++++++++++++++
 src/OMakefile                          |  19 ++---
 src/dlg_bulkdl_ex.cpp                  |   2 +-
 src/dlg_editselection_ex.cpp           |   2 +-
 src/dlg_eleprofile_ex.cpp              |   2 +-
 src/dlg_garmindl_ex.cpp                |   2 +-
 src/dlg_garminul_ex.cpp                |   2 +-
 src/dlg_search_ex.cpp                  |   2 +-
 src/dlg_settings_ex.cpp                |  14 +++-
 src/dlg_tileserver_ex.cpp              |   2 +-
 src/dlg_txtdisp_ex.cpp                 |   2 +-
 src/dlg_ui_ex.cpp                      |   6 +-
 src/fluid/dlg_ui.fl                    |  20 ++---
 src/gpsdclient.cpp                     |   7 +-
 src/gpsdclient.hpp                     |   6 ++
 src/i18n/CMakeLists.txt                |   1 +
 src/i18n/{de_DE/florb.po => de_DE.po}  |   0
 src/i18n/de_DE/florb.mo                | Bin 10279 -> 0 bytes
 src/mkversionhpp.sh                    |  25 +++++--
 src/res/audio-input-microphone-ina.png | Bin 0 -> 1315 bytes
 src/utils.cpp                          |   2 +
 23 files changed, 217 insertions(+), 41 deletions(-)
 create mode 100644 CMake/config.h.in
 create mode 100644 CMakeLists.txt
 create mode 100644 src/CMakeLists.txt
 create mode 100644 src/i18n/CMakeLists.txt
 rename src/i18n/{de_DE/florb.po => de_DE.po} (100%)
 delete mode 100644 src/i18n/de_DE/florb.mo
 create mode 100644 src/res/audio-input-microphone-ina.png

diff --git a/CMake/config.h.in b/CMake/config.h.in
new file mode 100644
index 0000000..eb28c3f
--- /dev/null
+++ b/CMake/config.h.in
@@ -0,0 +1,6 @@
+#ifndef _CONFIG_H_
+#define _CONFIG_H_
+
+#cmakedefine HAVE_LIBGPS
+
+#endif // _CONFIG_H_
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..39afa50
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,36 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(florb)
+
+set(CMAKE_CXX_STANDARD 11)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+
+set(OpenGL_GL_PREFERENCE GLVND)
+
+include(FindPkgConfig)
+
+find_package(Boost REQUIRED COMPONENTS system filesystem thread)
+find_package(CURL REQUIRED)
+find_package(FLTK REQUIRED)
+find_package(Gettext REQUIRED)
+find_package(Intl REQUIRED)
+find_package(TinyXML2)
+if (TinyXML2_FOUND)
+  set(TinyXML2_LIBRARIES tinyxml2::tinyxml2)
+else (Tinyxml2_FOUND)
+  pkg_check_modules(TinyXML2 REQUIRED tinyxml2)
+endif (NOT TinyXML2_FOUND)
+find_package(yaml-cpp REQUIRED)
+
+# optional packages
+find_package(libgps)
+if (libgps_FOUND)
+  set(HAVE_LIBGPS 1)
+else (libgps_FOUND)
+  pkg_check_modules(libgps libgps)
+  if (libgps_FOUND)
+    set(HAVE_LIBGPS 1)
+  endif (libgps_FOUND)
+endif (libgps_FOUND)
+
+add_subdirectory(src)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 0000000..21ea513
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,100 @@
+set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
+
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLOCALEDIR=\\\"${CMAKE_INSTALL_PREFIX}/share/local\\\"")
+
+configure_file(${CMAKE_SOURCE_DIR}/CMake/config.h.in
+  ${CMAKE_CURRENT_BINARY_DIR}/config.h)
+
+add_custom_target(version ALL)
+
+add_custom_command(TARGET version
+  PRE_BUILD
+  COMMAND ${CMAKE_SOURCE_DIR}/src/mkversionhpp.sh
+  COMMENT "Generating version.hpp")
+
+set(Ui_FLUID
+  fluid/dlg_bulkdl.fl
+  fluid/dlg_editselection.fl
+  fluid/dlg_eleprofile.fl
+  fluid/dlg_garmindl.fl
+  fluid/dlg_garminul.fl
+  fluid/dlg_search.fl
+  fluid/dlg_settings.fl
+  fluid/dlg_tileserver.fl
+  fluid/dlg_txtdisp.fl
+  fluid/dlg_ui.fl)
+
+set(Ui_SOURCES
+  dlg_bulkdl_ex.cpp
+  dlg_editselection_ex.cpp
+  dlg_eleprofile_ex.cpp
+  dlg_garmindl_ex.cpp
+  dlg_garminul_ex.cpp
+  dlg_search_ex.cpp
+  dlg_settings_ex.cpp
+  dlg_tileserver_ex.cpp
+  dlg_txtdisp_ex.cpp
+  dlg_ui_ex.cpp)
+
+set(Ui_INCLUDE_DIRS
+  ${PROJECT_SOURCE_DIR}/src
+  ${Boost_INCLUDE_DIRS}
+  ${CURL_INCLUDE_DIRS}
+  ${FLTK_INCLUDE_DIRS}
+  ${Intl_INCLUDE_DIRS}
+  ${TinyXML2_INCLUDE_DIRS})
+
+fltk_wrap_ui(Ui ${Ui_FLUID})
+add_library(Ui ${Ui_SOURCES} ${Ui_FLTK_UI_SRCS})
+add_dependencies(Ui version)
+target_include_directories(Ui PUBLIC ${Ui_INCLUDE_DIRS})
+
+set(florb_SOURCES
+  areaselectlayer.cpp
+  cache.cpp
+  downloader.cpp
+  event.cpp
+  gfx.cpp
+  gpsdclient.cpp
+  gpsdlayer.cpp
+  layer.cpp
+  markerlayer.cpp
+  osmlayer.cpp
+  scalelayer.cpp
+  settings.cpp
+  shell.cpp
+  tracklayer.cpp
+  unit.cpp
+  utils.cpp
+  viewport.cpp
+  wgt_eleprofile.cpp
+  wgt_map.cpp)
+
+set(florb_INCLUDE_DIRS
+  ${Boost_INCLUDE_DIRS}
+  ${CURL_INCLUDE_DIRS}
+  ${FLTK_INCLUDE_DIRS}
+  ${Intl_INCLUDE_DIRS}
+  ${TinyXML2_INCLUDE_DIRS})
+
+add_executable(florb ${florb_SOURCES})
+add_dependencies(florb Ui version)
+
+target_include_directories(florb PUBLIC ${florb_INCLUDE_DIRS})
+
+link_directories(florb PRIVATE
+  ${Boost_LIBRARY_DIRS}
+  ${CURL_LIBRARY_DIRS})
+
+target_link_libraries(florb PRIVATE Ui)
+target_link_libraries(florb PRIVATE ${FLTK_LIBRARIES})
+target_link_libraries(florb PRIVATE ${Boost_LIBRARIES})
+target_link_libraries(florb PRIVATE ${TinyXML2_LIBRARIES})
+target_link_libraries(florb PRIVATE yaml-cpp)
+target_link_libraries(florb PRIVATE ${CURL_LIBRARIES})
+target_link_libraries(florb PRIVATE ${Intl_LIBRARIES})
+target_link_libraries(florb PRIVATE ${libgps_LIBRARIES})
+
+add_subdirectory(i18n)
+
+install(TARGETS florb DESTINATION bin)
diff --git a/src/OMakefile b/src/OMakefile
index 8eb6ede..7fa8a13 100644
--- a/src/OMakefile
+++ b/src/OMakefile
@@ -59,10 +59,7 @@ OBJS_CPP   = $(rootname $(find . -name *.cpp))
 OBJS_RES   = $(rootname $(find . -name *.res))
 OBJS       = $(set $(OBJS_FLUID) $(OBJS_CPP) $(OBJS_RES))
 
-# Find all translations
-TRANSLATIONS =
-    foreach(d => ..., $(find ./i18n/ -regex [a-z]{2\,2}_[A-Z]{2\,2}))
-		value $(d)
+TRANSLATIONS[] += de_DE
 
 # (Re-)generate version string (version.hpp) from repository information if present
 version.hpp: :exists: ../.git/HEAD :exists: ../.git/index gittags.txt :value: $(shell ./gittags.sh) version.txt ./mkversionhpp.sh
@@ -70,7 +67,7 @@ version.hpp: :exists: ../.git/HEAD :exists: ../.git/index gittags.txt :value: $(
 
 # Rule for generating CPP code from fluid sources
 %.cpp: %.fl
-    fluid -c -o $@ -h $(replacesuffixes .cpp, .hpp, $@) $<
+    fluid -c -o $@ -h $(replacesuffixes .cpp, .h, $@) $<
 
 # Rule for generating binary resources
 %.o: %.res
@@ -97,7 +94,7 @@ install:
 	#install ../LICENSE.txt $(RESOURCEDIR)
 	foreach(t => ..., $(basename $(TRANSLATIONS)))
 		mkdir -p $(LOCALEDIR)/$(t)/LC_MESSAGES/
-		install ./i18n/$(t)/florb.mo $(LOCALEDIR)/$(t)/LC_MESSAGES/
+		install ./i18n/$(t).mo $(LOCALEDIR)/$(t)/LC_MESSAGES/
 
 # clean target
 clean:
@@ -110,12 +107,12 @@ i18nupdate:
 		txt2po -P -i $(t) -o $(t).pot
 	msgcat -o i18n/all.pot $(addsuffix .res.pot, $(OBJS_RES)) i18n/$(PROGRAM).pot
 	foreach(t => ..., $(basename $(TRANSLATIONS)))
-	    if $(file-exists ./i18n/$(t)/$(PROGRAM).po)
-			msgmerge -U ./i18n/$(t)/$(PROGRAM).po i18n/all.pot
+	    if $(file-exists ./i18n/$(t).po)
+			msgmerge -U ./i18n/$(t).po i18n/all.pot
 	    else
-			msginit --no-translator -l $(t).utf8 -o ./i18n/$(t)/$(PROGRAM).po -i i18n/all.pot
-		
+			msginit --no-translator -l $(t).utf8 -o ./i18n/$(t).po -i i18n/all.pot
+
 # compile translations
 i18ncompile:
 	foreach(t => ..., $(basename $(TRANSLATIONS)))
-		msgfmt -c -o ./i18n/$(t)/florb.mo ./i18n/$(t)/$(PROGRAM).po
+		msgfmt -c -o ./i18n/$(t).mo ./i18n/$(t).po
diff --git a/src/dlg_bulkdl_ex.cpp b/src/dlg_bulkdl_ex.cpp
index e60fbf1..b02e1cc 100644
--- a/src/dlg_bulkdl_ex.cpp
+++ b/src/dlg_bulkdl_ex.cpp
@@ -4,7 +4,7 @@
 #include <algorithm>
 #include "settings.hpp"
 #include "utils.hpp"
-#include "fluid/dlg_bulkdl.hpp"
+#include "dlg_bulkdl.h"
 
 void dlg_bulkdl::create_ex()
 {
diff --git a/src/dlg_editselection_ex.cpp b/src/dlg_editselection_ex.cpp
index 8ee9902..75b2d47 100644
--- a/src/dlg_editselection_ex.cpp
+++ b/src/dlg_editselection_ex.cpp
@@ -1,7 +1,7 @@
 #include <FL/fl_ask.H>
 #include "settings.hpp"
 #include "unit.hpp"
-#include "fluid/dlg_editselection.hpp"
+#include "dlg_editselection.h"
 
 void dlg_editselection::create_ex()
 {
diff --git a/src/dlg_eleprofile_ex.cpp b/src/dlg_eleprofile_ex.cpp
index 12971e8..7c485e0 100644
--- a/src/dlg_eleprofile_ex.cpp
+++ b/src/dlg_eleprofile_ex.cpp
@@ -1,6 +1,6 @@
 #include "utils.hpp"
 #include "unit.hpp"
-#include "fluid/dlg_eleprofile.hpp"
+#include "dlg_eleprofile.h"
 
 void dlg_eleprofile::create_ex()
 {
diff --git a/src/dlg_garmindl_ex.cpp b/src/dlg_garmindl_ex.cpp
index a898bdd..8357b5d 100644
--- a/src/dlg_garmindl_ex.cpp
+++ b/src/dlg_garmindl_ex.cpp
@@ -3,7 +3,7 @@
 #include <iostream>
 #include "utils.hpp"
 #include "shell.hpp"
-#include "fluid/dlg_garmindl.hpp"
+#include "dlg_garmindl.h"
 
 void dlg_garmindl::create_ex()
 {
diff --git a/src/dlg_garminul_ex.cpp b/src/dlg_garminul_ex.cpp
index 1d05341..4bed5ac 100644
--- a/src/dlg_garminul_ex.cpp
+++ b/src/dlg_garminul_ex.cpp
@@ -3,7 +3,7 @@
 #include <iostream>
 #include "utils.hpp"
 #include "shell.hpp"
-#include "fluid/dlg_garminul.hpp"
+#include "dlg_garminul.h"
 
 void dlg_garminul::create_ex()
 {
diff --git a/src/dlg_search_ex.cpp b/src/dlg_search_ex.cpp
index 6e00773..907c86a 100644
--- a/src/dlg_search_ex.cpp
+++ b/src/dlg_search_ex.cpp
@@ -4,7 +4,7 @@
 #include <clocale>
 #include <limits>
 #include "utils.hpp"
-#include "fluid/dlg_search.hpp"
+#include "dlg_search.h"
 
 void dlg_search::create_ex()
 {
diff --git a/src/dlg_settings_ex.cpp b/src/dlg_settings_ex.cpp
index 5dca6ce..2b740be 100644
--- a/src/dlg_settings_ex.cpp
+++ b/src/dlg_settings_ex.cpp
@@ -1,3 +1,5 @@
+#include "config.h"
+
 #include <sstream>
 #include <iostream>
 #include <FL/Fl_Color_Chooser.H>
@@ -5,8 +7,8 @@
 #include "settings.hpp"
 #include "utils.hpp"
 #include "unit.hpp"
-#include "fluid/dlg_settings.hpp"
-#include "fluid/dlg_tileserver.hpp"
+#include "dlg_settings.h"
+#include "dlg_tileserver.h"
 
 void dlg_settings::create_ex()
 {
@@ -231,7 +233,13 @@ void dlg_settings::tab_gpsd_setup_ex()
     m_input_server->value(m_cfggpsd.host().c_str());
     m_input_port->value(m_cfggpsd.port().c_str());
 
-    bool en = m_cfggpsd.enabled();
+    bool en;
+#ifdef HAVE_LIBGPS
+    en = m_cfggpsd.enabled();
+#else // ! HAVE_LIBGPS
+    en = false;
+    m_chkbtn_enable->deactivate();
+#endif // HAVE_LIBGPS
 
     if (en)
     {
diff --git a/src/dlg_tileserver_ex.cpp b/src/dlg_tileserver_ex.cpp
index 003c3e5..b398193 100644
--- a/src/dlg_tileserver_ex.cpp
+++ b/src/dlg_tileserver_ex.cpp
@@ -1,6 +1,6 @@
 #include "settings.hpp"
 #include "utils.hpp"
-#include "fluid/dlg_tileserver.hpp"
+#include "dlg_tileserver.h"
 #include <FL/fl_ask.H>
 
 void dlg_tileserver::create_ex()
diff --git a/src/dlg_txtdisp_ex.cpp b/src/dlg_txtdisp_ex.cpp
index c500cbd..d3f28d9 100644
--- a/src/dlg_txtdisp_ex.cpp
+++ b/src/dlg_txtdisp_ex.cpp
@@ -3,7 +3,7 @@
 #include <iostream>
 #include <fstream>
 #include "utils.hpp"
-#include "fluid/dlg_txtdisp.hpp"
+#include "dlg_txtdisp.h"
 
 void dlg_txtdisp::create_ex()
 {
diff --git a/src/dlg_ui_ex.cpp b/src/dlg_ui_ex.cpp
index ff2967b..6461b83 100644
--- a/src/dlg_ui_ex.cpp
+++ b/src/dlg_ui_ex.cpp
@@ -10,7 +10,7 @@
 #include "gpsdclient.hpp"
 #include "utils.hpp"
 #include "unit.hpp"
-#include "fluid/dlg_ui.hpp"
+#include "dlg_ui.h"
 #include "version.hpp"
 
 extern "C" 
@@ -186,6 +186,10 @@ void dlg_ui::create_ex(void)
     m_menuitem_gpsd_gotocursor->label(_("Go to cursor"));
     m_menuitem_gpsd_recordtrack->label(_("Record track"));
     m_menuitem_gpsd_lockcursor->label(_("Lock to cursor"));
+#ifndef HAVE_LIBGPS
+    m_menuitem_gpsd->deactivate();
+    m_btn_recordtrack->deactivate();
+#endif // HAVE_LIBGPS
     // Help
     m_menuitem_help->label(_("Help"));
     m_menuitem_help_about->label(_("About"));
diff --git a/src/fluid/dlg_ui.fl b/src/fluid/dlg_ui.fl
index 80e4b20..2aedbfd 100644
--- a/src/fluid/dlg_ui.fl
+++ b/src/fluid/dlg_ui.fl
@@ -11,7 +11,7 @@ decl {\#include <signal.h>} {private global
 decl {\#include <curl/curl.h>} {private global
 } 
 
-decl {\#include "dlg_ui.hpp"} {private global
+decl {\#include "dlg_ui.h"} {private global
 } 
 
 decl {\#include "wgt_map.hpp"} {public global
@@ -20,28 +20,28 @@ decl {\#include "wgt_map.hpp"} {public global
 decl {\#include "event.hpp"} {public global
 } 
 
-decl {\#include "dlg_search.hpp"} {public global
+decl {\#include "dlg_search.h"} {public global
 } 
 
-decl {\#include "dlg_garminul.hpp"} {public global
+decl {\#include "dlg_garminul.h"} {public global
 } 
 
-decl {\#include "dlg_garmindl.hpp"} {public global
+decl {\#include "dlg_garmindl.h"} {public global
 } 
 
-decl {\#include "dlg_editselection.hpp"} {public global
+decl {\#include "dlg_editselection.h"} {public global
 } 
 
-decl {\#include "dlg_settings.hpp"} {public global
+decl {\#include "dlg_settings.h"} {public global
 } 
 
-decl {\#include "dlg_txtdisp.hpp"} {public global
+decl {\#include "dlg_txtdisp.h"} {public global
 } 
 
-decl {\#include "dlg_bulkdl.hpp"} {public global
+decl {\#include "dlg_bulkdl.h"} {public global
 } 
 
-decl {\#include "dlg_eleprofile.hpp"} {public global
+decl {\#include "dlg_eleprofile.h"} {public global
 } 
 
 decl {int main_ex(int argc, char* argv[]);} {private global
@@ -396,7 +396,7 @@ ui->cb_choice_overlay_ex(widget);} {}
           Fl_Button m_btn_recordtrack {
             user_data this
             callback cb_btn_recordtrack
-            private tooltip {Record track} image {../res/audio-input-microphone.png} xywh {229 29 25 25} type Toggle box NO_BOX down_box THIN_DOWN_BOX
+            private tooltip {Record track} image {../res/audio-input-microphone.png} deimage {../res/audio-input-microphone-ina.png} xywh {229 29 25 25} type Toggle box NO_BOX down_box THIN_DOWN_BOX
           }
           Fl_Box {} {
             private xywh {254 29 5 25} box FLAT_BOX
diff --git a/src/gpsdclient.cpp b/src/gpsdclient.cpp
index 3dd542e..f975457 100644
--- a/src/gpsdclient.cpp
+++ b/src/gpsdclient.cpp
@@ -1,3 +1,5 @@
+#include "config.h"
+
 #include "gpsdclient.hpp"
 #include "utils.hpp"
 
@@ -141,6 +143,7 @@ void florb::gpsdclient::fire_event_gpsd(void)
 
 void florb::gpsdclient::worker(void)
 {
+#ifdef HAVE_LIBGPS
     int rc;
     for (;;)
     {
@@ -200,6 +203,7 @@ void florb::gpsdclient::worker(void)
         gps_stream(&m_gpsdata, WATCH_DISABLE, NULL);
         gps_close(&m_gpsdata);
     }
+#endif // HAVE_LIBGPS
 
     // Update connection status
     connected(false);
@@ -209,6 +213,7 @@ void florb::gpsdclient::worker(void)
 bool florb::gpsdclient::handle_set()
 {
     bool ret = false;
+#ifdef HAVE_LIBGPS
 
     for (;;) {
 
@@ -255,7 +260,7 @@ bool florb::gpsdclient::handle_set()
 
         break;
     }
-
+#endif // HAVE_LIBGPS
     return ret;
 }
 
diff --git a/src/gpsdclient.hpp b/src/gpsdclient.hpp
index 1256ca4..1d2cf6a 100644
--- a/src/gpsdclient.hpp
+++ b/src/gpsdclient.hpp
@@ -1,10 +1,14 @@
 #ifndef GPSDCLIENT_HPP
 #define GPSDCLIENT_HPP
 
+#include "config.h"
+
 #include <string>
 #include <boost/thread.hpp>
 #include <boost/interprocess/sync/interprocess_mutex.hpp>
+#ifdef HAVE_LIBGPS
 #include <gps.h>
+#endif // HAVE_LIBGPS
 #include "event.hpp"
 #include "point.hpp"
 
@@ -43,7 +47,9 @@ namespace florb
 
             void fire_event_gpsd(void);
 
+#ifdef HAVE_LIBGPS
             struct gps_data_t m_gpsdata;
+#endif // HAVE_LIBGPS
             boost::interprocess::interprocess_mutex m_mutex; 
 
             std::string m_host;
diff --git a/src/i18n/CMakeLists.txt b/src/i18n/CMakeLists.txt
new file mode 100644
index 0000000..673bffe
--- /dev/null
+++ b/src/i18n/CMakeLists.txt
@@ -0,0 +1 @@
+gettext_create_translations(florb.pot ALL de_DE.po)
diff --git a/src/i18n/de_DE/florb.po b/src/i18n/de_DE.po
similarity index 100%
rename from src/i18n/de_DE/florb.po
rename to src/i18n/de_DE.po
diff --git a/src/mkversionhpp.sh b/src/mkversionhpp.sh
index 3562cd1..6a8f81c 100755
--- a/src/mkversionhpp.sh
+++ b/src/mkversionhpp.sh
@@ -1,7 +1,11 @@
 #!/bin/sh
 
 # Default version if we can't take it from git
-FLORB_V="v1.0"
+if [ -e version.txt ]; then
+    FLORB_V=`cat version.txt`
+else
+    FLORB_V="v1.0"
+fi
 
 # Check whether we have git installed, and do nothing if not
 which git > /dev/null 2>&1
@@ -21,11 +25,18 @@ if [ $? -eq 0 ]; then
 
 fi
 
-echo "#ifndef VERSION_HPP" >  version.hpp
-echo "#define VERSION_HPP" >> version.hpp
+echo "#ifndef VERSION_HPP" >  version.hpp.tmp
+echo "#define VERSION_HPP" >> version.hpp.tmp
+
+echo "#define FLORB_VERSION     \"$FLORB_V\"" >> version.hpp.tmp
+echo "#define FLORB_PROGSTR     \"florb $FLORB_V\"" >> version.hpp.tmp
+echo "#define FLORB_USERAGENT   \"florb/$FLORB_V\"" >> version.hpp.tmp
 
-echo "#define FLORB_VERSION     \"$FLORB_V\"" >> version.hpp
-echo "#define FLORB_PROGSTR     \"florb $FLORB_V\"" >> version.hpp
-echo "#define FLORB_USERAGENT   \"florb/$FLORB_V\"" >> version.hpp
+echo "#endif //VERSION_HPP" >> version.hpp.tmp
 
-echo "#endif //VERSION_HPP" >> version.hpp
+diff version.hpp.tmp version.hpp >/dev/null 2>&1
+if [ $? -eq 0 ]; then
+    rm version.hpp.tmp
+else
+    mv version.hpp.tmp version.hpp
+fi
diff --git a/src/utils.cpp b/src/utils.cpp
index aa5f9cc..3e631c4 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -1,3 +1,5 @@
+#include "config.h"
+
 #include <cmath>
 #include <limits>
 #include <stdexcept>
