Skip to content

Commit

Permalink
CMake: Allow building as static lib in MSVC
Browse files Browse the repository at this point in the history
Set the LIBIIO_STATIC define when compiling a static library, which then
causes the __api to be resolved as empty.

This fixes building statically under MSVC.

Fixes #616.

Signed-off-by: Paul Cercueil <[email protected]>
  • Loading branch information
pcercuei committed Apr 7, 2021
1 parent fdb2ae9 commit 365108d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ endif()

set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries")

if (NOT BUILD_SHARED_LIBS)
add_definitions(-DLIBIIO_STATIC=1)
endif()

if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
option(OSX_PACKAGE "Create a OSX package" ON)

Expand Down
4 changes: 3 additions & 1 deletion iio.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ typedef ptrdiff_t ssize_t;
#endif

#ifdef _WIN32
# ifdef LIBIIO_EXPORTS
# ifdef LIBIIO_STATIC
# define __api
# elif defined(LIBIIO_EXPORTS)
# define __api __declspec(dllexport)
# else
# define __api __declspec(dllimport)
Expand Down

0 comments on commit 365108d

Please sign in to comment.