Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Conan as a dependency manager #122

Closed
wants to merge 12 commits into from
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ nbproject/*

# Generated headers
/src/ArcusExport.h

/cmake-build-*/
155 changes: 63 additions & 92 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,117 +1,68 @@
project(arcus)
cmake_minimum_required(VERSION 3.8)
cmake_minimum_required(VERSION 3.13)

include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
include(GenerateExportHeader)

option(BUILD_PYTHON "Build " ON)
# Basic projects options
option(BUILD_PYTHON "Build Python module" ON)
option(BUILD_EXAMPLES "Build the example programs" ON)
option(BUILD_STATIC "Build as a static library" OFF)

if(WIN32)
option(MSVC_STATIC_RUNTIME "Link the MSVC runtime statically" OFF)
endif()

# We want to have access to protobuf_generate_cpp and other FindProtobuf features.
# However, if ProtobufConfig is used instead, there is a CMake option that controls
# this, which defaults to OFF. We need to force this option to ON instead.
set(protobuf_MODULE_COMPATIBLE ON CACHE INTERNAL "" FORCE)
find_package(Protobuf 3.0.0 REQUIRED)

set(CMAKE_POSITION_INDEPENDENT_CODE ON) #Required if a patch to libArcus needs to be made via templates.

if(BUILD_PYTHON)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)

# FIXME: Remove the code for CMake <3.12 once we have switched over completely.
# FindPython3 is a new module since CMake 3.12. It deprecates FindPythonInterp and FindPythonLibs.
if(${CMAKE_VERSION} VERSION_LESS 3.12)
# FIXME: Use FindPython3 to find Python, new in CMake 3.12.
# However currently on our CI server it finds the wrong Python version and then doesn't find the headers.
find_package(PythonInterp 3.4 REQUIRED)
find_package(PythonLibs 3.4 REQUIRED)

else()
# Use FindPython3 for CMake >=3.12
find_package(Python3 3.4 REQUIRED COMPONENTS Interpreter Development)
endif()

find_package(SIP REQUIRED)
if(NOT DEFINED LIB_SUFFIX)
set(LIB_SUFFIX "")
endif()

include_directories(python/ src/ ${SIP_INCLUDE_DIRS} ${Python3_INCLUDE_DIRS})
endif()

set(CMAKE_CXX_STANDARD 17)
include(cmake/StandardProjectSettings.cmake)
include(CMakePackageConfigHelpers)
include(GenerateExportHeader)

if(APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
set(ARCUS_VERSION 1.1.0)
set(ARCUS_SOVERSION 3)

set(arcus_SRCS
src/Socket.cpp
src/SocketListener.cpp
src/MessageTypeStore.cpp
src/PlatformSocket.cpp
src/Error.cpp
)
src/Error.cpp)

set(arcus_HDRS
src/Socket.h
src/SocketListener.h
src/Types.h
src/MessageTypeStore.h
src/Error.h
${CMAKE_CURRENT_BINARY_DIR}/src/ArcusExport.h
src/ArcusExport.h
)

set(ARCUS_VERSION 1.1.0)
set(ARCUS_SOVERSION 3)

set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}")

if(BUILD_STATIC)
add_library(Arcus STATIC ${arcus_SRCS})
if(NOT WIN32 OR CMAKE_COMPILER_IS_GNUCXX)
target_link_libraries(Arcus PRIVATE pthread)
set_target_properties(Arcus PROPERTIES COMPILE_FLAGS -fPIC)
endif()
else()
if(${BUILD_SHARED_LIBS})
add_library(Arcus SHARED ${arcus_SRCS})
else()
add_library(Arcus STATIC ${arcus_SRCS})
endif()

