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

Add support for building static library #394

Merged
merged 9 commits into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
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})
mjcarroll marked this conversation as resolved.
Show resolved Hide resolved
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