From acd12e1754c6f7da74752c227d04260cc615de00 Mon Sep 17 00:00:00 2001 From: Schaich Date: Mon, 22 Mar 2021 20:20:44 +0900 Subject: [PATCH] Add and use helper to set all flags to both the shared and the static library --- backend/CMakeLists.txt | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/backend/CMakeLists.txt b/backend/CMakeLists.txt index d295447f..7db775aa 100644 --- a/backend/CMakeLists.txt +++ b/backend/CMakeLists.txt @@ -20,28 +20,42 @@ if(ZINT_STATIC) add_library(zint-static STATIC ${zint_SRCS}) endif() +function(zint_target_link_libraries library) + target_link_libraries(zint ${library}) + if(ZINT_STATIC) + target_link_libraries(zint-static ${library}) + endif() +endfunction() + +function(zint_target_compile_definitions scope definition) + target_compile_definitions(zint ${scope} ${definition}) + if(ZINT_STATIC) + target_compile_definitions(zint-static ${scope} ${definition}) + endif() +endfunction() + set_target_properties(zint PROPERTIES SOVERSION "${ZINT_VERSION_MAJOR}.${ZINT_VERSION_MINOR}" VERSION ${ZINT_VERSION}) if(PNG_FOUND) - target_link_libraries(zint PNG::PNG) + zint_target_link_libraries(PNG::PNG) else() - target_compile_definitions(zint PUBLIC NO_PNG) + zint_target_compile_definitions(PUBLIC NO_PNG) endif() if(ZINT_TEST) - target_compile_definitions(zint PUBLIC ZINT_TEST) + zint_target_compile_definitions(PUBLIC ZINT_TEST) endif() if(NOT MSVC) # Link with standard C math library. - target_link_libraries(zint m) + zint_target_link_libraries(m) endif() if(MSVC) # "BUILD_SHARED_LIBS" is a CMake defined variable, see documentation. if(BUILD_SHARED_LIBS) - target_compile_definitions(zint PRIVATE DLL_EXPORT) + zint_target_compile_definitions(zint PRIVATE DLL_EXPORT) endif() endif()