Skip to content

Commit

Permalink
🔨 Added cmake package configuration file
Browse files Browse the repository at this point in the history
  • Loading branch information
AnotherFoxGuy committed Sep 3, 2021
1 parent 8927090 commit 789c95d
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 60 deletions.
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
syntax: glob
_build/
build/
lib/

\.idea/

cmake-build-debug/
cmake-build-*/
src/sw_config.h
121 changes: 66 additions & 55 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,39 +1,56 @@
cmake_minimum_required(VERSION 3.0.2)

project(SocketW)

if(EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
# For some reason Conans libcxx will break the build
conan_define_targets()
else()
find_package(OpenSSL REQUIRED)
endif()

# some versioning things
SET(LIB_MAJOR_VERSION "3")
SET(LIB_MINOR_VERSION "10")
SET(LIB_BUILD_VERSION "27" CACHE STRING "build version")
SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_BUILD_VERSION}")
IF (NOT DEFINED LIB_INSTALL_DIR)
SET(LIB_INSTALL_DIR "lib${LIB_SUFFIX}")
ENDIF (NOT DEFINED LIB_INSTALL_DIR)
# Required for conan
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_BINARY_DIR})

project(
SocketW
HOMEPAGE_URL http://rigsofrods.github.io/socketw/
DESCRIPTION "SocketW is a library which provides cross-platform socket abstraction "
VERSION 3.10.27
)

include(CMakePackageConfigHelpers)
include(GNUInstallDirs)

SET(CMAKEFILES_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/SocketW")

find_package(OpenSSL)

set(_HAVE_SSL ${OpenSSL_FOUND})
configure_file("${CMAKE_SOURCE_DIR}/src/sw_config.h.in" "${CMAKE_SOURCE_DIR}/src/sw_config.h")

file(GLOB sources "src/*.cxx")
file(GLOB headers "src/*.h")

add_library(SocketW ${sources} ${headers})
add_library(${CMAKE_PROJECT_NAME} ${sources} ${headers})

if (OpenSSL_FOUND)
include_directories(${OPENSSL_INCLUDE_DIR})
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE OpenSSL::SSL)
endif ()

target_include_directories(
${CMAKE_PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

# install the library
install(
TARGETS ${CMAKE_PROJECT_NAME}
EXPORT SocketWTargets
RUNTIME LIBRARY ARCHIVE
)

if(EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
include_directories(${CONAN_INCLUDE_DIRS_OPENSSL})
target_link_libraries(SocketW PRIVATE CONAN_PKG::openssl)
else()
include_directories(${OPENSSL_INCLUDE_DIR})
target_link_libraries(SocketW PRIVATE OpenSSL::SSL)
endif()
install(
EXPORT SocketWTargets
FILE SocketWTargets.cmake
NAMESPACE SocketW::
DESTINATION ${CMAKEFILES_INSTALL_DIR}
)

install(TARGETS SocketW DESTINATION lib)
install(DIRECTORY src/ DESTINATION include FILES_MATCHING PATTERN "*.h")
install(DIRECTORY src/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN "*.h")

if (UNIX)
# Detect Linux distribution (if possible)
Expand All @@ -45,30 +62,24 @@ if (UNIX)
message(STATUS "Linux distro is: ${LINUX_VERSION}")
endif ()

# CPack
set(CPACK_PACKAGE_DESCRIPTION "SocketW")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "SocketW is a library which provides cross-platform socket abstraction.")
set(CPACK_PACKAGE_NAME "socketw")
set(CPACK_PACKAGE_CONTACT "Edgar@AnotherFoxGuy.com")
set(CPACK_PACKAGE_VENDOR "Edgar@AnotherFoxGuy.com")
SET(CPACK_PACKAGE_VERSION ${LIB_VERSION})
SET(CPACK_PACKAGE_VERSION_MAJOR ${LIB_MAJOR_VERSION})
SET(CPACK_PACKAGE_VERSION_MINOR ${LIB_MINOR_VERSION})
SET(CPACK_PACKAGE_VERSION_PATCH ${LIB_BUILD_VERSION})
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README")

SET(CPACK_GENERATOR ZIP)
IF (UNIX)
SET(CPACK_GENERATOR ${CPACK_GENERATOR};STGZ;TGZ;DEB;RPM)
ENDIF (UNIX)
IF (LINUX)
SET(CPACK_GENERATOR ${CPACK_GENERATOR};DEB;RPM)
ENDIF (LINUX)
SET(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${LIB_VERSION}-${CMAKE_SYSTEM_PROCESSOR}")

IF (LINUX_VERSION)
SET(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-${LINUX_VERSION}")
ENDIF ()

include(CPack)
# install the PkgConfig file
configure_file("${CMAKE_SOURCE_DIR}/SocketW.pc.in" "${CMAKE_BINARY_DIR}/SocketW.pc" @ONLY)
install(FILES "${CMAKE_BINARY_DIR}/SocketW.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")

configure_package_config_file(
SocketWConfig.cmake.in
${CMAKE_BINARY_DIR}/SocketWConfig.cmake
INSTALL_DESTINATION ${CMAKEFILES_INSTALL_DIR}
)

write_basic_package_version_file(
${CMAKE_BINARY_DIR}/SocketWConfigVersion.cmake
VERSION "${CMAKE_PROJECT_VERSION}"
COMPATIBILITY SameMajorVersion
)

install(
FILES ${CMAKE_BINARY_DIR}/SocketWConfig.cmake
${CMAKE_BINARY_DIR}/SocketWConfigVersion.cmake
DESTINATION ${CMAKEFILES_INSTALL_DIR}
)
11 changes: 11 additions & 0 deletions SocketW.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
prefix="@CMAKE_INSTALL_PREFIX@"
exec_prefix="${prefix}"
libdir="${prefix}/@CMAKE_INSTALL_LIBDIR@"
includedir="${prefix}/include"

Name: @CMAKE_PROJECT_NAME@
Version: @CMAKE_PROJECT_VERSION@
Description: @CMAKE_PROJECT_DESCRIPTION@
Requires: @PKG_CONFIG_REQUIRES@
Libs: -L${libdir} -l@CMAKE_PROJECT_NAME@
Cflags: -I${includedir}
5 changes: 5 additions & 0 deletions SocketWConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/SocketWTargets.cmake")

check_required_components(SocketW)
5 changes: 5 additions & 0 deletions conanfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[requires]
openssl/1.1.1g

[generators]
cmake_find_package
1 change: 0 additions & 1 deletion src/sw_config.h

This file was deleted.

2 changes: 2 additions & 0 deletions src/sw_config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* build SSL class? */
#cmakedefine _HAVE_SSL

0 comments on commit 789c95d

Please # to comment.