Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Host Build on MacOS #87

Merged
merged 5 commits into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ if(${ESP_PLATFORM})
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(${selected_test_project})
else()
message(STATUS "Compiling for Linux")
message(STATUS "Compiling for Host Platform")
if(${APPLE})
include_directories(SYSTEM /usr/local/include)
link_directories(/usr/local/lib)
endif()
add_subdirectory(mock-idf)
add_subdirectory(lib)
add_subdirectory(test/${selected_test_project})
Expand Down
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,24 @@ Please see the the different test projects under the test folder. When compiling
root of the repo as a CMake project. Select the project you wish to build by setting `selected_test_project`
in the top `CMakeLists.txt`. **You will likely have to re-generate your build files after changing the selection.**

## Using Smooth in your project (compiling for Linux)
## Using Smooth in your project (compiling for Linux or MacOS)

To build you application for Linux you must maintain a parallel build configuration as follows:
### System Libraries
Some libraries provided in the ESP distribution need to be installed as system libraries on the host. On Debian / Ubuntu:

```shell
apt-get install libsodium-dev libmbedtls-dev
```

With Homebrew on MacOS:

```shell
brew install libsodium mbedtls
```


### CMake Config
To build your application on the host platform you must maintain a parallel build configuration as follows:

Top `CMakeList.txt`

Expand All @@ -160,6 +175,12 @@ if(${ESP_PLATFORM})
externals/smooth/smooth_component)
project(your_project_name)
else()
if(${APPLE})
include_directories(SYSTEM /usr/local/include)
link_directories(/usr/local/lib)
endif()


add_subdirectory(main)
add_subdirectory(externals/smooth/lib)
add_subdirectory(externals/smooth/mock-idf)
Expand Down Expand Up @@ -188,6 +209,18 @@ else()
endif()
```

### Building on MacOS
Currently only GCC is supported. You can install GCC via homebrew and then pass flags to CMake to use that compiler:

```shell
brew install gcc
mkdir cmake-macos
cd cmake-macos
cmake -DCMAKE_C_COMPILER=gcc-9 -DCMAKE_CXX_COMPILER=g++-9 ..
make
```


Here's an example of how your `main.cpp` could look like if you want to compile for both ESP and Linux. The example
assumes you have named your main class `App` and it is derived from `smooth::core::Application`, which most
applications based on Smooth do. Doing so is not mandatory, it saves you some setup; see
Expand Down
4 changes: 2 additions & 2 deletions lib/smooth/core/network/SocketDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,12 @@ namespace smooth::core::network
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"

void SocketDispatcher::set_fd(std::size_t socket_id, fd_set& fd)
void SocketDispatcher::set_fd(FD socket_id, fd_set& fd)
{
FD_SET(socket_id, &fd);
}

bool SocketDispatcher::is_fd_set(std::size_t socket_id, fd_set& fd)
bool SocketDispatcher::is_fd_set(FD socket_id, fd_set& fd)
{
return FD_ISSET(socket_id, &fd);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/smooth/include/smooth/core/network/ISocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace smooth::core::network
friend class smooth::core::network::SocketDispatcher;
public:
static const int INVALID_SOCKET = -1;
#ifdef ESP_PLATFORM
#if defined(ESP_PLATFORM) || defined(__APPLE__)

// lwip doesn't signal SIGPIPE
static const int SEND_FLAGS = 0;
Expand Down
9 changes: 7 additions & 2 deletions lib/smooth/include/smooth/core/network/SocketDispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ namespace smooth::core::network
private ISocketBackOff
{
public:
#ifdef ESP_PLATFORM
typedef size_t FD;
#else
typedef int FD;
#endif
~SocketDispatcher() override = default;

static SocketDispatcher& instance();
Expand Down Expand Up @@ -90,9 +95,9 @@ namespace smooth::core::network
using SocketOperationQueue = smooth::core::ipc::TaskEventQueue<SocketOperation>;
std::shared_ptr<SocketOperationQueue> socket_op;

static void set_fd(std::size_t socket_id, fd_set& fd);
static void set_fd(FD socket_id, fd_set& fd);

static bool is_fd_set(std::size_t socket_id, fd_set& fd);
static bool is_fd_set(FD socket_id, fd_set& fd);

void print_status() const;

Expand Down
2 changes: 1 addition & 1 deletion lib/smooth/include/smooth/core/network/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.

#pragma once

#ifdef ESP_PLATFORM
#if defined(ESP_PLATFORM) || defined(__APPLE__)
#include <machine/endian.h>
#if _BYTE_ORDER == _LITTLE_ENDIAN
#define SMOOTH_LITTLE_ENDIAN
Expand Down