From afb700d627f2c238c9f0deea28a064010709c4fd Mon Sep 17 00:00:00 2001 From: Sebastien Vincent Date: Tue, 8 Aug 2017 13:02:06 +0200 Subject: [PATCH 1/8] Adds possibility to compile with mongoose or not. --- SConscript | 4 ++-- SConstruct | 18 ++++++++++++++++-- apps/freelan/SConscript | 24 ++++++++++++++---------- libs/freelan/include/freelan/server.hpp | 4 ++-- libs/freelan/src/core.cpp | 7 ++++--- libs/freelan/src/server.cpp | 4 ++-- 6 files changed, 40 insertions(+), 21 deletions(-) diff --git a/SConscript b/SConscript index d2680e21..d3ea7f3c 100644 --- a/SConscript +++ b/SConscript @@ -38,8 +38,8 @@ for x in Glob('libs/*'): if not sys.platform.startswith('linux'): if name in 'netlinkplus': continue - else: - if name in 'mongooseplus': + + if env.mongoose == 'no' and name in 'mongooseplus': continue library, library_includes = SConscript(sconscript_path, exports='env dirs name') diff --git a/SConstruct b/SConstruct index 0c3cb35f..fe6a2d3e 100644 --- a/SConstruct +++ b/SConstruct @@ -22,6 +22,15 @@ AddOption( default='all', help='The compilation mode.', ) +AddOption( + '--mongoose', + dest='mongoose', + nargs=1, + action='store', + choices=('yes', 'no'), + default='no', + help='Build webserver with mongoose (warning: it will violates GPLv3 license!', +) class FreelanEnvironment(Environment): @@ -29,7 +38,7 @@ class FreelanEnvironment(Environment): A freelan specific environment class. """ - def __init__(self, mode, prefix, bin_prefix=None, **kwargs): + def __init__(self, mode, prefix, bin_prefix=None, mongoose='no', **kwargs): """ Initialize the environment. @@ -69,6 +78,7 @@ class FreelanEnvironment(Environment): self.prefix = prefix self.bin_prefix = bin_prefix if bin_prefix else prefix self.destdir = self['ENV'].get('DESTDIR', '') + self.mongoose = mongoose if self.destdir: self.install_prefix = os.path.normpath( @@ -115,6 +125,9 @@ class FreelanEnvironment(Environment): else: self.Append(CXXFLAGS='-O3') + if self.mongoose == 'yes': + self.Append(CXXFLAGS=['-DUSE_MONGOOSE']) + self.Append(CPPDEFINES=r'FREELAN_INSTALL_PREFIX="\"%s\""' % self.prefix) def RGlob(self, path, patterns=None): @@ -159,6 +172,7 @@ class FreelanEnvironment(Environment): mode = GetOption('mode') +mongoose = GetOption('mongoose') prefix = os.path.normpath(os.path.abspath(ARGUMENTS.get('prefix', './install'))) if 'bin_prefix' in ARGUMENTS: @@ -167,7 +181,7 @@ else: bin_prefix = None if mode in ('all', 'release'): - env = FreelanEnvironment(mode='release', prefix=prefix, bin_prefix=bin_prefix) + env = FreelanEnvironment(mode='release', prefix=prefix, bin_prefix=bin_prefix, mongoose=mongoose) libraries, includes, apps, samples, configurations = SConscript('SConscript', exports='env', variant_dir=os.path.join('build', env.mode)) install = env.Install(os.path.join(env.bin_install_prefix, 'bin'), apps) install.extend(env.Install(os.path.join(env.install_prefix, 'etc', 'freelan'), configurations)) diff --git a/apps/freelan/SConscript b/apps/freelan/SConscript index b27286b9..b3d23182 100644 --- a/apps/freelan/SConscript +++ b/apps/freelan/SConscript @@ -1,7 +1,6 @@ import os import sys - Import('env dirs name') libraries = [ @@ -13,7 +12,6 @@ libraries = [ 'kfather', 'iconvplus', 'boost_system', - 'boost_thread', 'boost_filesystem', 'boost_date_time', 'boost_program_options', @@ -23,23 +21,29 @@ libraries = [ 'crypto', ] +if sys.platform.startswith('darwin'): + libraries.extend([ + 'boost_thread-mt', + 'ldap', + 'z', + 'iconv', + ]) +else: + libraries.extend([ + 'boost_thread', + ]) + if sys.platform.startswith('linux'): libraries.extend([ 'pthread', 'netlinkplus', ]) -else: + +if env.mongoose == 'yes': libraries.extend([ 'mongooseplus', ]) - if sys.platform.startswith('darwin'): - libraries.extend([ - 'ldap', - 'z', - 'iconv', - ]) - env = env.Clone() env.Prepend(LIBS=libraries) diff --git a/libs/freelan/include/freelan/server.hpp b/libs/freelan/include/freelan/server.hpp index 575b56e7..db002b6a 100644 --- a/libs/freelan/include/freelan/server.hpp +++ b/libs/freelan/include/freelan/server.hpp @@ -47,7 +47,7 @@ #include "os.hpp" -#ifndef LINUX +#ifdef USE_MONGOOSE #include "configuration.hpp" @@ -113,4 +113,4 @@ namespace freelan }; } -#endif \ No newline at end of file +#endif diff --git a/libs/freelan/src/core.cpp b/libs/freelan/src/core.cpp index 40bcb8ec..0c4c8363 100644 --- a/libs/freelan/src/core.cpp +++ b/libs/freelan/src/core.cpp @@ -2358,8 +2358,9 @@ namespace freelan { if (m_configuration.server.enabled) { -#ifdef LINUX - // Due to GPL licensing issues, we can't include that in the LINUX build without violating the GPLv3 license. +#ifndef USE_MONGOOSE + // Due to GPL licensing issues, we can't include that in the build without violating the GPLv3 license. + // If you still want that support, adds USE_MONGOOSE define to the build options. m_logger(fscp::log_level::warning) << "Web server support is not compiled in this version."; #else if (m_configuration.server.protocol == server_configuration::server_protocol_type::https) @@ -2427,7 +2428,7 @@ namespace freelan void core::close_web_server() { -#ifndef LINUX +#ifdef USE_MONGOOSE if (m_web_server) { m_logger(fscp::log_level::information) << "Closing web server..."; diff --git a/libs/freelan/src/server.cpp b/libs/freelan/src/server.cpp index 101cdbb6..64385adc 100644 --- a/libs/freelan/src/server.cpp +++ b/libs/freelan/src/server.cpp @@ -45,7 +45,7 @@ #include "server.hpp" -#ifndef LINUX +#ifdef USE_MONGOOSE #include "tools.hpp" @@ -471,4 +471,4 @@ namespace freelan } } -#endif \ No newline at end of file +#endif From bff29658a8ef87deb20d3a7e1a6c928879de33ba Mon Sep 17 00:00:00 2001 From: Sebastien Vincent Date: Tue, 8 Aug 2017 13:06:59 +0200 Subject: [PATCH 2/8] Fixes typo. --- SConstruct | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SConstruct b/SConstruct index fe6a2d3e..55b0a48c 100644 --- a/SConstruct +++ b/SConstruct @@ -29,7 +29,7 @@ AddOption( action='store', choices=('yes', 'no'), default='no', - help='Build webserver with mongoose (warning: it will violates GPLv3 license!', + help='Build webserver with mongoose (warning: it will violate GPLv3 license!)', ) From 0702121ca40696b19da49f33e5c8ad4d09af6d54 Mon Sep 17 00:00:00 2001 From: Sebastien Vincent Date: Tue, 8 Aug 2017 13:16:58 +0200 Subject: [PATCH 3/8] Removes part of previous commit that adds support for macOS compilation with brew packages. --- apps/freelan/SConscript | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/apps/freelan/SConscript b/apps/freelan/SConscript index b3d23182..e1e057fd 100644 --- a/apps/freelan/SConscript +++ b/apps/freelan/SConscript @@ -12,6 +12,7 @@ libraries = [ 'kfather', 'iconvplus', 'boost_system', + 'boost_thread', 'boost_filesystem', 'boost_date_time', 'boost_program_options', @@ -21,23 +22,18 @@ libraries = [ 'crypto', ] -if sys.platform.startswith('darwin'): - libraries.extend([ - 'boost_thread-mt', - 'ldap', - 'z', - 'iconv', - ]) -else: - libraries.extend([ - 'boost_thread', - ]) - if sys.platform.startswith('linux'): libraries.extend([ 'pthread', 'netlinkplus', ]) +else: + if sys.platform.startswith('darwin'): + libraries.extend([ + 'ldap', + 'z', + 'iconv', + ]) if env.mongoose == 'yes': libraries.extend([ From 85984c26afc2a44c0a76394ea5684467011c3109 Mon Sep 17 00:00:00 2001 From: Sebastien Vincent Date: Tue, 8 Aug 2017 18:04:11 +0200 Subject: [PATCH 4/8] Modify scons scripts to be able to compile on macOS with brew packages. --- SConstruct | 4 ++++ apps/freelan/SConscript | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/SConstruct b/SConstruct index 0c3cb35f..36f78fd9 100644 --- a/SConstruct +++ b/SConstruct @@ -107,7 +107,11 @@ class FreelanEnvironment(Environment): self.Append(CXXFLAGS=['-arch', 'x86_64']) self.Append(CXXFLAGS=['-DBOOST_ASIO_DISABLE_KQUEUE']) self.Append(CXXFLAGS=['--stdlib=libc++']) + self.Append(CXXFLAGS=['-I/usr/local/opt/openssl/include']) + self.Append(CFLAGS=['-I/usr/local/opt/openssl/include']) self.Append(LDFLAGS=['--stdlib=libc++']) + self.Append(LDFLAGS=['-L/usr/local/opt/openssl/lib']) + self.Append(LIBPATH=['/usr/local/opt/openssl/lib']) if self.mode == 'debug': self.Append(CXXFLAGS=['-g']) diff --git a/apps/freelan/SConscript b/apps/freelan/SConscript index b27286b9..4b7ad1b4 100644 --- a/apps/freelan/SConscript +++ b/apps/freelan/SConscript @@ -13,7 +13,6 @@ libraries = [ 'kfather', 'iconvplus', 'boost_system', - 'boost_thread', 'boost_filesystem', 'boost_date_time', 'boost_program_options', @@ -23,6 +22,15 @@ libraries = [ 'crypto', ] +if sys.platform.startswith('darwin'): + libraries.extend([ + 'boost_thread-mt', + ]) +else: + libraries.extend([ + 'boost_thread', + ]) + if sys.platform.startswith('linux'): libraries.extend([ 'pthread', From 54be93d69fb3c9206c568bed556c7b7ddfa227a2 Mon Sep 17 00:00:00 2001 From: Sebastien Vincent Date: Tue, 8 Aug 2017 18:04:20 +0200 Subject: [PATCH 5/8] Adds documentation to install brew packages on MacOS X. --- BUILD.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/BUILD.md b/BUILD.md index 313c8e18..6b3a423d 100644 --- a/BUILD.md +++ b/BUILD.md @@ -11,7 +11,7 @@ FreeLAN depends on the following libraries: - OpenSSL - iconv (Windows) -Generally Linux users can just use the binaries provided by their package manager, but other platforms such as Mac OSX or Windows may need to build these libraries explicitely. +Generally Linux users can just use the binaries provided by their package manager, Mac OSX users can use brew but other platforms such as Windows may need to build these libraries explicitely. To build the third-party libraries, you can use [teapot](https://github.com/freelan-developers/teapot). Check its [documentation](http://teapot-builder.readthedocs.org/en/latest/) for details, or just type the following command at the root of FreeLAN's repository: @@ -25,6 +25,16 @@ To install the required dependencies on Debian Linux (Or Ubuntu), type the follo > sudo apt-get install scons python libssl-dev libcurl4-openssl-dev libboost-system-dev libboost-thread-dev libboost-program-options-dev libboost-filesystem-dev libboost-iostreams-dev build-essential +### Mac OSX + +To install the required dependencies on Mac OS, type the following commands: + +> /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + +> brew update + +> brew install scons boost openssl + Building FreeLAN ---------------- From 7bdbd1044d2c2fbab6f7883bcc329ac25b72db62 Mon Sep 17 00:00:00 2001 From: Sebastien Vincent Date: Tue, 8 Aug 2017 18:08:15 +0200 Subject: [PATCH 6/8] Adds macOS build in Travis CI script (tentative). --- .travis.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9a40a3d7..69accb36 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,12 @@ language: cpp compiler: - g++ -dist: trusty -sudo: false +matrix: + include: + - os: linux + dist: trusty + sudo: false + - os: osx addons: apt: sources: @@ -14,6 +18,9 @@ addons: - libcurl4-openssl-dev - gcc - g++ +before_install: + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install scons boost openssl; fi cache: apt: true script: scons install apps samples From 7de9b70d5e621b56e6ca8d0d67a0fe67d6c40b7d Mon Sep 17 00:00:00 2001 From: Sebastien Vincent Date: Wed, 9 Aug 2017 15:19:35 +0200 Subject: [PATCH 7/8] Fixes Travis CI build file for macOS. The 'brew install' command will fail if package is already installed. So check if package is present first before installing it. --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 69accb36..e15daf58 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,9 @@ addons: - g++ before_install: - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install scons boost openssl; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew list scons &>/dev/null || brew install scons ; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew list boost &>/dev/null || brew install boost ; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew list openssl &>/dev/null || brew install openssl ; fi cache: apt: true script: scons install apps samples From 8e86b5ac90d4bb252a5d1b504f88edb45b1ab358 Mon Sep 17 00:00:00 2001 From: Sebastien Vincent Date: Wed, 9 Aug 2017 15:48:35 +0200 Subject: [PATCH 8/8] Fixes compilation of FSCP samples on macOS (link with boost_thread-mt instead of boost_thread. --- samples/fscp/client/SConscript | 10 +++++++++- samples/fscp/schat/SConscript | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/samples/fscp/client/SConscript b/samples/fscp/client/SConscript index d3133279..b77fd312 100644 --- a/samples/fscp/client/SConscript +++ b/samples/fscp/client/SConscript @@ -5,11 +5,19 @@ import sys libraries = [ 'fscp', 'cryptoplus', - 'boost_thread', 'boost_system', 'crypto', ] +if sys.platform.startswith('darwin'): + libraries.extend([ + 'boost_thread-mt', + ]) +else: + libraries.extend([ + 'boost_thread', + ]) + if sys.platform.startswith('linux'): libraries.extend([ 'pthread', diff --git a/samples/fscp/schat/SConscript b/samples/fscp/schat/SConscript index d3133279..b77fd312 100644 --- a/samples/fscp/schat/SConscript +++ b/samples/fscp/schat/SConscript @@ -5,11 +5,19 @@ import sys libraries = [ 'fscp', 'cryptoplus', - 'boost_thread', 'boost_system', 'crypto', ] +if sys.platform.startswith('darwin'): + libraries.extend([ + 'boost_thread-mt', + ]) +else: + libraries.extend([ + 'boost_thread', + ]) + if sys.platform.startswith('linux'): libraries.extend([ 'pthread',