Skip to content

Commit

Permalink
modern CMake
Browse files Browse the repository at this point in the history
- bumped required CMake version
- removed globbing
- added targets with appropriate PUBLIC/PRIVATE properties
- added an option to use pkg-config
- added link-time optimization for release builds
- added default build type
- added some warnings and rewritten other compiler flags to use
  modern CMake functions
- installed headers are in extra directory to avoid polluting global
  include directory
- removed bii directory
  • Loading branch information
Xeverous committed Feb 25, 2020
1 parent 0c2f06d commit e4f875c
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 105 deletions.
72 changes: 36 additions & 36 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
IF(BIICODE)
INCLUDE(biicode/cmake/tools)

ACTIVATE_CPP11()
ADD_BIICODE_TARGETS()
ELSE()
cmake_minimum_required(VERSION 2.8)
#if using an older VERSION of curl ocsp stapling can be disabled
set(CURL_MIN_VERSION "7.28.0")
# Setting up project
project(CURLCPP)


# Add MacPorts
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_PREFIX_PATH /opt/local ${CMAKE_PREFIX_PATH})
endif()

# Checking for dependencies
find_package(CURL ${CURL_MIN_VERSION} REQUIRED)

# Set up include pathes
include_directories(${CURL_INCLUDE_DIRS}
${CURLCPP_SOURCE_DIR}/include)

file(GLOB HEADER_LIST "${CMAKE_SOURCE_DIR}/include/*.h")
install (FILES ${HEADER_LIST} DESTINATION include)

# Set up source directories
add_subdirectory(src)

set(CURLCPP_LIB_LOCATION "$<TARGET_FILE:${curlcpp}>")

configure_file(CMake/curlcppConfig.cmake.in
${CURLCPP_BINARY_DIR}/curlcppConfig.cmake @ONLY)
ENDIF()
cmake_minimum_required(VERSION 3.10...3.15)

#if using an older VERSION of curl ocsp stapling can be disabled
set(CURL_MIN_VERSION "7.28.0")
# Setting up project
project(curlcpp LANGUAGES CXX)

set(DEFAULT_BUILD_TYPE "Release")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified.")
set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE
STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()

include(CheckIPOSupported)
check_ipo_supported(RESULT IPO_SUPPORTED OUTPUT ERROR)

if(IPO_SUPPORTED)
message(STATUS "IPO / LTO supported, will enable for targets in release build type")
else()
message(STATUS "IPO / LTO not supported: <${ERROR}>, will not enable")
endif()

option(CURLCPP_USE_PKGCONFIG
"Use pkg-config to find libcurl. When off, find_package() will be used" OFF)

# Set up source directories
add_subdirectory(src)

set(CURLCPP_LIB_LOCATION "$<TARGET_FILE:${curlcpp}>")

configure_file(CMake/curlcppConfig.cmake.in
${CURLCPP_BINARY_DIR}/curlcppConfig.cmake @ONLY)
12 changes: 0 additions & 12 deletions bii/layout.bii

This file was deleted.

49 changes: 0 additions & 49 deletions bii/policies.bii

This file was deleted.

2 changes: 0 additions & 2 deletions bii/settings.bii

This file was deleted.

67 changes: 61 additions & 6 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
set(CURLCPP_SOURCE
set(CURLCPP_HEADER_LIST
../include/cookie.h
../include/cookie_date.h
../include/cookie_datetime.h
../include/cookie_time.h
../include/curl_config.h
../include/curl_cookie.h
../include/curl_easy.h
../include/curl_easy_info.h
../include/curl_exception.h
../include/curl_form.h
../include/curl_global.h
../include/curl_header.h
../include/curl_info.h
../include/curl_interface.h
../include/curl_ios.h
../include/curl_multi.h
../include/curl_option.h
../include/curl_pair.h
../include/curl_receiver.h
../include/curl_sender.h
../include/curl_share.h
../include/curl_utility.h
)

add_library(curlcpp)

target_sources(curlcpp
PRIVATE
curl_easy.cpp
curl_header.cpp
curl_global.cpp
Expand All @@ -12,16 +40,43 @@ set(CURLCPP_SOURCE
cookie_date.cpp
cookie_time.cpp
cookie_datetime.cpp
PUBLIC
${CURLCPP_HEADER_LIST}
)

target_include_directories(curlcpp PUBLIC ../include)

target_compile_features(curlcpp PUBLIC cxx_std_11)

target_compile_options(curlcpp PRIVATE
$<$<CXX_COMPILER_ID:GNU>:-Wall -Wextra -Wpedantic>
$<$<CXX_COMPILER_ID:Clang>:-Wall -Wpedantic>
$<$<CXX_COMPILER_ID:MSVC>:/W4 /wd4244 /wd4305 /wd4996 /wd4267 /wd4018>
)

if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
if(CURLCPP_USE_PKGCONFIG)
find_package(PkgConfig REQUIRED)
pkg_check_modules(libcurl REQUIRED IMPORTED_TARGET libcurl>=${CURL_MIN_VERSION})
target_link_libraries(curlcpp PUBLIC PkgConfig::libcurl)
else()
# Add MacPorts
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_PREFIX_PATH /opt/local ${CMAKE_PREFIX_PATH})
endif()

find_package(CURL ${CURL_MIN_VERSION} REQUIRED)

target_include_directories(curlcpp PUBLIC ${CURL_INCLUDE_DIRS})
target_link_libraries(curlcpp PUBLIC ${CURL_LIBRARY})
endif()

if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
target_compile_options(curlcpp PUBLIC -stdlib=libc++)
endif()

if(IPO_SUPPORTED AND CMAKE_BUILD_TYPE STREQUAL "Release")
set_target_properties(curlcpp PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()

add_library(curlcpp ${CURLCPP_SOURCE})
target_link_libraries(curlcpp ${CURL_LIBRARY})
install (TARGETS curlcpp LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)
install (FILES ${CURLCPP_HEADER_LIST} DESTINATION include/curlcpp)

0 comments on commit e4f875c

Please sign in to comment.