Skip to content

Commit

Permalink
Merge pull request #6 from rexut/devel/linux
Browse files Browse the repository at this point in the history
Add Linux support
  • Loading branch information
zarthcode authored Oct 17, 2017
2 parents e874ff8 + 79198eb commit 389ceea
Show file tree
Hide file tree
Showing 57 changed files with 2,280 additions and 779 deletions.
36 changes: 36 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
language: cpp

matrix:
include:
- os: linux
dist: trusty
sudo: required
compiler: gcc
env: CMAKE_EXTRA_OPTS=""
- os: linux
dist: trusty
sudo: required
compiler: clang
env: CMAKE_EXTRA_OPTS="-DCMAKE_CXX_FLAGS=-stdlib=libc++"

addons:
apt:
packages:
- cmake
- libc++-dev
- libboost-test-dev
- libboost-system-dev
- libboost-filesystem-dev
- libusb-1.0-0-dev
- libusb-dev
sources:
- ubuntu-toolchain-r-test

before_script:
- mkdir build
- cd build
- cmake $CMAKE_EXTRA_OPTS -DCMAKE_BUILD_TYPE=Debug ..

script:
- make
- make check
192 changes: 192 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
#
# To build out-of-source do (example):
#
# mkdir build
# cd build
# cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
#
# CMAKE_BUILD_TYPE can be: empty, Debug, Release, RelWithDebInfo or MinSizeRel
#

# Define minimum CMake version required
cmake_minimum_required(VERSION 2.8.5 FATAL_ERROR)

# Define the project name belong their language.
# This top-leve project name can be refered by refered exactly by
# ${CMAKE_PROJECT_NAME} -- any overwritten project name can be refered by
# ${PROJECT_NAME}.
project (libusbpp CXX)

# The project package version.
set (PROJECT_VERSION_MAJOR 1)
set (PROJECT_VERSION_MINOR 0)
set (PROJECT_VERSION_PATCH 0)

