Skip to content

Commit

Permalink
Merge pull request #131 from tamasmeszaros/cmake-dynlib
Browse files Browse the repository at this point in the history
Modified cmake script to support shared library mode and find_package.
  • Loading branch information
uroni authored May 27, 2019
2 parents ea41268 + 1261dfa commit ff06fba
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 4 deletions.
65 changes: 61 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
PROJECT(miniz C)
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.4)

set(Upstream_VERSION 2.1.0)

if(CMAKE_BUILD_TYPE STREQUAL "")
# CMake defaults to leaving CMAKE_BUILD_TYPE empty. This screws up
# differentiation between debug and release builds.
Expand All @@ -11,6 +14,7 @@ endif ()
option(BUILD_EXAMPLES "Build examples" ON)
option(AMALGAMATE_SOURCES "Amalgamate sources into miniz.h/c" OFF)
option(BUILD_HEADER_ONLY "Build a header-only version" OFF)
option(BUILD_SHARED_LIBS "Build shared library instead of static" ON)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)

Expand Down Expand Up @@ -65,13 +69,65 @@ if(AMALGAMATE_SOURCES)
endif(BUILD_HEADER_ONLY)
set(INSTALL_HEADERS ${CMAKE_BINARY_DIR}/amalgamation/miniz.h)
else(AMALGAMATE_SOURCES)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
set(miniz_SOURCE miniz.c miniz_zip.c miniz_tinfl.c miniz_tdef.c)
add_library(${PROJECT_NAME} ${miniz_SOURCE})
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>

set_property(TARGET ${PROJECT_NAME} PROPERTY VERSION ${Upstream_VERSION})
set_property(TARGET ${PROJECT_NAME} PROPERTY SOVERSION 2)
set_property(TARGET ${PROJECT_NAME} PROPERTY
INTERFACE_${PROJECT_NAME}_MAJOR_VERSION 2)
set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY
COMPATIBLE_INTERFACE_STRING ${PROJECT_NAME}_MAJOR_VERSION
)

# target_include_directories(${PROJECT_NAME} PUBLIC
# $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
# $<INSTALL_INTERFACE:include>
# )
file(GLOB INSTALL_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.h)

install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Targets
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
INCLUDES DESTINATION include
)

include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${Upstream_VERSION}
COMPATIBILITY AnyNewerVersion
)

export(EXPORT ${PROJECT_NAME}Targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}Targets.cmake"
NAMESPACE ${PROJECT_NAME}::
)
configure_file(Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}Config.cmake"
@ONLY
)

set(ConfigPackageLocation lib/cmake/${PROJECT_NAME})
install(EXPORT ${PROJECT_NAME}Targets
FILE
${PROJECT_NAME}Targets.cmake
NAMESPACE
${PROJECT_NAME}::
DESTINATION
${ConfigPackageLocation}
)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION
${ConfigPackageLocation}
COMPONENT
Devel
)
endif(AMALGAMATE_SOURCES)

if(BUILD_EXAMPLES)
Expand Down Expand Up @@ -108,3 +164,4 @@ endif(BUILD_EXAMPLES)
set(INCLUDE_INSTALL_DIR "include")

install(FILES ${INSTALL_HEADERS} DESTINATION ${INCLUDE_INSTALL_DIR}/${PROJECT_NAME})

1 change: 1 addition & 0 deletions Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")

0 comments on commit ff06fba

Please sign in to comment.