Handle the case where the user changes the DEFINE_SYMBOL property.

This eases porting of KDE code.
This commit is contained in:
Stephen Kelly 2011-08-08 02:08:10 +02:00
parent 30880707c0
commit def0a54e0a
7 changed files with 44 additions and 1 deletions

View File

@ -188,6 +188,12 @@ macro(_DO_GENERATE_EXPORT_HEADER TARGET_LIBRARY)
set(INCLUDE_GUARD_NAME "${PREFIX}${EXPORT_MACRO_NAME}_H")
get_target_property(EXPORT_IMPORT_CONDITION ${TARGET_LIBRARY} DEFINE_SYMBOL)
if (NOT EXPORT_IMPORT_CONDITION)
set(EXPORT_IMPORT_CONDITION ${TARGET_LIBRARY}_EXPORTS)
endif()
configure_file(${myDir}/exportheader.cmake.in ${EXPORT_FILE_NAME} @ONLY)
endmacro()

View File

@ -7,7 +7,7 @@
# define @NO_EXPORT_MACRO_NAME@
#else
# ifndef @EXPORT_MACRO_NAME@
# ifdef @TARGET_LIBRARY@_EXPORTS
# ifdef @EXPORT_IMPORT_CONDITION@
/* We are building this library */
# define @EXPORT_MACRO_NAME@ @DEFINE_EXPORT@
# else

View File

@ -107,6 +107,8 @@ macro_add_test_library(libstatic)
add_subdirectory(lib_shared_and_static)
add_subdirectory(lib_shared_and_statictest)
add_subdirectory(override_symbol)
if (CMAKE_COMPILER_IS_GNUCXX)
# We deliberately call deprecated methods, and test for that elsewhere.
# No need to clutter the test output with warnings.

View File

@ -0,0 +1,11 @@
project(override_symbol)
add_library(somelib SHARED someclass.cpp)
set_target_properties(somelib PROPERTIES DEFINE_SYMBOL SOMELIB_MAKEDLL)
generate_export_header(somelib)
add_executable(consumer main.cpp)
target_link_libraries(consumer somelib)

View File

@ -0,0 +1,9 @@
#include "someclass.h"
int main(int, char**)
{
SomeClass sc;
sc.someMethod();
return 0;
}

View File

@ -0,0 +1,7 @@
#include "someclass.h"
void SomeClass::someMethod() const
{
}

View File

@ -0,0 +1,8 @@
#include "somelib_export.h"
class SOMELIB_EXPORT SomeClass
{
public:
void someMethod() const;
};