diff --git a/.gitignore b/.gitignore index c92fa45..40ce586 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,6 @@ -syntax: glob _build/ build/ lib/ - \.idea/ - -cmake-build-debug/ +cmake-build-*/ +src/sw_config.h \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index bc54623..6c34ee4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 + $ + $ +) + +# 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) @@ -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} +) \ No newline at end of file diff --git a/SocketW.pc.in b/SocketW.pc.in new file mode 100644 index 0000000..9cb3930 --- /dev/null +++ b/SocketW.pc.in @@ -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} diff --git a/SocketWConfig.cmake.in b/SocketWConfig.cmake.in new file mode 100644 index 0000000..eb8afe1 --- /dev/null +++ b/SocketWConfig.cmake.in @@ -0,0 +1,5 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/SocketWTargets.cmake") + +check_required_components(SocketW) \ No newline at end of file diff --git a/conanfile.txt b/conanfile.txt new file mode 100644 index 0000000..f3aae8d --- /dev/null +++ b/conanfile.txt @@ -0,0 +1,5 @@ +[requires] +openssl/1.1.1g + +[generators] +cmake_find_package \ No newline at end of file diff --git a/src/sw_config.h b/src/sw_config.h deleted file mode 100644 index a7271e8..0000000 --- a/src/sw_config.h +++ /dev/null @@ -1 +0,0 @@ -#define _HAVE_SSL /* build SSL class? */ diff --git a/src/sw_config.h.in b/src/sw_config.h.in new file mode 100644 index 0000000..ff91741 --- /dev/null +++ b/src/sw_config.h.in @@ -0,0 +1,2 @@ +/* build SSL class? */ +#cmakedefine _HAVE_SSL