# The project package version.
set (PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")

# The package configuration name.
set (PACKAGE_NAME "${PROJECT_NAME}")

# Define a short description of the project (only a few words).
set (PACKAGE_DESCRIPTION "C++ wrapper API of C API for USB device access (libusb-1.0)")

# The package configuration version.
set (PACKAGE_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")

# The package full name with version
set (PACKAGE "${PACKAGE_NAME}-${PACKAGE_VERSION}")

# The API version (SOVERSION) of the USBPP libraries.
# Increment this when more or fewer functions are included in the
# library, the function prototype changes, or data type changes.
#
# The SOVERSION is not necessarily the same as the major version.
# The rule is that any breakage of the ABI must be indicated by
# incrementing the SOVERSION. So, adding e.g. functions is no
# problem, modifying argument lists or removing functions would
# required the SOVERSION to be incremented. Similar rules hold of
# course for non-opaque data-structures. For C++ the whole issue
# is infinitely more complicated, as determining whether the ABI
# was changed in an incompatible way is AFAIK nearly impossible.
#
# Refer to:
# cmake --help-command set_target_properties
# cmake --help-property SOVERSION
# https://community.kde.org/Policies/Binary_Compatibility_Issues_With_C++
#
set (LIBUSBPP_LIB_SOVERSION 0)

# The build version (VERSION) of the USBPP libraries.
set (LIBUSBPP_LIB_VERSION "${LIBUSBPP_LIB_SOVERSION}.${PACKAGE_VERSION}")

# The build name (OUTPUT_NAME) of the USBPP libraries.
set (LIBUSBPP_LIB_NAME "usbpp-${PACKAGE_VERSION}")

# Make sure the user doesn't play dirty with symlinks
get_filename_component (srcdir "${CMAKE_SOURCE_DIR}" REALPATH)
get_filename_component (bindir "${CMAKE_BINARY_DIR}" REALPATH)

# Disallow in-source builds
if (${srcdir} STREQUAL ${bindir})
message(FATAL_ERROR "In-source builds are not allowed. "
"Please create a directory and run cmake from there, passing the path "
"to this source directory as the last argument. This process created "
"the file `CMakeCache.txt' and the directory `CMakeFiles' in ${srcdir}. "
"Please remove them.")
endif (${srcdir} STREQUAL ${bindir})

# Use NEW behavior with newer CMake releases
foreach (p
CMP0025 # CMake 3.0: Compiler id for Apple Clang is now AppleClang
)
if (POLICY ${p})
cmake_policy(SET ${p} NEW)
endif()
endforeach()

# Use OLD behavior with newer CMake releases
foreach (p
CMP0026 # CMake 3.0: Disallow use of the LOCATION target property
)
if (POLICY ${p})
cmake_policy(SET ${p} OLD)
endif()
endforeach()

# Make it possible to locate CMake modules for finding libraries
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

# Use GNUInstallDirst to get canonical paths
include(GNUInstallDirs)

# Check for C++14 or at least C++11 support
include (CheckCXXCompilerFlag)
check_cxx_compiler_flag ("-std=c++14" COMPILER_SUPPORTS_CXX14)
if (COMPILER_SUPPORTS_CXX14)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
else (COMPILER_SUPPORTS_CXX14)
message (WARNING "The compiler ${CMAKE_CXX_COMPILER} "
"has no C++14 support. Try to fall back "
"to older C++11 compatibility level.")
check_cxx_compiler_flag ("-std=c++11" COMPILER_SUPPORTS_CXX11)
check_cxx_compiler_flag ("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if (COMPILER_SUPPORTS_CXX11)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif (COMPILER_SUPPORTS_CXX0X)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else (COMPILER_SUPPORTS_CXX0X)
message (FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} "
"has no C++11 support. Please use a "
"different C++ compiler.")
endif (COMPILER_SUPPORTS_CXX11)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include backport_std_unique_ptr.hpp")
endif (COMPILER_SUPPORTS_CXX14)

# Setup CMake to run tests
include (CTest)
if (BUILD_TESTING)
# Setup CMake to provide a customized CTest -- see:
# https://cmake.org/Wiki/CMake/Testing_With_CTest#Customizing_CTest
enable_testing ()
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/CTestCustom.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake"
IMMEDIATE @ONLY)
# Emulate GNU Autotools 'make check'
if (NOT TARGET check)
add_custom_target (check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure)
endif (NOT TARGET check)
# Combine the fancy 'make ARGS=--verbose all test'
if (NOT TARGET build_and_test)
add_custom_target (build_and_test COMMAND ${CMAKE_CTEST_COMMAND} --verbose)
endif (NOT TARGET build_and_test)
add_subdirectory (test)
endif (BUILD_TESTING)

# Setup CMake to provide an uninstall target -- see:
# https://cmake.org/Wiki/CMake_FAQ#Can_I_do_.22make_uninstall.22_with_CMake.3F
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)

if (NOT TARGET uninstall)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif (NOT TARGET uninstall)

# This makes the project importable from the install directory
# Put config file in per-project dir (name MUST match), can also
# just go into <prefix>/cmake.
install(EXPORT ${PACKAGE_NAME}Config DESTINATION ${CMAKE_INSTALL_DATADIR}/${PACKAGE}/cmake)

# Exporting dependencies towards external packages
set (PKG_CONFIG_REQUIRES libusb-1.0)
set (PKG_CONFIG_LIBDIR
"\${prefix}/lib"
)
set (PKG_CONFIG_INCLUDEDIR
"\${prefix}/include/${PACKAGE}"
)
set (PKG_CONFIG_LIBS
"-L\${libdir} -l${LIBUSBPP_LIB_NAME}"
)
set (PKG_CONFIG_CFLAGS
"-I\${includedir}"
)

configure_file (
${CMAKE_CURRENT_SOURCE_DIR}/cmake/pkg-config.pc.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}.pc
)

# Install package configuration file
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)

## Add subdirectories
add_subdirectory (headers)
add_subdirectory (src)
add_subdirectory (examples)
21 changes: 21 additions & 0 deletions CTestCustom.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# CTestCustom.cmake
#
# CTest can be customized by providing CTestCustom.cmake -- see:
# https://cmake.org/Wiki/CMake/Testing_With_CTest#Customizing_CTest
#

# disable unit test cases that will fail on non-WIN32 systems
if (NOT WIN32)
set (
CTEST_CUSTOM_TESTS_IGNORE ${CTEST_CUSTOM_TESTS_IGNORE}
# OFF: TestSuit
# OFF: TestSuit/TestCase
)
endif (NOT WIN32)

