From: Corentin Chary <[email protected]>
Build a shared library by default, build a static library if
BUILD_SHARED_LIBS is OFF.
Note that on windows, static libraries *must not* be built with
dllexport, and dllimport *must not* be present when you build
anything against them. That means that a project using a static
qjson on win32 will have to define QJSON_STATIC prior incluing
qjon's headers. That's far from perfect, and one could probably
tweak FindQJSON.cmake and add something like "QJSON_DEFINITIONS".
---
src/CMakeLists.txt | 12 ++++++++----
src/qjson_export.h | 13 +++++++++----
2 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 0d9c63c..b5e8de5 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -24,7 +24,7 @@ qt4_wrap_cpp(qjson_MOC_SRCS ${qjson_MOC_HDRS})
set (qjson_SRCS parser.cpp qobjecthelper.cpp json_scanner.cpp json_parser.cc
parserrunnable.cpp serializer.cpp serializerrunnable.cpp)
-add_library (qjson SHARED ${qjson_SRCS} ${qjson_MOC_SRCS})
+add_library (qjson ${qjson_SRCS} ${qjson_MOC_SRCS})
target_link_libraries( qjson ${QT_LIBRARIES})
if(NOT android)
@@ -33,9 +33,13 @@ if(NOT android)
SOVERSION ${QJSON_LIB_MAJOR_VERSION}
)
endif()
-set_target_properties(qjson PROPERTIES
- DEFINE_SYMBOL QJSON_MAKEDLL
- )
+if(BUILD_SHARED_LIBS)
+ set_target_properties(qjson PROPERTIES
+ DEFINE_SYMBOL QJSON_MAKEDLL
+ )
+else(BUILD_SHARED_LIBS)
+ add_definitions(-DQJSON_STATIC)
+endif(BUILD_SHARED_LIBS)
INSTALL(TARGETS qjson EXPORT qjson-export
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
diff --git a/src/qjson_export.h b/src/qjson_export.h
index 9a807b9..9154d23 100644
--- a/src/qjson_export.h
+++ b/src/qjson_export.h
@@ -23,13 +23,18 @@
#include <QtCore/qglobal.h>
#ifndef QJSON_EXPORT
-# if defined(QJSON_MAKEDLL)
+# ifndef QJSON_STATIC
+# if defined(QJSON_MAKEDLL)
/* We are building this library */
-# define QJSON_EXPORT Q_DECL_EXPORT
-# else
+# define QJSON_EXPORT Q_DECL_EXPORT
+# else
/* We are using this library */
-# define QJSON_EXPORT Q_DECL_IMPORT
+# define QJSON_EXPORT Q_DECL_IMPORT
+# endif
# endif
#endif
+#ifndef QJSON_EXPORT
+# define QJSON_EXPORT
+#endif
#endif
--
1.7.4.msysgit.0
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
QJson-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qjson-devel