diff --git a/cmake/D2MOO.TargetsHelpers.cmake b/cmake/D2MOO.TargetsHelpers.cmake index 195ea6d0..a5754c74 100644 --- a/cmake/D2MOO.TargetsHelpers.cmake +++ b/cmake/D2MOO.TargetsHelpers.cmake @@ -28,23 +28,26 @@ function(D2MOO_configure_exports DLLTargetName) set(options FORCE_EXPORT IGNORE_MISSING_DEF) cmake_parse_arguments(PARSE_ARGV 1 this "${options}" "" "") + get_target_property(Library_TYPE ${DLLTargetName} TYPE) string(TOUPPER "${DLLTargetName}" DLLTargetNameUpperCase) - set(EXPORT_IF_SHARED_LIB "$<$,SHARED_LIBRARY>:__declspec( dllexport )>") - set(IMPORT_IF_SHARED_LIB "$<$,SHARED_LIBRARY>:__declspec( dllimport )>") - - D2MOO_get_def_file(${DLLTargetName} DEF_FILE_NAME) - - if(EXISTS "${DEF_FILE_NAME}") - set(ShouldExportIfSharedLib ${this_FORCE_EXPORT}) - target_sources(${DLLTargetName} PRIVATE "${DEF_FILE_NAME}") - else() - set(ShouldExportIfSharedLib TRUE) - if(NOT this_IGNORE_MISSING_DEF) - message(WARNING "Def file '${DEF_FILE_NAME}' not found.") - endif() + + set(ShouldExport ${this_FORCE_EXPORT}) + if(Library_TYPE STREQUAL SHARED_LIBRARY) + set(EXPORT_IF_SHARED_LIB "__declspec( dllexport )") + set(IMPORT_IF_SHARED_LIB "__declspec( dllimport )") + D2MOO_get_def_file(${DLLTargetName} DEF_FILE_NAME) + if(EXISTS "${DEF_FILE_NAME}") + target_sources(${DLLTargetName} PRIVATE "${DEF_FILE_NAME}") + else() + set(ShouldExport TRUE) + if(BUILD_SHARED_LIBS AND NOT this_IGNORE_MISSING_DEF) + message(WARNING "Def file '${DEF_FILE_NAME}' not found.") + endif() + endif() + else() endif() - if(ShouldExportIfSharedLib) + if(ShouldExport) D2MOO_set_dll_decl(${DLLTargetName} "${EXPORT_IF_SHARED_LIB}" "${IMPORT_IF_SHARED_LIB}") else() D2MOO_set_dll_decl(${DLLTargetName} "" "${IMPORT_IF_SHARED_LIB}")