Skip to content

Commit

Permalink
Add support for building static library (#394)
Browse files Browse the repository at this point in the history
* Change BUILDING_DLL to BUILDING_SDFORMAT
* Add SDFORMAT_STATIC_DEFINE in cmake
* Drop __GNUC__ conditional

Signed-off-by: Juan Oxoby <juan@vicarious.com>

Co-authored-by: Juan Oxoby <juan@vicarious.com>
Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com>
Co-authored-by: Louise Poubel <louise@openrobotics.org>
Co-authored-by: Michael Carroll <michael@openrobotics.org>
Co-authored-by: Steve Peters <scpeters@openrobotics.org>
  • Loading branch information
6 people authored Nov 23, 2020
1 parent 1014a21 commit a42103e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ else()
endif()
endif()

#============================================================================
# Ask whether we should make a shared or static library.
option(BUILD_SHARED_LIBS "Set this to true to generate shared libraries (recommended), or false for static libraries" ON)

#####################################
# Handle CFlags
unset (CMAKE_C_FLAGS_ALL CACHE)
Expand Down
7 changes: 5 additions & 2 deletions cmake/SDFUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ endmacro (BUILD_WARNING)
#################################################
macro (sdf_add_library _name)
set(LIBS_DESTINATION ${PROJECT_BINARY_DIR}/src)
set_source_files_properties(${ARGN} PROPERTIES COMPILE_DEFINITIONS "BUILDING_DLL")
add_library(${_name} SHARED ${ARGN})
add_library(${_name} ${ARGN})
set_target_properties(${_name} PROPERTIES DEFINE_SYMBOL "BUILDING_SDFORMAT_SHARED")
if(NOT BUILD_SHARED_LIBS)
target_compile_definitions(${_name} PUBLIC SDFORMAT_STATIC_DEFINE)
endif()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBS_DESTINATION})
if (MSVC)
set_target_properties( ${_name} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${LIBS_DESTINATION})
Expand Down
17 changes: 5 additions & 12 deletions include/sdf/system_util.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,13 @@
*/

#if defined _WIN32 || defined __CYGWIN__
#ifdef BUILDING_DLL
#ifdef __GNUC__
#define SDFORMAT_VISIBLE __attribute__ ((dllexport))
#else
#define SDFORMAT_VISIBLE __declspec(dllexport)
#endif
#ifdef BUILDING_SDFORMAT_SHARED
#define SDFORMAT_VISIBLE __declspec(dllexport)
#elif !defined SDFORMAT_STATIC_DEFINE
#define SDFORMAT_VISIBLE __declspec(dllimport)
#else
#ifdef __GNUC__
#define SDFORMAT_VISIBLE __attribute__ ((dllimport))
#else
#define SDFORMAT_VISIBLE __declspec(dllimport)
#endif
#define SDFORMAT_VISIBLE
#endif
#define SDFORMAT_HIDDEN
#else
#if __GNUC__ >= 4 && !defined SDFORMAT_STATIC_DEFINE
#define SDFORMAT_VISIBLE __attribute__ ((visibility ("default")))
Expand Down

0 comments on commit a42103e

Please sign in to comment.