Skip to content

Commit

Permalink
Now the build output is a dynamic library, small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephP91 committed Sep 14, 2022
1 parent cafa9aa commit e7c7656
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 31 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ build.log
cmake-build-debug/
cmake-build-debug-visual-studio/
.vscode
install
install
.DS_Store
*.out
24 changes: 7 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ set(CURL_MIN_VERSION "7.28.0")
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(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")
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()

include(CheckIPOSupported)
Expand All @@ -37,8 +35,7 @@ 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)
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)
Expand All @@ -49,19 +46,12 @@ if(BUILD_TEST)
endif()

# Install
install(EXPORT curlcppTargets
NAMESPACE curlcpp::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/curlcpp)
install(EXPORT curlcppTargets NAMESPACE curlcpp:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/curlcpp)
include(CMakePackageConfigHelpers)
configure_package_config_file(CMake/curlcppConfig.cmake.in
"${PROJECT_BINARY_DIR}/curlcppConfig.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/curlcpp")
configure_package_config_file(CMake/curlcppConfig.cmake.in "${PROJECT_BINARY_DIR}/curlcppConfig.cmake" INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/curlcpp")
install(FILES ${PROJECT_BINARY_DIR}/curlcppConfig.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/curlcpp)

join_paths(libdir_for_pc_file "\${exec_prefix}" "${CMAKE_INSTALL_LIBDIR}")
join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
configure_file("${PROJECT_SOURCE_DIR}/src/curlcpp.pc.in"
"${PROJECT_BINARY_DIR}/src/curlcpp.pc"
@ONLY)
install(FILES "${PROJECT_BINARY_DIR}/src/curlcpp.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/")
configure_file("${PROJECT_SOURCE_DIR}/src/curlcpp.pc.in" "${PROJECT_BINARY_DIR}/src/curlcpp.pc" @ONLY)
install(FILES "${PROJECT_BINARY_DIR}/src/curlcpp.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/")
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,12 @@ cmake ..
make # -j2
```

**Note:** cURL >= 7.34 is required.
**Note:** cURL >= 7.28.0 is required.

Then add `<curlcpp root>/build/src/` to your library path and `<curlcpp root>/include/` to your include path.

When linking, link against `curlcpp` (e.g.: g++ -std=c++11 example.cpp -o example -lcurlcpp -lcurl).
Or if you want run from terminal,
When linking curlcpp to your application don't forget to also link `curl`. Example:

```bash
g++ -std=c++11 example.cpp -L/home/username/path/to/build/src/ -I/home/username/path/to/include/ -lcurlcpp -lcurl
g++ -std=c++11 example.cpp -I/usr/local/include/curlcpp/ -lcurlcpp -lcurl
```

Submodule
Expand Down
15 changes: 8 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ set(CURLCPP_HEADER_LIST
../include/curl_utility.h
)

add_library(curlcpp
add_library(curlcpp SHARED
curl_easy.cpp
curl_header.cpp
curl_global.cpp
Expand All @@ -37,14 +37,15 @@ add_library(curlcpp
cookie_date.cpp
cookie_time.cpp
cookie_datetime.cpp

${CURLCPP_HEADER_LIST}
)

add_library(curlcpp::curlcpp ALIAS curlcpp)

target_include_directories(curlcpp PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/../include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/>")
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/../include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/>")

target_compile_features(curlcpp PUBLIC cxx_std_11)

Expand Down Expand Up @@ -86,7 +87,7 @@ set_target_properties (curlcpp PROPERTIES PUBLIC_HEADER "${CURLCPP_HEADER_LIST}"

include(GNUInstallDirs)
install(TARGETS curlcpp
EXPORT ${PROJECT_NAME}Targets
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
EXPORT ${PROJECT_NAME}Targets
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})

0 comments on commit e7c7656

Please sign in to comment.