if(MSVC_STATIC_RUNTIME)
foreach(flag_var
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if(${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif(${flag_var} MATCHES "/MD")
endforeach(flag_var)
endif()
use_threads(Arcus)

if(BUILD_PYTHON)
set(SIP_EXTRA_FILES_DEPEND python/SocketListener.sip python/Types.sip python/PythonMessage.sip python/Error.sip)
set(SIP_EXTRA_SOURCE_FILES python/PythonMessage.cpp)
set(SIP_EXTRA_OPTIONS -g -n PyQt5.sip) # -g means always release the GIL before calling C++ methods. -n PyQt5.sip is required to not get the PyCapsule error
add_sip_python_module(Arcus python/Socket.sip Arcus)
endif()
find_package(Protobuf 3.9.2 REQUIRED)
target_link_libraries(Arcus PUBLIC protobuf::libprotobuf)

target_include_directories(Arcus PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
${PROTOBUF_INCLUDE_DIR}
)
target_link_libraries(Arcus PUBLIC ${PROTOBUF_LIBRARIES})
set_project_standards(Arcus)
set_project_warnings(Arcus)
enable_sanitizers(Arcus)

if(NOT MSVC)
if(${CMAKE_BUILD_TYPE} STREQUAL "Debug" OR ${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo")
target_compile_definitions(Arcus PUBLIC -DARCUS_DEBUG)
endif()
endif()

if(WIN32)
add_definitions(-D_WIN32_WINNT=0x0600) # Declare we require Vista or higher, this allows us to use IPv6 functions.
# Declare we require Vista or higher, this allows us to use IPv6 functions.
target_compile_definitions(Arcus PUBLIC -D_WIN32_WINNT=0x0600)
target_link_libraries(Arcus PUBLIC Ws2_32)
endif()

generate_export_header(Arcus EXPORT_FILE_NAME ${CMAKE_SOURCE_DIR}/src/ArcusExport.h)
target_include_directories(Arcus
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

if(${CMAKE_BUILD_TYPE})
if(${CMAKE_BUILD_TYPE} STREQUAL "Debug" OR ${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo")
add_definitions(-DARCUS_DEBUG)
Expand All @@ -128,12 +79,34 @@ set_target_properties(Arcus PROPERTIES
VISIBILITY_INLINES_HIDDEN 1
)

generate_export_header(Arcus
EXPORT_FILE_NAME src/ArcusExport.h
)
# This is required when building out-of-tree.
# The compiler won't find the generated header otherwise.
include_directories(${CMAKE_BINARY_DIR}/src)
if(BUILD_PYTHON)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)

find_package(SIP REQUIRED)
if(NOT DEFINED LIB_SUFFIX)
set(LIB_SUFFIX "")
endif()

set(SIP_EXTRA_FILES_DEPEND python/SocketListener.sip python/Types.sip python/PythonMessage.sip python/Error.sip)
set(SIP_EXTRA_SOURCE_FILES python/PythonMessage.cpp)
set(SIP_EXTRA_OPTIONS -y Arcus.pyi -o -g -n PyQt5.sip) # -g means always release the GIL before calling C++ methods. -n PyQt5.sip is required to not get the PyCapsule error
add_sip_python_module(Arcus python/Socket.sip Arcus)
use_python(python_module_Arcus Interpreter Development)

target_link_libraries(python_module_Arcus
PRIVATE
SIP::SIP
protobuf::libprotobuf
Arcus
)
target_include_directories(python_module_Arcus
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/python>
)
set_project_standards(python_module_Arcus)
set_project_warnings(python_module_Arcus)
endif()

if(BUILD_EXAMPLES)
add_subdirectory(examples)
Expand All @@ -147,9 +120,7 @@ install(TARGETS Arcus
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/Arcus
)

install(EXPORT Arcus-targets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Arcus
)
install(EXPORT Arcus-targets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Arcus)

configure_package_config_file(ArcusConfig.cmake.in ${CMAKE_BINARY_DIR}/ArcusConfig.cmake INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Arcus)
write_basic_package_version_file(${CMAKE_BINARY_DIR}/ArcusConfigVersion.cmake VERSION ${ARCUS_VERSION} COMPATIBILITY SameMajorVersion)
Expand Down
24 changes: 13 additions & 11 deletions cmake/FindSIP.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,13 @@ if(APPLE)
set(CMAKE_FIND_FRAMEWORK LAST)
endif()

# FIXME: Use FindPython3 to find Python, new in CMake 3.12.
# However currently on our CI server it finds the wrong Python version and then doesn't find the headers.
find_package(PythonInterp 3.5 REQUIRED)
find_package(PythonLibs 3.5 REQUIRED)

# Define variables that are available in FindPython3, so there's no need to branch off in the later part.
set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE})
set(Python3_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS})
set(Python3_LIBRARIES ${PYTHON_LIBRARIES})
set(Python3_VERSION_MINOR "${PYTHON_VERSION_MINOR}")
if(NOT Python_VERSION)
set(Python_VERSION
3.8
CACHE STRING "Python Version" FORCE)
message(STATUS "Setting Python version to ${Python_VERSION}. Set Python_VERSION if you want to compile against an other version.")
endif()
find_package(Python3 ${Python_VERSION} EXACT REQUIRED COMPONENTS Interpreter Development)

execute_process(
COMMAND ${Python3_EXECUTABLE} -c
Expand Down Expand Up @@ -89,4 +86,9 @@ if(SIP_FOUND)
include(${CMAKE_CURRENT_LIST_DIR}/SIPMacros.cmake)
endif()

mark_as_advanced(SIP_EXECUTABLE SIP_INCLUDE_DIRS SIP_VERSION)
add_library(SIP::SIP INTERFACE IMPORTED)
set_property(TARGET SIP::SIP
PROPERTY INTERFACE_INCLUDE_DIRECTORIES
${SIP_INCLUDE_DIRS} APPEND)

mark_as_advanced(SIP_EXECUTABLE SIP_INCLUDE_DIRS SIP_VERSION SIP::SIP)
8 changes: 0 additions & 8 deletions cmake/SIPMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,6 @@ MACRO(ADD_SIP_PYTHON_MODULE MODULE_NAME MODULE_SIP)
DEPENDS ${_abs_module_sip} ${SIP_EXTRA_FILES_DEPEND}
)
ADD_LIBRARY(${_logical_name} MODULE ${_sip_output_files} ${SIP_EXTRA_SOURCE_FILES})
IF (NOT APPLE)
IF ("${Python3_VERSION_MINOR}" GREATER 7)
MESSAGE(STATUS "Python > 3.7 - not linking to libpython")
ELSE ()
TARGET_LINK_LIBRARIES(${_logical_name} ${Python3_LIBRARIES})
ENDIF ()
ENDIF (NOT APPLE)
TARGET_LINK_LIBRARIES(${_logical_name} ${EXTRA_LINK_LIBRARIES})
IF (APPLE)
SET_TARGET_PROPERTIES(${_logical_name} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
ENDIF (APPLE)
Expand Down
Loading