Skip to content

Commit

Permalink
Add support for shared libraries on Windows (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielius1922 authored Feb 23, 2022
1 parent 8b7c181 commit 3f760f2
Show file tree
Hide file tree
Showing 9 changed files with 447 additions and 136 deletions.
72 changes: 34 additions & 38 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ if(OC_CLOUD_ENABLED)
set(CLOUD_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/api/cloud)
endif()

if(UNIX)
file(GLOB PYTHON_SRC python/*.c)
endif()
file(GLOB PYTHON_SRC python/*.c)

######## Define link dependencies ########
set(PRIVATE_LINK_LIBS "")
Expand Down Expand Up @@ -220,13 +218,13 @@ if(OC_CLOUD_ENABLED)
endif()
endif()

if(UNIX)
add_library(python-obj OBJECT ${PYTHON_SRC})
target_compile_definitions(python-obj PRIVATE ${PRIVATE_COMPILE_DEFINITIONS} PUBLIC ${PUBLIC_COMPILE_DEFINITIONS} "OC_CLIENT")
target_include_directories(python-obj PRIVATE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/port ${PORT_INCLUDE_DIR})
if(OC_SECURITY_ENABLED)
target_include_directories(python-obj PRIVATE ${MBEDTLS_INCLUDE_DIRS})
endif()
add_library(python-obj OBJECT ${PYTHON_SRC})
target_compile_definitions(python-obj PRIVATE ${PRIVATE_COMPILE_DEFINITIONS} OC_LIBRARY_EXPORT PUBLIC ${PUBLIC_COMPILE_DEFINITIONS} "OC_LIBRARY" "OC_CLIENT")
set_property(TARGET python-obj PROPERTY C_VISIBILITY_PRESET hidden)
set_property(TARGET python-obj PROPERTY VISIBILITY_INLINES_HIDDEN ON)
target_include_directories(python-obj PRIVATE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/port ${PORT_INCLUDE_DIR})
if(OC_SECURITY_ENABLED)
target_include_directories(python-obj PRIVATE ${MBEDTLS_INCLUDE_DIRS})
endif()

######## Compose static and shared libraries ########
Expand Down Expand Up @@ -406,35 +404,33 @@ if(NOT MSVC)
endif()

# Python client
if(UNIX)
set(client-python-lib-obj
$<TARGET_OBJECTS:common-obj>
$<TARGET_OBJECTS:tinycbor-master>
$<TARGET_OBJECTS:client-obj>
$<TARGET_OBJECTS:python-obj>
)
if(OC_SECURITY_ENABLED)
list(APPEND client-python-lib-obj $<TARGET_OBJECTS:mbedtls>)
endif()
add_library(client-python-shared SHARED ${client-python-lib-obj})
target_link_libraries(client-python-shared PRIVATE ${PRIVATE_LINK_LIBS})
target_compile_definitions(client-python-shared PUBLIC
$<BUILD_INTERFACE:${PUBLIC_COMPILE_DEFINITIONS};OC_CLIENT>
$<INSTALL_INTERFACE:${PUBLIC_COMPILE_DEFINITIONS};OC_CLIENT>
)
target_include_directories(client-python-shared PUBLIC
$<BUILD_INTERFACE:.;include;port;${PORT_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include/iotivity-lite>
)
if(OC_SECURITY_ENABLED)
target_include_directories(client-python-shared PUBLIC "$<BUILD_INTERFACE:${MBEDTLS_INCLUDE_DIRS}>")
endif()
set_target_properties(client-python-shared PROPERTIES
OUTPUT_NAME "iotivity-lite-client-python"
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
)
set(client-python-lib-obj
$<TARGET_OBJECTS:common-obj>
$<TARGET_OBJECTS:tinycbor-master>
$<TARGET_OBJECTS:client-obj>
$<TARGET_OBJECTS:python-obj>
)
if(OC_SECURITY_ENABLED)
list(APPEND client-python-lib-obj $<TARGET_OBJECTS:mbedtls>)
endif()
add_library(client-python-shared SHARED ${client-python-lib-obj})
target_link_libraries(client-python-shared PRIVATE ${PRIVATE_LINK_LIBS})
target_compile_definitions(client-python-shared PUBLIC
$<BUILD_INTERFACE:${PUBLIC_COMPILE_DEFINITIONS};OC_CLIENT>
$<INSTALL_INTERFACE:${PUBLIC_COMPILE_DEFINITIONS};OC_CLIENT>
)
target_include_directories(client-python-shared PUBLIC
$<BUILD_INTERFACE:.;include;port;${PORT_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include/iotivity-lite>
)
if(OC_SECURITY_ENABLED)
target_include_directories(client-python-shared PUBLIC "$<BUILD_INTERFACE:${MBEDTLS_INCLUDE_DIRS}>")
endif()
set_target_properties(client-python-shared PROPERTIES
OUTPUT_NAME "iotivity-lite-client-python"
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
)

######## Units tests (UNIX only) ########
include(CTest)
Expand Down
6 changes: 3 additions & 3 deletions apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,19 @@ if(UNIX)
)
target_link_libraries(cloud_server client-server-static)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/cloud_server_creds)

add_executable(cloud_client
${PROJECT_SOURCE_DIR}/cloud_client.c
)
target_link_libraries(cloud_client client-server-static)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/cloud_client_creds)

add_executable(cloud_proxy
${PROJECT_SOURCE_DIR}/cloud_proxy.c
)
target_link_libraries(cloud_proxy client-server-static)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/cloud_proxy_creds)

add_executable(cloud_tests
${PROJECT_SOURCE_DIR}/cloud_certification_tests.c
)
Expand Down
42 changes: 42 additions & 0 deletions include/oc_export.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
// Copyright (c) 2022 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
*/

#ifndef OC_EXPORT_H
#define OC_EXPORT_H

#ifdef _WIN32
#define OC_EXPORT __declspec(dllexport)
#define OC_IMPORT __declspec(dllimport)
#elif (defined __GNUC__ && __GNUC__ >= 4)
#define OC_EXPORT __attribute__((visibility("default")))
#define OC_IMPORT
#else /* !__GNUC__ || __GNUC__ < 4 */
#warning "Shared libraries not supported"
#define OC_EXPORT
#define OC_IMPORT
#endif /* _WIN32 */

#ifdef OC_LIBRARY
#ifdef OC_LIBRARY_EXPORT
#define OC_API OC_EXPORT
#else /* !OC_LIBRARY_EXPORT*/
#define OC_API OC_IMPORT
#endif /* OC_LIBRARY_EXPORT */
#else /* !OC_LIBRARY */
#define OC_API
#endif /* OC_LIBRARY */

#endif /* OC_EXPORT_H */
4 changes: 4 additions & 0 deletions include/oc_uuid.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#ifndef OC_UUID_H
#define OC_UUID_H

#include "oc_export.h"
#include <stdint.h>

#ifdef __cplusplus
Expand Down Expand Up @@ -59,6 +60,7 @@ typedef struct
* @param[in] str the UUID string
* @param[out] uuid the oc_uuid_t to hold the UUID bits.
*/
OC_API
void oc_str_to_uuid(const char *str, oc_uuid_t *uuid);

/**
Expand All @@ -84,6 +86,7 @@ void oc_str_to_uuid(const char *str, oc_uuid_t *uuid);
* @param [in] buflen The size of the input buffer.
* Recommend always using OC_UUID_LEN for buflen.
*/
OC_API
void oc_uuid_to_str(const oc_uuid_t *uuid, char *buffer, int buflen);
/**
* Generate a random Universally Unique IDentifier (UUID)
Expand All @@ -100,6 +103,7 @@ void oc_uuid_to_str(const oc_uuid_t *uuid, char *buffer, int buflen);
*
* @param[out] uuid the randomly generated UUID
*/
OC_API
void oc_gen_uuid(oc_uuid_t *uuid);

#ifdef __cplusplus
Expand Down
5 changes: 5 additions & 0 deletions port/oc_random.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#ifndef OC_RANDOM_H
#define OC_RANDOM_H

#include "oc_export.h"

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -45,19 +47,22 @@ extern "C" {
* @brief Initialize the pseudo-random generator.
*
*/
OC_API
void oc_random_init(void);

/**
*@brief Calculate a pseudo random number.
*
* @return A pseudo-random number.
*/
OC_API
unsigned int oc_random_value(void);

/**
* @brief destroy the pseudo-random generator
*
*/
OC_API
void oc_random_destroy(void);

#ifdef __cplusplus
Expand Down
Loading

0 comments on commit 3f760f2

Please sign in to comment.