Skip to content

Commit

Permalink
FIX: export dll for windows in cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
KangLin committed Jul 30, 2020
1 parent 30efb46 commit 4b67917
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ ENDIF()
message("BUILD_VERSION:${BUILD_VERSION}")
set(VERSION ${BUILD_VERSION})

# Open qt compile tools
SET(CMAKE_AUTOUIC ON)
SET(CMAKE_AUTOMOC ON)
SET(CMAKE_AUTORCC ON)
SET(CMAKE_INCLUDE_CURRENT_DIR ON)
SET(CMAKE_VERBOSE_MAKEFILE ON)

include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
include(GenerateExportHeader)
Expand All @@ -50,7 +57,7 @@ SET(BIGINT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/zxing/bigint)
SET(WIN32_DIR ${CMAKE_CURRENT_SOURCE_DIR}/zxing/win32/zxing)
SET(ZXING_DIR ${CMAKE_CURRENT_SOURCE_DIR}/zxing/zxing)

#SET(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libs")
SET(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libs")

set(INSTALL_HEADER_FILES
QZXing.h
Expand Down Expand Up @@ -79,13 +86,6 @@ set_target_properties(${PROJECT_NAME} PROPERTIES
target_compile_definitions(${PROJECT_NAME} PRIVATE
QZXING_LIBRARY ZXING_ICONV_CONST)

# Open qt compile tools
SET(CMAKE_AUTOUIC ON)
SET(CMAKE_AUTOMOC ON)
SET(CMAKE_AUTORCC ON)
SET(CMAKE_INCLUDE_CURRENT_DIR ON)
SET(CMAKE_VERBOSE_MAKEFILE ON)

# Need qt components
SET(QT_COMPONENTS Core Gui)

Expand All @@ -100,7 +100,7 @@ endif(QZXING_MULTIMEDIA)
option(QZXING_USE_QML "Use qml" ${QZXING_USE_QML})
if(QZXING_USE_QML)
target_sources(${PROJECT_NAME} PRIVATE QZXingImageProvider.cpp QZXingImageProvider.h)
target_compile_definitions(${PROJECT_NAME} PUBLIC QZXING_QML)
LIST(APPEND EXPORT_DEFINES QZXING_QML)
LIST(APPEND QT_COMPONENTS Quick)
SET(QZXING_ENABLE_ENCODER ON)
endif(QZXING_USE_QML)
Expand All @@ -119,8 +119,7 @@ target_link_libraries(${PROJECT_NAME} PUBLIC ${QT_LIBRARIES})

option(QZXING_ENABLE_ENCODER "Enable encoder" ${QZXING_ENABLE_ENCODER})
if(QZXING_ENABLE_ENCODER)
target_compile_definitions(${PROJECT_NAME} PUBLIC
ENABLE_ENCODER_GENERIC)
LIST(APPEND EXPORT_DEFINES ENABLE_ENCODER_GENERIC)
endif()

if(MSVC)
Expand Down Expand Up @@ -160,6 +159,9 @@ target_include_directories(${PROJECT_NAME}
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
)

# Export defines by configure_file
target_compile_definitions(${PROJECT_NAME} PUBLIC ${EXPORT_DEFINES})

if(ANDROID)
# Install target
INSTALL(TARGETS ${PROJECT_NAME}
Expand Down Expand Up @@ -212,3 +214,11 @@ write_basic_package_version_file(
COMPATIBILITY AnyNewerVersion)
install(FILES "${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")

# Install configure file
foreach(ed ${EXPORT_DEFINES})
set(PC_EXPORT_DEFINES "${PC_EXPORT_DEFINES} -D${ed}")
endforeach()
configure_file(QZXing.pc.in ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
10 changes: 10 additions & 0 deletions src/QZXing.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${prefix}/lib
includedir=${prefix}/include

Name: @PROJECT_NAME@
Description: @PROJECT_NAME@ Library
Version: @BUILD_VERSION@
Libs: -L${libdir} -l@PROJECT_NAME@
Cflags: @PC_EXPORT_DEFINES@ -I${includedir}

0 comments on commit 4b67917

Please sign in to comment.