# Check if all tests will run
message ("[****] Searching for ignored test cases...")
foreach (_ct_ignored ${CTEST_CUSTOM_TESTS_IGNORE})
message (AUTHOR_WARNING "**** IGNORED: ${_ct_ignored}")
endforeach ()
2 changes: 1 addition & 1 deletion Libusb++.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Libusb++", "Libusb++.vcxproj", "{30392DF7-2449-406E-B2DF-40CEA218C8C1}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LibusbTest", "LibusbTest\LibusbTest.vcxproj", "{C0929D1D-39E5-4859-B60F-4A24D69CD73C}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LibusbTest", "examples\LibusbTest.vcxproj", "{C0929D1D-39E5-4859-B60F-4A24D69CD73C}"
ProjectSection(ProjectDependencies) = postProject
{30392DF7-2449-406E-B2DF-40CEA218C8C1} = {30392DF7-2449-406E-B2DF-40CEA218C8C1}
EndProjectSection
Expand Down
32 changes: 16 additions & 16 deletions Libusb++.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<IncludePath>D:\Libraries\libusbx\libroot;$(IncludePath)</IncludePath>
<IncludePath>D:\Libraries\libusbx\libroot\libusb;$(IncludePath)</IncludePath>
<OutDir>$(SolutionDir)build\$(Platform)\$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(SolutionDir)build\$(Platform)\$(Configuration)\</OutDir>
<IncludePath>D:\Libraries\libusbx\libroot;$(IncludePath)</IncludePath>
<IncludePath>D:\Libraries\libusbx\libroot\libusb;$(IncludePath)</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
Expand Down Expand Up @@ -90,22 +90,22 @@
</Lib>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="headers\Configuration.h" />
<ClInclude Include="headers\Device.h" />
<ClInclude Include="headers\Endpoint.h" />
<ClInclude Include="headers\Endpointdefs.h" />
<ClInclude Include="headers\Interface.h" />
<ClInclude Include="headers\Libusbpp.h" />
<ClInclude Include="headers\Transfer.h" />
<ClInclude Include="headers\Transferdefs.h" />
<ClInclude Include="headers\UsbException.h" />
<ClInclude Include="headers\libusbpp\Configuration.h" />
<ClInclude Include="headers\libusbpp\Device.h" />
<ClInclude Include="headers\libusbpp\Endpoint.h" />
<ClInclude Include="headers\libusbpp\EndpointDefs.h" />
<ClInclude Include="headers\libusbpp\Exception.h" />
<ClInclude Include="headers\libusbpp\Interface.h" />
<ClInclude Include="headers\libusbpp\Transfer.h" />
<ClInclude Include="headers\libusbpp\TransferDefs.h" />
<ClInclude Include="headers\libusbpp.h" />
<ClInclude Include="src\ConfigurationImpl.h" />
<ClInclude Include="src\DeviceImpl.h" />
<ClInclude Include="src\EndpointImpl.h" />
<ClInclude Include="src\InterfaceImpl.h" />
<ClInclude Include="src\LibusbImpl.h" />
<ClInclude Include="src\TransferImpl.h" />
<ClInclude Include="src\wideconvert.h" />
<ClInclude Include="src\Wideconvert.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\Configuration.cpp" />
Expand All @@ -114,16 +114,16 @@
<ClCompile Include="src\DeviceImpl.cpp" />
<ClCompile Include="src\Endpoint.cpp" />
<ClCompile Include="src\EndpointImpl.cpp" />
<ClCompile Include="src\Exception.cpp" />
<ClCompile Include="src\Interface.cpp" />
<ClCompile Include="src\InterfaceImpl.cpp" />
<ClCompile Include="src\LibusbImpl.cpp" />
<ClCompile Include="src\Libusbpp.cpp" />
<ClCompile Include="src\libusbpp.cpp" />
<ClCompile Include="src\Transfer.cpp" />
<ClCompile Include="src\TransferImpl.cpp" />
<ClCompile Include="src\UsbException.cpp" />
<ClCompile Include="src\wideconvert.cpp" />
<ClCompile Include="src\Wideconvert.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
Loading

0 comments on commit 389ceea

Please sign in to comment.