Ticket #55583: patch-build-shared+static.diff

File patch-build-shared+static.diff, 2.6 KB (added by RJVB (René Bertin), 7 years ago)
  • CMakeLists.txt

    diff --git CMakeLists.txt CMakeLists.txt
    index 3f534b134eb8421b6cb34f6416b0a854144f92f5..68a24f05f08613c0af851e5f98f6a46e85378d61 100644
    project(Snappy VERSION 1.1.7 LANGUAGES C CXX) 
    33
    44# BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to make
    55# it prominent in the GUI.
    6 option(BUILD_SHARED_LIBS "Build shared libraries(DLLs)." OFF)
     6# option(BUILD_SHARED_LIBS "Build shared libraries(DLLs)." OFF)
    77
    88option(SNAPPY_BUILD_TESTS "Build Snappy's own tests." ON)
    99
    configure_file( 
    7272  "${PROJECT_SOURCE_DIR}/snappy-stubs-public.h.in"
    7373  "${PROJECT_BINARY_DIR}/snappy-stubs-public.h")
    7474
    75 add_library(snappy "")
     75add_library(snappy SHARED "")
    7676target_sources(snappy
    7777  PRIVATE
    7878    "${PROJECT_SOURCE_DIR}/snappy-internal.h"
    if(BUILD_SHARED_LIBS) 
    108108  set_target_properties(snappy PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
    109109endif(BUILD_SHARED_LIBS)
    110110
     111add_library(staticlib STATIC "")
     112target_sources(staticlib
     113  PRIVATE
     114    "${PROJECT_SOURCE_DIR}/snappy-internal.h"
     115    "${PROJECT_SOURCE_DIR}/snappy-stubs-internal.h"
     116    "${PROJECT_SOURCE_DIR}/snappy-c.cc"
     117    "${PROJECT_SOURCE_DIR}/snappy-sinksource.cc"
     118    "${PROJECT_SOURCE_DIR}/snappy-stubs-internal.cc"
     119    "${PROJECT_SOURCE_DIR}/snappy.cc"
     120    "${PROJECT_BINARY_DIR}/config.h"
     121
     122  # Only CMake 3.3+ supports PUBLIC sources in targets exported by "install".
     123  $<$<VERSION_GREATER:CMAKE_VERSION,3.2>:PUBLIC>
     124    $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/snappy-c.h>
     125    $<INSTALL_INTERFACE:include/snappy-c.h>
     126    $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/snappy-sinksource.h>
     127    $<INSTALL_INTERFACE:include/snappy-sinksource.h>
     128    $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/snappy.h>
     129    $<INSTALL_INTERFACE:include/snappy.h>
     130    $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/snappy-stubs-public.h>
     131    $<INSTALL_INTERFACE:include/snappy-stubs-public.h>
     132)
     133target_include_directories(staticlib
     134  PUBLIC
     135    $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
     136    $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
     137    $<INSTALL_INTERFACE:include>
     138)
     139set_target_properties(staticlib
     140    PROPERTIES  VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}
     141                OUTPUT_NAME snappy
     142)
     143
     144target_compile_definitions(staticlib PRIVATE -DHAVE_CONFIG_H)
     145
    111146if(SNAPPY_BUILD_TESTS)
    112147  enable_testing()
    113148
    if(SNAPPY_BUILD_TESTS) 
    141176endif(SNAPPY_BUILD_TESTS)
    142177
    143178include(GNUInstallDirs)
    144 install(TARGETS snappy
     179install(TARGETS snappy staticlib
    145180  EXPORT SnappyTargets
    146181  RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    147182  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}