Create cmake target
This commit is contained in:
Родитель
3f44bbc98e
Коммит
87f2d8793c
105
CMakeLists.txt
105
CMakeLists.txt
|
@ -1,29 +1,92 @@
|
|||
cmake_minimum_required(VERSION 2.8.9)
|
||||
project(winhttppal DESCRIPTION "WinHttpPAL")
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
project(libwinhttppal VERSION 1.0.0 LANGUAGES CXX)
|
||||
|
||||
# dependencies
|
||||
set(CURL_LIBRARY "-lcurl")
|
||||
find_package(CURL REQUIRED)
|
||||
include_directories(${CURL_INCLUDE_DIR})
|
||||
#Make sure that custom modules like FindRapidJSON are found
|
||||
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_SOURCE_DIR}/cmake)
|
||||
|
||||
# include path
|
||||
include_directories(inc)
|
||||
##############################################
|
||||
# Declare dependencies
|
||||
find_package(CURL 7.57 REQUIRED MODULE)
|
||||
|
||||
# definition
|
||||
add_library(winhttppal SHARED src/winhttppal.cpp)
|
||||
add_library(winhttppal-static src/winhttppal.cpp)
|
||||
##############################################
|
||||
# Create target and set properties
|
||||
|
||||
set_target_properties(winhttppal PROPERTIES
|
||||
SOVERSION 1)
|
||||
add_library(winhttppal
|
||||
src/winhttppal.cpp
|
||||
)
|
||||
|
||||
#compile flags
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O2" )
|
||||
#Add an alias so that library can be used inside the build tree, e.g. when testing
|
||||
add_library(winhttppal::winhttppal ALIAS winhttppal)
|
||||
|
||||
target_link_libraries(winhttppal pthread dl stdc++ ${CURL_LIBRARIES} crypto ssl)
|
||||
target_link_libraries(winhttppal-static pthread dl stdc++ ${CURL_LIBRARIES} crypto ssl)
|
||||
set_target_properties(winhttppal-static PROPERTIES OUTPUT_NAME "winhttppal")
|
||||
#Set target properties
|
||||
target_include_directories(winhttppal
|
||||
PUBLIC
|
||||
$<INSTALL_INTERFACE:include>
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||
)
|
||||
|
||||
install(TARGETS winhttppal-static DESTINATION lib)
|
||||
install(TARGETS winhttppal DESTINATION lib)
|
||||
install(FILES inc/winhttppal.h src/winhttppal_imp.h DESTINATION include)
|
||||
target_compile_features(winhttppal PRIVATE cxx_auto_type)
|
||||
target_compile_options(winhttppal PRIVATE $<$<CXX_COMPILER_ID:GNU>:-Wall>)
|
||||
|
||||
target_link_libraries(winhttppal
|
||||
PUBLIC
|
||||
${CURL_LIBRARIES}
|
||||
)
|
||||
|
||||
##############################################
|
||||
# Installation instructions
|
||||
|
||||
include(GNUInstallDirs)
|
||||
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/winhttppal)
|
||||
|
||||
install(TARGETS winhttppal
|
||||
EXPORT winhttppal-targets
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
)
|
||||
|
||||
#This is required so that the exported target has the name winhttppal and not winhttppal
|
||||
set_target_properties(winhttppal PROPERTIES EXPORT_NAME winhttppal)
|
||||
|
||||
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||
|
||||
#Export the targets to a script
|
||||
install(EXPORT winhttppal-targets
|
||||
FILE
|
||||
winhttppalTargets.cmake
|
||||
NAMESPACE
|
||||
winhttppal::
|
||||
DESTINATION
|
||||
${INSTALL_CONFIGDIR}
|
||||
)
|
||||
|
||||
#Create a ConfigVersion.cmake file
|
||||
include(CMakePackageConfigHelpers)
|
||||
write_basic_package_version_file(
|
||||
${CMAKE_CURRENT_BINARY_DIR}/winhttppalConfigVersion.cmake
|
||||
VERSION ${PROJECT_VERSION}
|
||||
COMPATIBILITY AnyNewerVersion
|
||||
)
|
||||
|
||||
configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/cmake/winhttppalConfig.cmake.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/winhttppalConfig.cmake
|
||||
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
|
||||
)
|
||||
|
||||
#Install the config, configversion and custom find modules
|
||||
install(FILES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/winhttppalConfig.cmake
|
||||
${CMAKE_CURRENT_BINARY_DIR}/winhttppalConfigVersion.cmake
|
||||
DESTINATION ${INSTALL_CONFIGDIR}
|
||||
)
|
||||
|
||||
##############################################
|
||||
## Exporting from the build tree
|
||||
export(EXPORT winhttppal-targets FILE ${CMAKE_CURRENT_BINARY_DIR}/winhttppalTargets.cmake NAMESPACE winhttppal::)
|
||||
|
||||
#Register package in user's package registry
|
||||
#export(PACKAGE winhttppal)
|
||||
|
||||
#add_subdirectory(test)
|
|
@ -0,0 +1,15 @@
|
|||
get_filename_component(winhttppal_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
|
||||
include(CMakeFindDependencyMacro)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH ${winhttppal_CMAKE_DIR})
|
||||
|
||||
# NOTE Had to use find_package because find_dependency does not support COMPONENTS or MODULE until 3.8.0
|
||||
|
||||
find_package(CURL 1.57 REQUIRED MODULE)
|
||||
list(REMOVE_AT CMAKE_MODULE_PATH -1)
|
||||
|
||||
if(NOT TARGET winhttppal::winhttppal)
|
||||
include("${winhttppal_CMAKE_DIR}/winhttppalTargets.cmake")
|
||||
endif()
|
||||
|
||||
set(winhttppal_LIBRARIES winhttppal::winhttppal)
|
|
@ -0,0 +1,6 @@
|
|||
include(GNUInstallDirs)
|
||||
install(TARGETS winhttppal
|
||||
EXPORT winhttppal-export
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
)
|
Загрузка…
Ссылка в новой задаче