Skip to content

Commit

Permalink
Improve cmake build for MSVC
Browse files Browse the repository at this point in the history
  • Loading branch information
sphaerophoria committed Sep 21, 2018
1 parent 2abc006 commit 602e602
Show file tree
Hide file tree
Showing 8 changed files with 624 additions and 58 deletions.
7 changes: 3 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ set(toxcore_SOURCES ${toxcore_SOURCES}
include(CheckFunctionExists)
check_function_exists(explicit_bzero HAVE_EXPLICIT_BZERO)
check_function_exists(memset_s HAVE_MEMSET_S)
set(toxcore_LINK_MODULES ${toxcore_LINK_MODULES} ${LIBSODIUM_LIBRARIES})
set(toxcore_LINK_MODULES ${toxcore_LINK_MODULES} sodium)
set(toxcore_PKGCONFIG_REQUIRES ${toxcore_PKGCONFIG_REQUIRES} libsodium)

# LAYER 2: Basic networking
Expand Down Expand Up @@ -275,7 +275,7 @@ if(BUILD_TOXAV)
toxav/toxav_old.c
toxav/video.c
toxav/video.h)
set(toxcore_LINK_MODULES ${toxcore_LINK_MODULES} ${OPUS_LIBRARIES} ${VPX_LIBRARIES})
set(toxcore_LINK_MODULES ${toxcore_LINK_MODULES} Opus::Opus Vpx::Vpx)
set(toxcore_PKGCONFIG_REQUIRES ${toxcore_PKGCONFIG_REQUIRES} opus vpx)

set(toxcore_API_HEADERS ${toxcore_API_HEADERS} ${toxcore_SOURCE_DIR}/toxav/toxav.h^toxav)
Expand Down Expand Up @@ -304,11 +304,10 @@ set(toxcore_API_HEADERS ${toxcore_API_HEADERS} ${toxcore_SOURCE_DIR}/toxencrypts
# any potential libvpx linking.
message("CMAKE_THREAD_LIBS_INIT: ${CMAKE_THREAD_LIBS_INIT}")
if(CMAKE_THREAD_LIBS_INIT)
set(toxcore_LINK_MODULES ${toxcore_LINK_MODULES} ${CMAKE_THREAD_LIBS_INIT})
set(toxcore_LINK_MODULES ${toxcore_LINK_MODULES} Threads::Threads)
set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} ${CMAKE_THREAD_LIBS_INIT})
endif()


if(NSL_LIBRARIES)
set(toxcore_LINK_MODULES ${toxcore_LINK_MODULES} ${NSL_LIBRARIES})
set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} -lnsl)
Expand Down
4 changes: 3 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ install:
- mkdir pthreads-win32 && cd pthreads-win32
- if not exist %APPDATA%\downloads\pthreads.zip curl -L ftp://sourceware.org/pub/pthreads-win32/pthreads-w32-2-9-1-release.zip -o %APPDATA%\downloads\pthreads.zip
- unzip %APPDATA%\downloads\pthreads.zip
- copy Pre-built.2\lib\x86\* Pre-built.2\lib\
- cd ../..

# TODO currently don't have prebuilt libraries for libvpx and libopus so we will just build with BUILD_TOXAV=OFF for now
before_build:
- cmake . -DBOOTSTRAP_DAEMON=OFF -DENABLE_SHARED=OFF -DBUILD_TOXAV=OFF
- cmake . -DBOOTSTRAP_DAEMON=OFF -DENABLE_SHARED=OFF -DBUILD_TOXAV=OFF -DCMAKE_PREFIX_PATH="third_party\pthreads-win32\Pre-built.2;third_party\libsodium"

build:
project: INSTALL.vcxproj
Expand Down
80 changes: 30 additions & 50 deletions cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,45 @@
###############################################################################

include(ModulePackage)
include(SimpleFindPackage)

if (MSVC)
set(THREADS_USE_PTHREADS_WIN32 1)
endif()

find_package(Threads REQUIRED)

if (MSVC)
set_property(TARGET Threads::Threads APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS "HAVE_STRUCT_TIMESPEC")
endif()

find_library(NSL_LIBRARIES nsl )
find_library(RT_LIBRARIES rt )
find_library(SOCKET_LIBRARIES socket )

# For toxcore.
pkg_use_module(LIBSODIUM libsodium )
# for toxcore

# Try to find both static and shared variants of sodium
set(sodium_USE_STATIC_LIBS ON)
find_package(sodium)
if (NOT sodium_FOUND)
set(sodium_USE_STATIC_LIBS OFF)
find_package(sodium REQUIRED)
endif()

# For toxav.
pkg_use_module(OPUS opus )
pkg_use_module(VPX vpx )
simple_find_package(Opus
INCLUDE_NAMES opus.h
PKGCFG_NAME opus
LIB_NAMES opus
PATH_SUFFIXES opus
)

simple_find_package(Vpx
PKGCFG_NAME vpx
INCLUDE_NAMES vpx_codec.h
PATH_SUFFIXES vpx
LIB_NAMES vpx vpxmd)

# For tox-bootstrapd.
pkg_use_module(LIBCONFIG libconfig )
Expand All @@ -29,49 +55,3 @@ pkg_use_module(MSGPACK msgpack )
pkg_use_module(OPENCV opencv )
pkg_use_module(PORTAUDIO portaudio-2.0)
pkg_use_module(SNDFILE sndfile )

###############################################################################
#
# :: For MSVC Windows builds.
#
# These require specific installation paths of dependencies:
# - libsodium in third-party/libsodium/Win32/Release/v140/dynamic
# - pthreads in third-party/pthreads-win32/Pre-built.2
#
###############################################################################

if(MSVC)
# libsodium
# ---------
find_library(LIBSODIUM_LIBRARIES
NAMES sodium libsodium
PATHS
"third_party/libsodium/Win32/Release/v140/dynamic"
"third_party/libsodium/x64/Release/v140/dynamic"
)
if(LIBSODIUM_LIBRARIES)
include_directories("third_party/libsodium/include")
set(LIBSODIUM_FOUND TRUE)
message("libsodium: ${LIBSODIUM_LIBRARIES}")
else()
message(FATAL_ERROR "libsodium libraries not found")
endif()

# pthreads
# --------
if(CMAKE_USE_WIN32_THREADS_INIT)
find_library(CMAKE_THREAD_LIBS_INIT
NAMES pthreadVC2
PATHS
"third_party/pthreads-win32/Pre-built.2/lib/x86"
"third_party/pthreads-win32/Pre-built.2/lib/x64"
)
if(CMAKE_THREAD_LIBS_INIT)
include_directories("third_party/pthreads-win32/Pre-built.2/include")
add_definitions(-DHAVE_STRUCT_TIMESPEC)
message("libpthreads: ${CMAKE_THREAD_LIBS_INIT}")
else()
message(FATAL_ERROR "libpthreads libraries not found")
endif()
endif()
endif()
Loading

0 comments on commit 602e602

Please sign in to comment.