Skip to content

Commit

Permalink
Mac OS X support
Browse files Browse the repository at this point in the history
  • Loading branch information
loentar committed Aug 24, 2016
1 parent b545b2c commit 7a6b476
Show file tree
Hide file tree
Showing 27 changed files with 96 additions and 36 deletions.
12 changes: 7 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ if (HAS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
endif()

check_cxx_compiler_flag(-Wl,--no-undefined HAS_NO_UNDEFINED)
if (HAS_NO_UNDEFINED)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-undefined")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
if (NOT APPLE)
check_cxx_compiler_flag(-Wl,--no-undefined HAS_NO_UNDEFINED)
if (HAS_NO_UNDEFINED)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-undefined")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
endif()
endif()

check_cxx_compiler_flag(-pedantic HAS_PEDANTIC)
Expand Down
2 changes: 2 additions & 0 deletions core/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 2.6)
project (ngrestcommon CXX)

set (CMAKE_MACOSX_RPATH 1)

set (PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)

FILE(GLOB NGRESTCOMMON_SOURCES ${PROJECT_SOURCE_DIR}/*.cpp)
Expand Down
2 changes: 2 additions & 0 deletions core/engine/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 2.6)
project (ngrestengine CXX)

set (CMAKE_MACOSX_RPATH 1)

set (PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)

FILE(GLOB NGRESTENGINE_SOURCES ${PROJECT_SOURCE_DIR}/*.cpp)
Expand Down
2 changes: 2 additions & 0 deletions core/json/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 2.6)
project (ngrestjson CXX)

set (CMAKE_MACOSX_RPATH 1)

set (PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)

FILE(GLOB NGRESTJSON_SOURCES ${PROJECT_SOURCE_DIR}/*.cpp)
Expand Down
2 changes: 2 additions & 0 deletions core/server/src/ClientHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

#include <unistd.h>
#ifndef WIN32
#ifndef __APPLE__
#include <error.h>
#endif
#include <sys/socket.h>
#include <netdb.h>
#else
Expand Down
16 changes: 10 additions & 6 deletions core/server/src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,12 @@ int Server::exec()
int processedFds = 0;
// Service all the sockets with input pending.
for (int i = 0; (i < FD_SETSIZE) && (processedFds < readyFds); ++i) {
#ifndef WIN32
Socket fd = readFds[i];
#else
#ifdef WIN32
Socket fd = readFds.fd_array[i];
#elif defined __APPLE__
Socket fd = i;
#else
Socket fd = readFds[i];
#endif
if (FD_ISSET(fd, &readFds)) {
if (fd == fdServer) {
Expand All @@ -250,10 +252,12 @@ int Server::exec()
if (processedFds == readyFds)
break;

#ifndef WIN32
fd = writeFds[i];
#else
#ifdef WIN32
fd = writeFds.fd_array[i];
#elif defined __APPLE__
fd = i;
#else
fd = writeFds[i];
#endif
if (FD_ISSET(fd, &writeFds)) {
callback->readyWrite(fd);
Expand Down
2 changes: 1 addition & 1 deletion core/server/src/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ class Server
private:
bool isStopping = false;
Socket fdServer = 0;
int fdEpoll = 0;
#ifdef HAS_EPOLL
int fdEpoll = 0;
epoll_event* event = nullptr;
epoll_event* events = nullptr;
#else
Expand Down
2 changes: 1 addition & 1 deletion core/server/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "Server.h"
#include "ClientHandler.h"

#ifdef WIN32
#if defined WIN32 || defined __APPLE__
typedef void(__cdecl *sighandler_t)(int);
#endif

Expand Down
2 changes: 2 additions & 0 deletions core/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 2.6)
project (ngrestutils CXX)

set (CMAKE_MACOSX_RPATH 1)

set (PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)

FILE(GLOB NGRESTUTILS_SOURCES ${PROJECT_SOURCE_DIR}/*.cpp)
Expand Down
2 changes: 2 additions & 0 deletions core/xml/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 2.6)
project (ngrestxml CXX)

set (CMAKE_MACOSX_RPATH 1)

set (PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)

FILE(GLOB NGRESTXML_SOURCES ${PROJECT_SOURCE_DIR}/*.cpp)
Expand Down
2 changes: 1 addition & 1 deletion core/xml/src/Value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ std::string& Value::asString()

bool Value::operator==(const Value& value) const
{
return value == value.value;
return this->value == value.value;
}


Expand Down
2 changes: 1 addition & 1 deletion modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if (APXS_PATH)
endif()

if ("$ENV{NGINX_PATH}" STREQUAL "")
message(Skipping Nginx module compilation: no Nginx source path provided)
message("Skipping Nginx module compilation: no Nginx source path provided")
else()
set(NGINX_SRC_PATH "$ENV{NGINX_PATH}")
add_subdirectory(nginx)
Expand Down
7 changes: 7 additions & 0 deletions modules/apache2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
project (ngrest_apache2_mod CXX)

set (CMAKE_MACOSX_RPATH 1)

execute_process(COMMAND ${APXS_PATH} -q CFLAGS EXTRA_INCLUDES
OUTPUT_VARIABLE APXS_CFLAGS
)
Expand All @@ -11,6 +13,11 @@ STRING(REGEX REPLACE "\n" "" APXS_CFLAGS ${APXS_CFLAGS})
STRING(REGEX REPLACE ";;" " " APXS_CFLAGS ${APXS_CFLAGS})
STRING(REGEX REPLACE "\n" "" APXS_LDFLAGS ${APXS_LDFLAGS})

if (APPLE)
set(APXS_CFLAGS "${APXS_CFLAGS} -I/usr/include/apr-1")
set(CMAKE_SHARED_LINKER_FLAGS "-undefined dynamic_lookup ${CMAKE_SHARED_LINKER_FLAGS}")
endif ()

set(CMAKE_C_FLAGS "${APXS_CFLAGS} ${CMAKE_C_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${APXS_LDFLAGS} ${CMAKE_SHARED_LINKER_FLAGS}")

Expand Down
1 change: 0 additions & 1 deletion modules/apache2/src/mod_ngrest.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/

#include <unistd.h>
#include <apr_strings.h>
#include <ap_config.h>
#include <httpd.h>
#include <http_config.h>
Expand Down
3 changes: 1 addition & 2 deletions modules/nginx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
project (ngrest_nginx_mod CXX)

#set(CMAKE_C_FLAGS "${APXS_CFLAGS} ${CMAKE_C_FLAGS}")
#set(CMAKE_SHARED_LINKER_FLAGS "${APXS_LDFLAGS} ${CMAKE_SHARED_LINKER_FLAGS}")
set (CMAKE_MACOSX_RPATH 1)

# remove -Wl,--no-undefined to allow ngx_* symbols be imported from nginx binary
STRING(REGEX REPLACE "-Wl,--no-undefined" "" CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS})
Expand Down
13 changes: 9 additions & 4 deletions scripts/inst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

set -eu

Expand All @@ -14,6 +14,9 @@ case $(uname -s) in
Linux)
OS=Linux
;;
Darwin)
OS=Darwin
;;
*)
echo "This OS is not yet supported" >&2
exit 1
Expand All @@ -40,7 +43,7 @@ then
pkg=

# detect package manager
for p in apt-get yum
for p in apt-get yum port
do
if $p -v >/dev/null 2>&1
then
Expand All @@ -55,10 +58,12 @@ then
exit 1
fi

[ $pkg == port ] && YES= || YES=-y

echo "This script will install missing dependencies for you: $TO_INSTALL$TO_INSTALL_OPT..."
echo "To continue please enter your password, or press Ctrl+C to install it manually."
sudo $pkg install -y $TO_INSTALL </dev/null
sudo $pkg install -y $TO_INSTALL_OPT </dev/null || true
sudo $pkg install $YES $TO_INSTALL </dev/null
[ $OS == Darwin ] || sudo $pkg install $YES $TO_INSTALL_OPT </dev/null || true
fi
fi

Expand Down
8 changes: 6 additions & 2 deletions scripts/ngrest
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

set -eu

Expand All @@ -11,6 +11,10 @@ case $(uname -s) in
Linux)
OS=Linux
;;
Darwin)
OS=Darwin
export DISABLE_WATCHER=1
;;
*)
echo "This OS is not yet supported" >&2
exit 1
Expand Down Expand Up @@ -64,7 +68,7 @@ else
fi


if [ $OS = MINGW ]
if [ $OS = MINGW -o $OS = Darwin ]
then
mktemp() {
n=/tmp/$(date +%Y%m%d%H%M%S)
Expand Down
3 changes: 3 additions & 0 deletions services/favicon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ list(APPEND FAVICON_SOURCES ${FAVICON_CODEGEN_SOURCES})
include_directories(${PROJECT_SOURCE_DIR})

add_library(favicon MODULE ${FAVICON_SOURCES})
if (APPLE) # cmake sets .so extension for modules under mac os x
set_target_properties(favicon PROPERTIES SUFFIX ".dylib")
endif()

set_target_properties(favicon PROPERTIES PREFIX "")
set_target_properties(favicon PROPERTIES
Expand Down
3 changes: 3 additions & 0 deletions services/serverstatus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ list(APPEND SERVERSTATUS_SOURCES ${SERVERSTATUS_CODEGEN_SOURCES})
include_directories(${PROJECT_SOURCE_DIR})

add_library(serverstatus MODULE ${SERVERSTATUS_SOURCES})
if (APPLE) # cmake sets .so extension for modules under mac os x
set_target_properties(serverstatus PROPERTIES SUFFIX ".dylib")
endif()

set_target_properties(serverstatus PROPERTIES PREFIX "")
set_target_properties(serverstatus PROPERTIES
Expand Down
4 changes: 2 additions & 2 deletions tests/deployment/src/TestServiceGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ namespace ngrest {
TestServiceGroup::TestServiceGroup():
name("test")
{
services = {{
services = {
new ::ngrest::TestDeploymentWrapper()
}};
};
}

TestServiceGroup::~TestServiceGroup()
Expand Down
15 changes: 10 additions & 5 deletions tools/ngrestcg/templates/project/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ if (HAS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
endif()

check_cxx_compiler_flag(-Wl,--no-undefined HAS_NO_UNDEFINED)
if (HAS_NO_UNDEFINED)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-undefined")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
if (NOT APPLE)
check_cxx_compiler_flag(-Wl,--no-undefined HAS_NO_UNDEFINED)
if (HAS_NO_UNDEFINED)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-undefined")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
endif()
endif()

check_cxx_compiler_flag(-pedantic HAS_PEDANTIC)
Expand Down Expand Up @@ -74,5 +76,8 @@ set(NGREST_BIN_PATH "${NGREST_HOME}/bin/")
##var serviceNs $($servicesTmp.!lasttoken/ /||$servicesTmp)
##var service $($serviceNs.!lasttoken/./||$serviceNs)
add_subdirectory($($service.!tolower))
if (APPLE) # cmake sets .so extension for modules under mac os x
set_target_properties($($service.!tolower) PROPERTIES SUFFIX ".dylib")
endif()
##var servicesTmp $($servicesTmp.!cutlast/ /)
##done
4 changes: 2 additions & 2 deletions tools/ngrestcg/templates/service/ServiceGroupImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ NGREST_DECLARE_PLUGIN($(project.ns)ServiceGroupImpl)
ServiceGroupImpl::ServiceGroupImpl():
name("$(project.ns.!dot)")
{
services = {{
services = {
##var isComma 0
##foreach $(project.interfaces)
##foreach $(interface.services)
Expand All @@ -28,7 +28,7 @@ ServiceGroupImpl::ServiceGroupImpl():
##endfor
##endfor

}};
};
}

ServiceGroupImpl::~ServiceGroupImpl()
Expand Down
2 changes: 2 additions & 0 deletions tools/ngrestcgparser/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 2.6)
project (ngrestcgparser CXX)

set (CMAKE_MACOSX_RPATH 1)

set (PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)

FILE(GLOB NGRESTCGPARSER_SOURCES ${PROJECT_SOURCE_DIR}/*.cpp)
Expand Down
2 changes: 1 addition & 1 deletion tools/ngrestcgparser/src/Interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ struct NGREST_CODEGENPARSER_EXPORT Struct: public BaseType
std::string parentNs; //!< parent struct namespace (actual)
std::list<Field> fields; //!< struct fields
std::list<Struct> structs; //!< sub struct list
std::list<class Enum> enums; //!< sub enum list
std::list<struct Enum> enums; //!< sub enum list

Struct();
Struct& operator=(const Struct& other);
Expand Down
9 changes: 8 additions & 1 deletion tools/ngrestcgparser/src/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,18 @@ bool fixId(std::string& id, bool ignoreBool /*= false*/)
}

