Fix compilation errors when using CMake to add a project through add_subdirectory.

This commit is contained in:
ShiXiaodi 2023-10-17 15:19:49 +08:00
parent 2287b9ab0a
commit 7080918350
6 changed files with 34 additions and 23 deletions

3
.gitignore vendored
View File

@ -18,3 +18,6 @@ win32/Debug
win32/Release
win32/x64
extern/*
.vscode/
out/

View File

@ -15,7 +15,7 @@ set(ZINT_VERSION "${ZINT_VERSION_MAJOR}.${ZINT_VERSION_MINOR}.${ZINT_VERSION_REL
add_definitions(-DZINT_VERSION=\"${ZINT_VERSION}\")
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
option(ZINT_DEBUG "Set debug compile flags" OFF)
option(ZINT_NOOPT "Set no optimize compile flags" OFF)
@ -27,6 +27,8 @@ option(ZINT_STATIC "Build static library" OFF)
option(ZINT_USE_PNG "Build with PNG support" ON)
option(ZINT_USE_QT "Build with Qt support" ON)
option(ZINT_QT6 "If ZINT_USE_QT, use Qt6" OFF)
option(ZINT_UNINSTALL "Add uninstall target" ON)
option(ZINT_FRONTEND "Build frontend" ON)
if(NOT ZINT_SHARED AND NOT ZINT_STATIC)
message(SEND_ERROR "Either ZINT_SHARED or ZINT_STATIC or both must be set")
@ -143,7 +145,9 @@ if(NOT HAVE_GETOPT)
endif()
add_subdirectory(backend)
if(ZINT_FRONTEND)
add_subdirectory(frontend)
endif()
if(NOT ZINT_USE_QT)
message(STATUS "Qt support was disabled for this build")
@ -184,6 +188,7 @@ else()
endif()
endif()
if(ZINT_UNINSTALL)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
@ -191,6 +196,7 @@ configure_file(
add_custom_target(uninstall
"${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
endif()
# staniek: don't install
if(DATA_INSTALL_DIR)

View File

@ -372,6 +372,8 @@ extern "C" {
# else
# define ZINT_EXTERN extern
# endif
#elif defined(__GNUC__) && __GNUC__ >= 4
# define ZINT_EXTERN extern __attribute__((visibility("default")))
#else
# define ZINT_EXTERN extern
#endif

View File

@ -17,7 +17,7 @@ add_library(${PROJECT_NAME} STATIC ${QZint_SRCS})
set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION "${ZINT_VERSION_MAJOR}.${ZINT_VERSION_MINOR}"
VERSION ${ZINT_VERSION})
target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_SOURCE_DIR}/backend")
target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../backend")
if(ZINT_SHARED)
target_link_libraries(${PROJECT_NAME} zint)

View File

@ -12,7 +12,7 @@ if(WIN32)
target_sources(${PROJECT_NAME} PRIVATE zint.rc)
endif()
target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_SOURCE_DIR}/backend")
target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../backend")
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "zint")
@ -27,7 +27,7 @@ endif()
install(TARGETS ${PROJECT_NAME} DESTINATION "${BIN_INSTALL_DIR}" RUNTIME)
if(UNIX)
install(FILES "${CMAKE_SOURCE_DIR}/docs/zint.1" DESTINATION "${MAN_INSTALL_DIR}/man1" COMPONENT doc)
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/../docs/zint.1" DESTINATION "${MAN_INSTALL_DIR}/man1" COMPONENT doc)
endif()
if(ZINT_TEST)

View File

@ -46,7 +46,7 @@ if(WIN32)
target_sources(${PROJECT_NAME} PRIVATE res/qtZint.rc)
endif()
target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_SOURCE_DIR}/backend" "${CMAKE_SOURCE_DIR}/backend_qt")
target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../backend" "${CMAKE_CURRENT_SOURCE_DIR}/../backend_qt")
if(ZINT_SHARED)
target_link_libraries(${PROJECT_NAME} zint)