Skip to content

Commit

Permalink
Merge branch 'pkgconfig' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregory Mullen (grayhatter) committed Aug 20, 2017
2 parents 5c07a65 + 447d50f commit e6d2d53
Show file tree
Hide file tree
Showing 24 changed files with 301 additions and 239 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ install_manifest.txt
toxcore/tox*
sys/**


# generated by CMake
src/cocoa/Info.plist
src/utox.1
79 changes: 33 additions & 46 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.2)
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.6 CACHE STRING "Minimum OS X deployment version")
project(uTox LANGUAGES C)

#####################
Expand Down Expand Up @@ -101,6 +102,8 @@ elseif(FREEBSD)
include(cmake/toolchain-freebsd.cmake)
elseif(OPENBSD OR NETBSD)
include(cmake/toolchain-openbsd.cmake)
elseif(APPLE)
include(cmake/macOS.cmake)
endif()


Expand Down Expand Up @@ -247,10 +250,6 @@ if(ENABLE_WERROR)
add_cflag("-Werror")
endif()

if(ENABLE_FILTERAUDIO)
add_cflag("-DAUDIO_FILTERING")
endif()

if(UTOX_STATIC)
if(UNIX)
add_cflag("-Wl -Bstatic -lopus -lopenal -lfilteraudio -Bdynamic -lrt -lm -lpthread -ldl")
Expand All @@ -263,9 +262,9 @@ if(ENABLE_AUTOUPDATE)
add_cflag("-DENABLE_AUTOUPDATE=1")
endif()

if(TOXCORE_STATIC)
if(TOXCORE_STATIC AND WIN32)
# The static windows libs need all of these... because REASONS!
set(TOX_LIBS
find_package(libtox REQUIRED COMPONENTS
toxencryptsave
toxav
toxcore
Expand All @@ -276,14 +275,16 @@ if(TOXCORE_STATIC)
toxnetcrypto
toxcrypto
toxnetwork
)
)
else()
set(TOX_LIBS
toxencryptsave
toxav
toxcore
)
find_package(libtox REQUIRED COMPONENTS toxencryptsave toxav toxcore)
endif()
include_directories(${LIBTOX_INCLUDE_DIRS})
set(TOX_LIBS ${LIBTOX_LIBRARIES})

find_package(libsodium REQUIRED)
include_directories(${LIBSODIUM_INCLUDE_DIRS})
set(LIBRARIES ${LIBRARIES} ${LIBSODIUM_LIBRARIES})

# Protip, you must use a different directory for each build target...
# -DMAKE_TOOLCHAIN_FILE has no effect unless the target directory is empty
Expand Down Expand Up @@ -312,33 +313,14 @@ if(WIN32)
elseif(APPLE)
set(GUI_TYPE MACOSX_BUNDLE)

# Make apple icon
set(APPLE_ICON utox.icns)
add_custom_command(OUTPUT utox.icns
COMMAND iconutil --convert icns ${uTox_SOURCE_DIR}/src/cocoa/utox.iconset -o utox.icns
DEPENDS ${uTox_SOURCE_DIR}/src/cocoa/utox.iconset
)
set_source_files_properties(${APPLE_ICON} PROPERTIES
MACOSX_PACKAGE_LOCATION "Resources")

include_directories( /usr/local/include /usr/include/malloc )
link_directories ( /usr/local/lib )

# Homebrew installed libtoxcore
if(EXISTS /usr/local/opt/libtoxcore/)
include_directories( /usr/local/opt/libtoxcore/include )
link_directories ( /usr/local/opt/libtoxcore/lib )
endif()

add_definitions("-x objective-c")
add_subdirectory(src/cocoa)
set(LIBRARIES "opus")
elseif(UNIX)
add_subdirectory(src/xlib)

if(LINUX)
# Required for v4l (at least in the Linux static builds on Jenkins)
set(LIBRARIES "rt")
set(LIBRARIES ${LIBRARIES} "rt")
endif()
endif()

Expand Down Expand Up @@ -385,34 +367,39 @@ add_executable(utox ${GUI_TYPE}
src/window.c

${WINDOWS_ICON}
${APPLE_ICON}
${APPLE_FILES}

)

target_link_libraries(utox
utoxAV utoxNATIVE utoxUI
${TOX_LIBS} ${LIBRARIES} sodium
${TOX_LIBS} ${LIBRARIES}
vpx pthread m )

set_property(TARGET utox PROPERTY C_STANDARD 11)
if(APPLE)
set_target_properties(utox PROPERTIES MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION})
set_target_properties(utox PROPERTIES MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION})
set_target_properties(utox PROPERTIES MACOSX_BUNDLE_LONG_VERSION_STRING ${PROJECT_VERSION})
set_target_properties(utox PROPERTIES MACOSX_BUNDLE_GUI_IDENTIFIER "io.utox.future")
set_target_properties(utox PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "uTox")
set_target_properties(utox PROPERTIES MACOSX_BUNDLE_COPYRIGHT ${PROJECT_COPYRIGHT})
set_target_properties(utox PROPERTIES MACOSX_BUNDLE_ICON_FILE "${APPLE_ICON}")

install(TARGETS utox
RUNTIME DESTINATION "bin"
BUNDLE DESTINATION "resources"
)
if(APPLE)
set_target_properties(utox PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${uTox_SOURCE_DIR}/src/cocoa/Info.plist")
# check that the app is valid and when the app is static
# also check that it does not depend on external libs (system libs excepted)
install(CODE "include(BundleUtilities)
verify_app(${CMAKE_BINARY_DIR}/utox.app)
if(UTOX_STATIC OR TOXCORE_STATIC)
verify_bundle_prerequisites(${CMAKE_BINARY_DIR}/utox.app RETURN_VAR INFO_VAR)
endif()"
)
# needed for packaging, so that CPack can find the app
install(TARGETS utox DESTINATION .)
# install App
install(TARGETS utox DESTINATION /Applications)
elseif(UNIX)
install(TARGETS utox
RUNTIME DESTINATION "bin"
)
endif()

# packaging
include(CPack)

###########
# Testing #
Expand Down
38 changes: 38 additions & 0 deletions cmake/Findlibfilteraudio.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# - Try to find FilterAudio
# Once done this will define
# LIBFILTERAUDIO_FOUND - System has FilterAudio
# LIBFILTERAUDIO_INCLUDE_DIRS - The FilterAudio include directories
# LIBFILTERAUDIO_LIBRARIES - The libraries needed to use FilterAudio
# LIBFILTERAUDIO_DEFINITIONS - Compiler switches required for using FilterAudio

find_package(PkgConfig)

pkg_check_modules(PKG_LIBFILTERAUDIO QUIET libfilteraudio)
set(LIBFILTERAUDIO_DEFINITIONS ${PKG_LIBFILTERAUDIO_CFLAGS_OTHER})

find_path(LIBFILTERAUDIO_INCLUDE_DIR filter_audio.h HINTS
${PKG_LIBFILTERAUDIO_INCLUDEDIR}
${PKG_LIBFILTERAUDIO_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/libs/windows-x64/include
)

find_library(LIBFILTERAUDIO_LIBRARY NAMES filteraudio HINTS
${PKG_LIBFILTERAUDIO_LIBDIR}
${PKG_LIBFILTERAUDIO_LIBRARY_DIRS}
${CMAKE_SOURCE_DIR}/libs/windows-x64/lib
)

include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set LIBFILTERAUDIO_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args(
libfilteraudio
DEFAULT_MSG
LIBFILTERAUDIO_LIBRARY
LIBFILTERAUDIO_INCLUDE_DIR
)

mark_as_advanced(LIBFILTERAUDIO_INCLUDE_DIR LIBFILTERAUDIO_LIBRARY)

set(LIBFILTERAUDIO_LIBRARIES ${LIBFILTERAUDIO_LIBRARY})
set(LIBFILTERAUDIO_INCLUDE_DIRS ${LIBFILTERAUDIO_INCLUDE_DIR})
38 changes: 38 additions & 0 deletions cmake/Findlibopus.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# - Try to find opus
# Once done this will define
# LIBOPUS_FOUND - System has opus
# LIBOPUS_INCLUDE_DIRS - The opus include directories
# LIBOPUS_LIBRARIES - The libraries needed to use opus
# LIBOPUS_DEFINITIONS - Compiler switches required for using opus

find_package(PkgConfig)

pkg_check_modules(PKG_LIBOPUS QUIET libopus)
set(LIBOPUS_DEFINITIONS ${PKG_LIBOPUS_CFLAGS_OTHER})

find_path(LIBOPUS_INCLUDE_DIR opus/opus.h HINTS
${PKG_LIBOPUS_INCLUDEDIR}
${PKG_LIBOPUS_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/libs/windows-x64/include
)

find_library(LIBOPUS_LIBRARY NAMES opus HINTS
${PKG_LIBOPUS_LIBDIR}
${PKG_LIBOPUS_LIBRARY_DIRS}
${CMAKE_SOURCE_DIR}/libs/windows-x64/lib
)

include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set LIBOPUS_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args(
libopus
DEFAULT_MSG
LIBOPUS_LIBRARY
LIBOPUS_INCLUDE_DIR
)

mark_as_advanced(LIBOPUS_INCLUDE_DIR LIBOPUS_LIBRARY)

set(LIBOPUS_LIBRARIES ${LIBOPUS_LIBRARY})
set(LIBOPUS_INCLUDE_DIRS ${LIBOPUS_INCLUDE_DIR})
38 changes: 38 additions & 0 deletions cmake/Findlibsodium.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# - Try to find sodium
# Once done this will define
# LIBSODIUM_FOUND - System has sodium
# LIBSODIUM_INCLUDE_DIRS - The sodium include directories
# LIBSODIUM_LIBRARIES - The libraries needed to use sodium
# LIBSODIUM_DEFINITIONS - Compiler switches required for using sodium

find_package(PkgConfig)

pkg_check_modules(PKG_LIBSODIUM QUIET libsodium)
set(LIBSODIUM_DEFINITIONS ${PKG_LIBSODIUM_CFLAGS_OTHER})

find_path(LIBSODIUM_INCLUDE_DIR sodium.h HINTS
${PKG_LIBSODIUM_INCLUDEDIR}
${PKG_LIBSODIUM_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/libs/windows-x64/include
)

find_library(LIBSODIUM_LIBRARY NAMES sodium HINTS
${PKG_LIBSODIUM_LIBDIR}
${PKG_LIBSODIUM_LIBRARY_DIRS}
${CMAKE_SOURCE_DIR}/libs/windows-x64/lib
)

include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set LIBSODIUM_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args(
libsodium
DEFAULT_MSG
LIBSODIUM_LIBRARY
LIBSODIUM_INCLUDE_DIR
)

mark_as_advanced(LIBSODIUM_INCLUDE_DIR LIBSODIUM_LIBRARY)

set(LIBSODIUM_LIBRARIES ${LIBSODIUM_LIBRARY})
set(LIBSODIUM_INCLUDE_DIRS ${LIBSODIUM_INCLUDE_DIR})
69 changes: 69 additions & 0 deletions cmake/Findlibtox.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# - Try to find Tox
# Once done this will define
# LIBTOX_FOUND - System has Tox
# LIBTOX_INCLUDE_DIRS - The Tox include directories
# LIBTOX_LIBRARY_DIRS - The Tox lib directories
# LIBTOX_LIBRARIES - The libraries needed to use Tox
# LIBTOX_DEFINITIONS - Compiler switches required for using Tox
#
# COMPONENTS
# toxencryptsave
# toxav
# toxdns
# toxcore
# toxgroup
# toxmessenger
# toxfriends
# toxdht
# toxnetcrypto
# toxcrypto
# toxnetwork

find_package(PkgConfig)

if(libtox_FIND_COMPONENTS)
set(_TOX_COMPNENTS ${libtox_FIND_COMPONENTS})
else()
set(_TOX_COMPNENTS toxencryptsave toxdns toxav toxcore) # default components
endif()

pkg_check_modules(_PKG_TOX QUIET libtoxcore)
set(LIBTOX_DEFINITIONS ${_PKG_TOX_CFLAGS_OTHER})

find_path(LIBTOX_INCLUDE_DIR tox/tox.h HINTS
${_PKG_TOX_INCLUDEDIR}
${_PKG_TOX_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/libs/windows-x64/include
)

# required components
foreach(_COMPNENT ${_TOX_COMPNENTS})
find_library(_TEMP NAMES ${_COMPNENT} HINTS
${_PKG_TOX_LIBDIR}
${_PKG_TOX_LIBRARY_DIRS}
${CMAKE_SOURCE_DIR}/libs/windows-x64/lib
)
list(APPEND LIBTOX_LIBRARIES ${_TEMP})
unset(_TEMP CACHE)
endforeach()

include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set LIBTOX_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args(
libtox
DEFAULT_MSG
LIBTOX_LIBRARIES
LIBTOX_INCLUDE_DIR
)

mark_as_advanced(_TOX_COMPNENTS _PKG_TOX LIBTOX_INCLUDE_DIR)

set(LIBTOX_INCLUDE_DIRS ${LIBTOX_INCLUDE_DIR})
set(LIBTOX_LIBRARY_DIRS ${_PKG_TOX_LIBRARY_DIRS})
set(LIBTOX_LIBRARY_DIR ${_PKG_TOX_LIBDIR})

unset(_TOX_COMPNENTS)
unset(_COMPNENT)
unset(_PKG_TOX)
unset(_TEMP)
40 changes: 40 additions & 0 deletions cmake/macOS.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# These variables are needed to generate the Info.plist
set(EXECUTABLE_NAME utox)
set(APPLE_ICON utox.icns)
set(APPLE_MENU MainMenu)
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.6)

# Xcode needs these to find libs
include_directories(/usr/local/include)
link_directories(/usr/local/lib)

# Make apple icon
add_custom_command(OUTPUT ${APPLE_ICON}
COMMAND iconutil --convert icns ${uTox_SOURCE_DIR}/src/cocoa/utox.iconset -o ${APPLE_ICON}
DEPENDS ${uTox_SOURCE_DIR}/src/cocoa/utox.iconset
)

# Make apple menu
add_custom_command(OUTPUT ${APPLE_MENU}.nib
COMMAND ibtool --errors --warnings --notices --output-format human-readable-text
--compile ${APPLE_MENU}.nib ${uTox_SOURCE_DIR}/src/cocoa/MainMenu.xib
DEPENDS ${uTox_SOURCE_DIR}/src/cocoa/MainMenu.xib
)

# Copy files
set_source_files_properties(${APPLE_ICON} ${APPLE_MENU}.nib PROPERTIES
MACOSX_PACKAGE_LOCATION "Resources")

set(APPLE_FILES
${APPLE_ICON}
${APPLE_MENU}.nib
)

if(UTOX_STATIC OR TOXCORE_STATIC)
set(CMAKE_FIND_LIBRARY_SUFFIXES .a .dylib)
endif()

# create DMG
set(CPACK_GENERATOR "DragNDrop")
set(CPACK_PACKAGE_FILE_NAME "uTox ${PROJECT_VERSION}")

Loading

0 comments on commit e6d2d53

Please sign in to comment.