const std::string& stringMapValue(const StringMap& map, const std::string& name,
const std::string& defaultValue /*= ""*/)
const std::string& defaultValue)
{
StringMap::const_iterator itValue = map.find(name);
return (itValue != map.end()) ? itValue->second : defaultValue;
}

const std::string& stringMapValue(const StringMap& map, const std::string& name)
{
const static std::string defaultValue;
StringMap::const_iterator itValue = map.find(name);
return (itValue != map.end()) ? itValue->second : defaultValue;
}

}
}
8 changes: 7 additions & 1 deletion tools/ngrestcgparser/src/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@ bool fixId(std::string& name, bool bIgnoreBool = false);
*/
NGREST_CODEGENPARSER_EXPORT
const std::string& stringMapValue(const StringMap& map, const std::string& name,
const std::string& defaultValue = "");
const std::string& defaultValue);

/**
* @brief get value from map if it exists, or default value else
*/
NGREST_CODEGENPARSER_EXPORT
const std::string& stringMapValue(const StringMap& map, const std::string& name);



Expand Down
2 changes: 2 additions & 0 deletions tools/parsers/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 2.6)
project (ngrestcgparser-cpp CXX)

set (CMAKE_MACOSX_RPATH 1)

set (PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)

FILE(GLOB NGRESTCGPARSER_CPP_SOURCES ${PROJECT_SOURCE_DIR}/*.cpp)
Expand Down

0 comments on commit 7a6b476

Please sign in to comment.