Skip to content

Commit

Permalink
Build gateway SDK for macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
damonbarry committed Mar 26, 2017
1 parent 51ace91 commit a5f111d
Show file tree
Hide file tree
Showing 24 changed files with 144 additions and 71 deletions.
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ endif()
if(LINUX)
set (CMAKE_C_FLAGS "-fPIC ${CMAKE_C_FLAGS}")
set (CMAKE_CXX_FLAGS "-fPIC ${CMAKE_CXX_FLAGS}")
elseif(APPLE)
# Warnings as errors
set (CMAKE_C_FLAGS "-Werror ${CMAKE_C_FLAGS}")
set (CMAKE_CXX_FLAGS "-Werror ${CMAKE_CXX_FLAGS}")
endif()

function(add_module_to_solution undecoratedModuleName)
Expand Down Expand Up @@ -197,9 +201,7 @@ endfunction(linkSharedUtil)
include_directories(./deps/parson)

function(link_broker whatIsBuilding)

target_link_libraries(${whatIsBuilding} nanomsg ${NN_REQUIRED_LIBRARIES})

target_link_libraries(${whatIsBuilding} nanomsg ${NN_REQUIRED_LIBRARIES})
endfunction(link_broker)

function(install_broker whatIsBuilding whatIsBuildingLocation)
Expand All @@ -225,8 +227,6 @@ function(copy_gateway_dll whatIsBuilding whatIsBuildingLocation)
"${azure_c_shared_utility_DIR}/../bin/${SHARED_UTIL_LIB}.dll"
${whatIsBuildingLocation})
endif()


endif()
endfunction(copy_gateway_dll)

Expand Down
11 changes: 11 additions & 0 deletions bindings/java/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ elseif(LINUX)
set(java_libs
$ENV{JAVA_HOME}/jre/lib/${JDK_ARCH}/server/libjvm.so
)
elseif(APPLE)
set(java_include_dirs
$ENV{JAVA_HOME}/include
$ENV{JAVA_HOME}/include/darwin
)
set(java_link_dirs
$ENV{JAVA_HOME}/jre/lib/server
)
set(java_libs
$ENV{JAVA_HOME}/jre/lib/server/libjvm.dylib
)
endif()

set(LIBS ${java_libs} gateway)
Expand Down
4 changes: 2 additions & 2 deletions bindings/java/src/java_module_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ static void JavaModuleHost_Receive(MODULE_HANDLE module, MESSAGE_HANDLE message)
else
{
/*Codes_SRS_JAVA_MODULE_HOST_14_044: [This function shall set the contents of the jbyteArray to the serialized_message.]*/
JNIFunc(moduleHandle->env, SetByteArrayRegion, arr, 0, size, serialized_message);
JNIFunc(moduleHandle->env, SetByteArrayRegion, arr, 0, size, (jbyte*)serialized_message);
jthrowable exception = JNIFunc(moduleHandle->env, ExceptionOccurred);
if (exception)
{
Expand Down Expand Up @@ -564,7 +564,7 @@ JNIEXPORT jint JNICALL Java_com_microsoft_azure_gateway_core_Broker_publishMessa
else
{
/*Codes_SRS_JAVA_MODULE_HOST_14_025: [This function shall convert the jbyteArray message into an unsigned char array.]*/
JNIFunc(env, GetByteArrayRegion, serialized_message, 0, (jsize)length, arr);
JNIFunc(env, GetByteArrayRegion, serialized_message, 0, (jsize)length, (jbyte*)arr);
jthrowable exception = JNIFunc(env, ExceptionOccurred);
if (exception)
{
Expand Down
2 changes: 1 addition & 1 deletion bindings/java/tests/host_ut/host_ut.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ MOCK_FUNCTION_END(num)

MOCK_FUNCTION_WITH_CODE(, const char*, json_array_get_string, const JSON_Array*, arr, size_t, index)
const char* str = NULL;
if (arr != NULL && index >= 0)
if (arr != NULL)
{
str = "hello_world";
}
Expand Down
27 changes: 20 additions & 7 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ cmake_minimum_required(VERSION 2.8.12)
if(POLICY CMP0054)
cmake_policy(SET CMP0054 OLD)
endif()
cmake_policy(SET CMP0022 NEW)
if(POLICY CMP0022)
cmake_policy(SET CMP0022 NEW)
endif()
if(POLICY CMP0042)
cmake_policy(SET CMP0042 NEW)
endif()

add_subdirectory(deps)

Expand All @@ -16,19 +21,19 @@ set(GW_SRC ${CMAKE_CURRENT_LIST_DIR}/src CACHE INTERNAL "Needs to be included fo
#setting the dynamic_loader file based on OS that it is used
if(WIN32)
include_directories(${GW_INC}/windows )
elseif(LINUX)
elseif(UNIX) # LINUX or APPLE
include_directories(${GW_INC}/linux)
endif()

#setting the dynamic_loader file based on OS that it is used
if(WIN32)
set(dynamic_library_c_file ./adapters/dynamic_library_windows.c ./adapters/gb_library_windows.c)
elseif(LINUX)
elseif(UNIX) # LINUX or APPLE
set(dynamic_library_c_file ./adapters/dynamic_library_linux.c ./adapters/gb_library_linux.c )
endif()

#setting specific libraries to be loaded based on OS (for example, Linux needs "-ldl", windows does not)
if(LINUX)
if(UNIX) # LINUX or APPLE
set(dynamic_loader_library dl)
endif()

Expand Down Expand Up @@ -228,9 +233,17 @@ if(NOT ${use_xplat_uuid})
else()
find_package(PkgConfig REQUIRED)
pkg_search_module(UUID REQUIRED uuid)
target_link_libraries(gateway ${UUID_LIBRARIES})
target_link_libraries(gateway_static ${UUID_LIBRARIES})
target_link_libraries(module_host_static ${UUID_LIBRARIES})
link_directories(${UUID_LIBRARY_DIRS})

if(APPLE)
target_link_libraries(gateway -L${UUID_LIBRARY_DIRS} ${UUID_LIBRARIES})
target_link_libraries(gateway_static -L${UUID_LIBRARY_DIRS} ${UUID_LIBRARIES})
target_link_libraries(module_host_static -L${UUID_LIBRARY_DIRS} ${UUID_LIBRARIES})
elseif(LINUX)
target_link_libraries(gateway ${UUID_LIBRARIES})
target_link_libraries(gateway_static ${UUID_LIBRARIES})
target_link_libraries(module_host_static ${UUID_LIBRARIES})
endif()
endif()
endif()

Expand Down
16 changes: 8 additions & 8 deletions core/src/control_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ DEFINE_ENUM_STRINGS(CONTROL_MESSAGE_TYPE, CONTROL_MESSAGE_TYPE_VALUES);
#define BASE_CREATE_SIZE (BASE_MESSAGE_SIZE+10)
#define BASE_CREATE_REPLY_SIZE (BASE_MESSAGE_SIZE+1)

static int parse_int32_t(const unsigned char* source, size_t sourceSize, size_t position, int32_t *parsed, int32_t* value)
static int parse_uint32_t(const unsigned char* source, size_t sourceSize, size_t position, int32_t *parsed, uint32_t* value)
{
int result;
if (position + 4 > sourceSize)
Expand All @@ -41,12 +41,12 @@ static int parse_int32_t(const unsigned char* source, size_t sourceSize, size_t
return result;
}

static int parse_memory_chunk(const unsigned char* source, size_t sourceSize, size_t position, int32_t *parsed, int32_t *size, unsigned char** value)
static int parse_memory_chunk(const unsigned char* source, size_t sourceSize, size_t position, int32_t *parsed, uint32_t *size, char** value)
{
int result;
int32_t chunk_size;
uint32_t chunk_size;
int32_t current_parsed;
result = parse_int32_t(source, sourceSize, position, &current_parsed, &chunk_size);
result = parse_uint32_t(source, sourceSize, position, &current_parsed, &chunk_size);
if (result == 0)
{
position += current_parsed;
Expand All @@ -68,7 +68,7 @@ static int parse_memory_chunk(const unsigned char* source, size_t sourceSize, si
else
{
/* allocate 1 more for null-termination */
*value = (unsigned char *)malloc(chunk_size);
*value = (char *)malloc(chunk_size);
if (*value == NULL)
{
LogError("unable to allocate memory chunk");
Expand Down Expand Up @@ -163,7 +163,7 @@ int parse_create_message(const unsigned char* source, size_t sourceSize, size_t
position,
&current_parsed,
&(create_msg->args_size),
(unsigned char**)&(create_msg->args)) != 0)
&(create_msg->args)) != 0)
{
LogError("unable to parse a module args");
result = __LINE__;
Expand Down Expand Up @@ -211,9 +211,9 @@ CONTROL_MESSAGE * ControlMessage_CreateFromByteArray(const unsigned char* source
/*Codes_SRS_CONTROL_MESSAGE_17_005: [ This function shall read the version, type and size from the byte stream. ]*/
uint8_t messageVersion = (uint8_t)source[currentPosition++];
uint8_t messageType = (uint8_t)source[currentPosition++];
int32_t messageSize;
uint32_t messageSize;
/* we already know buffer is at least BASE_MESSAGE_SIZE - this will always return OK */
(void)parse_int32_t(source, size, currentPosition, &parsed, &messageSize);
(void)parse_uint32_t(source, size, currentPosition, &parsed, &messageSize);
currentPosition += parsed;
/*Codes_SRS_CONTROL_MESSAGE_17_006: [ If the size embedded in the message is not the same as size parameter then this function shall fail and return NULL. ]*/
if (messageSize != size)
Expand Down
2 changes: 1 addition & 1 deletion core/tests/dynamic_library_ut/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if(WIN32)
${testSuiteName}_windows.cpp)
set(${testSuiteName}_c_files
../../adapters/dynamic_library_windows.c)
elseif(LINUX)
elseif(UNIX) # LINUX or APPLE
set(${testSuiteName}_cpp_files
${testSuiteName}_linux.cpp)
set(${testSuiteName}_c_files
Expand Down
2 changes: 1 addition & 1 deletion core/tests/dynamic_loader_ut/dynamic_loader_ut.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ MOCK_FUNCTION_END(arr)

MOCK_FUNCTION_WITH_CODE(, JSON_Value*, json_array_get_value, const JSON_Array*, arr, size_t, index)
JSON_Value* val = NULL;
if (arr != NULL && index >= 0)
if (arr != NULL && index != 0)
{
val = (JSON_Value*)0x42;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ TYPED_MOCK_CLASS(CGatewayMocks, CGlobalMock)

MOCK_STATIC_METHOD_2(, JSON_Object*, json_array_get_object, const JSON_Array*, arr, size_t, index)
JSON_Object* object = NULL;
if (arr != NULL && index >= 0)
if (arr != NULL)
{
object = (JSON_Object*)0x42;
}
Expand Down
2 changes: 1 addition & 1 deletion core/tests/gateway_e2e/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ${theseTestsName}.cpp
#setting the dynamic_loader file based on OS that it is used
if(WIN32)
set(modules_c_file ./module_config_windows.c)
elseif(LINUX)
elseif(UNIX) # LINUX OR APPLE
set(modules_c_file ./module_config_linux.c)
endif()

Expand Down
4 changes: 2 additions & 2 deletions core/tests/gateway_ut/gateway_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ TYPED_MOCK_CLASS(CGatewayLLMocks, CGlobalMock)
MOCK_STATIC_METHOD_0(, BROKER_HANDLE, Broker_Create)
BROKER_HANDLE result1;
currentBroker_Create_call++;
if (whenShallBroker_Create_fail >= 0 && whenShallBroker_Create_fail == currentBroker_Create_call)
if (whenShallBroker_Create_fail == currentBroker_Create_call)
{
result1 = NULL;
}
Expand Down Expand Up @@ -173,7 +173,7 @@ TYPED_MOCK_CLASS(CGatewayLLMocks, CGlobalMock)
MOCK_STATIC_METHOD_2(, MODULE_LIBRARY_HANDLE, DynamicModuleLoader_Load, const struct MODULE_LOADER_TAG*, loader, const void*, entrypoint)
currentModuleLoader_Load_call++;
MODULE_LIBRARY_HANDLE handle = NULL;
if (whenShallModuleLoader_Load_fail >= 0 && whenShallModuleLoader_Load_fail != currentModuleLoader_Load_call)
if (whenShallModuleLoader_Load_fail != currentModuleLoader_Load_call)
{
handle = (MODULE_LIBRARY_HANDLE)BASEIMPLEMENTATION::gballoc_malloc(1);
}
Expand Down
2 changes: 1 addition & 1 deletion core/tests/gwmessage_ut/gwmessage_ut.c
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ BEGIN_TEST_SUITE(gwmessage_ut)
///cleanup
}

/*Tests_SRS_MESSAGE_02_020: [Otherwise, Message_Destroy shall decrement the internal ref count of the message.]
/*Tests_SRS_MESSAGE_02_020: [Otherwise, Message_Destroy shall decrement the internal ref count of the message.]*/
/*Tests_SRS_MESSAGE_02_021: [If the ref count is zero then the allocated resources are freed.]*/
/*Tests_SRS_MESSAGE_17_002: [Message_Destroy shall destroy the CONSTMAP properties.]*/
/*Tests_SRS_MESSAGE_17_005: [Message_Destroy shall destroy the CONSTBUFFER.]*/
Expand Down
4 changes: 2 additions & 2 deletions core/tests/java_loader_ut/java_loader_ut.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ MOCK_FUNCTION_END(arr)

MOCK_FUNCTION_WITH_CODE(, JSON_Value*, json_array_get_value, const JSON_Array*, arr, size_t, index)
JSON_Value* val = NULL;
if (arr != NULL && index >= 0)
if (arr != NULL)
{
val = (JSON_Value*)0x42;
}
Expand Down Expand Up @@ -197,7 +197,7 @@ MOCK_FUNCTION_END(num)

MOCK_FUNCTION_WITH_CODE(, const char*, json_array_get_string, const JSON_Array*, arr, size_t, index)
const char* str = NULL;
if (arr != NULL && index >= 0)
if (arr != NULL)
{
str = "hello_world";
}
Expand Down
2 changes: 1 addition & 1 deletion core/tests/module_loader_ut/module_loader_ut.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ MOCK_FUNCTION_END(arr)

MOCK_FUNCTION_WITH_CODE(, JSON_Value*, json_array_get_value, const JSON_Array*, arr, size_t, index)
JSON_Value* val = NULL;
if (arr != NULL && index >= 0)
if (arr != NULL && index != 0)
{
val = (JSON_Value*)0x42;
}
Expand Down
24 changes: 16 additions & 8 deletions dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@ include("gatewayFunctions.cmake")
###############################################################################
###################Find/Install/Build azure_c_shared_utility###################
###############################################################################
set(PASSVARS)
if(DEFINED OPENSSL_ROOT_DIR)
set(PASSVARS ${PASSVARS} -DOPENSSL_ROOT_DIR:PATH=${OPENSSL_ROOT_DIR})
endif()

findAndInstall(azure_c_shared_utility 1.0.25
${PROJECT_SOURCE_DIR}/deps/c-utility
${PROJECT_SOURCE_DIR}/deps/c-utility
-Duse_installed_dependencies=ON
-Drun_unittests=${run_unittests}
-Dbuild_as_dynamic=ON
-Duse_default_uuid=${use_xplat_uuid}
${PASSVARS}
-G "${CMAKE_GENERATOR}")
set(SHARED_UTIL_INC_FOLDER ${AZURE_C_SHARED_UTILITY_INCLUDE_DIR} CACHE INTERNAL "this is what needs to be included if using sharedLib lib" FORCE)
set(SHARED_UTIL_LIB_FOLDER ${AZURE_C_SHARED_LIBRARY_DIR} CACHE INTERNAL "this is what needs to be included if using sharedLib lib" FORCE)
Expand Down Expand Up @@ -48,32 +54,36 @@ if(WIN32)
set(NANOMSG_INCLUDES "${CMAKE_INSTALL_PREFIX}/../nanomsg/include" CACHE INTERNAL "")
endif()
else()
include(FindPkgConfig)
find_package(PkgConfig REQUIRED)

#If using a custom install prefix, tell find pkg to use it instead of defaults
set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH TRUE)

pkg_search_module(NANOMSG QUIET nanomsg)
if(NOT NANOMSG_FOUND)
findAndInstallNonFindPkg(nanomsg ${PROJECT_SOURCE_DIR}/deps/nanomsg ${PROJECT_SOURCE_DIR}/deps/nanomsg -G "${CMAKE_GENERATOR}")
findAndInstallNonFindPkg(nanomsg
${PROJECT_SOURCE_DIR}/deps/nanomsg
${PROJECT_SOURCE_DIR}/deps/nanomsg
-G "${CMAKE_GENERATOR}"
-DNN_TESTS=OFF
-DNN_TOOLS=OFF)
endif()

#If earlier cmake
if("${CMAKE_VERSION}" VERSION_GREATER 3.0.2)
pkg_search_module(NANOMSG REQUIRED nanomsg)
set (NANOMSG_LIB_LOCATION "${NANOMSG_LIBDIR}/lib${NANOMSG_LIBRARIES}.so")
set (NANOMSG_LIB_LOCATION
"${NANOMSG_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}${NANOMSG_LIBRARIES}${CMAKE_SHARED_LIBRARY_SUFFIX}")
else()
if(DEFINED ${dependency_install_prefix})
set(NANOMSG_INCLUDEDIR "${dependency_install_prefix}/include")
set(NANOMSG_LIBRARIES nanomsg)
set(NANOMSG_LIBRARY_DIRS "${dependency_install_prefix}/${CMAKE_INSTALL_LIBDIR}")
set(NANOMSG_LDFLAGS "-L${NANOMSG_LIBRARY_DIRS};-l${NANOMSG_LIBRARIES}")
else()
pkg_search_module(NANOMSG REQUIRED nanomsg)
set(NANOMSG_LIBRARY_DIRS "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
endif()
set (NANOMSG_LIB_LOCATION "${NANOMSG_LIBRARY_DIRS}/lib${NANOMSG_LIBRARIES}.so")
set (NANOMSG_LIB_LOCATION
"${NANOMSG_LIBRARY_DIRS}/${CMAKE_SHARED_LIBRARY_PREFIX}${NANOMSG_LIBRARIES}${CMAKE_SHARED_LIBRARY_SUFFIX}")

endif()

Expand All @@ -88,11 +98,9 @@ else()
set_target_properties(nanomsg PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${NANOMSG_INCLUDEDIR}"
INTERFACE_LINK_LIBRARIES "${NANOMSG_LIBRARIES}"
INTERFACE_COMPILE_OPTIONS "${NANOMSG_LDFLAGS}"
IMPORTED_LOCATION "${NANOMSG_LIB_LOCATION}"
)
message(STATUS "NANOMSG LIBRARIES: ${NANOMSG_LIBRARIES}")
message(STATUS "NANOMSG LDFLAGS: ${NANOMSG_LDFLAGS}")
message(STATUS "NANOMSG CFLAGS: ${NANOMSG_CFLAGS}")
message(STATUS "NANOMSG LOCATION: ${NANOMSG_LIB_LOCATION}")
endif()
Expand Down
5 changes: 3 additions & 2 deletions gatewayFunctions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ function(findAndInstallNonFindPkg libraryName submoduleRootDirectory cmakeRootDi
endif()

#Create the build directory to run cmake, and run cmake
#generate comand

#generate command
set(CMD cmake)
foreach(arg ${ARGN})
set(CMD ${CMD} ${arg})
Expand Down Expand Up @@ -139,7 +140,7 @@ function(findAndInstall libraryName version submoduleRootDirectory cmakeRootDire
set(CMD ${CMD} -DCMAKE_INSTALL_PREFIX=${dependency_install_prefix})
endif()
if(CMAKE_TOOLCHAIN_FILE)
set( CMD ${CMD} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE})
set(CMD ${CMD} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE})
endif()
set(CMD ${CMD} ../)

Expand Down
Loading

0 comments on commit a5f111d

Please sign in to comment.