Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

WIP: Allow building with visual studio #5347

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sphaerophoria
Copy link
Contributor

@sphaerophoria sphaerophoria commented Sep 21, 2018

PR for building qTox with MSVC.

I wanted to develop a piece of windows software in a windows IDE. Here are the changes that were needed :).

Ran sanity tests on the following

  • Adding friend
  • Chat with friend
  • Audio call with friend (libopus working)
  • Video call with friend (libvpx working)
  • QR code generated on about page
  • Image previews work

Along with the PR I'd like to put the following on the wiki (or in an md file somewhere)

Building qTox with visual studio

Disclaimer 1: This is from the perspective of a linux developer just trying to run software on thier windows PC. This may result in things being done in non-idiomadic ways. If there are "more windowsy" ways of doing this please edit this article.
Disclaimer 2: By the end of this process I was just happy that it worked. This means I was not willing to go back and do it again. This guide may be incomplete.

Prerequisites

  • Msys2/Cygwin. I got mine using chocolatey
  • Visual studio 2017 build tools
  1. Download and extract ffmpeg binaries from here
    • Get the dev version + the shared version. Later you will have to copy the ffmpeg dlls into the qtox build folder
    • Unzip the dev version to C:\ffmpeg
    • Do whatever you want with the shared verion, you will need them later
  2. Download and install Qt development packages. Install the MSVC variant to C:\Qt
  3. Create a qtox rootfs for finding libraries. This will simplify life later.
  4. Build zlib.
    • Download zlib source from here
    • In a command prompt do the following
      cd zlib
      mkdir build
      cd build
      cmake .. -DCMAKE_INSTALL_PREFIX=<qtox rootfs dir> -G"Visual Studio 15 2017 Win64"
      cmake --build . --config Release --target install
      
  5. Buid libpng
    • Get source from here
    • In a command prompt do the following
      cd libpng
      mkdir build
      cd build
      cmake .. -DCMAKE_INSTALL_PREFIX=<qtox rootfs dir> -G"Visual Studio 15 2017 Win64"
      cmake --build . --config Release --target install
      
  6. Build libqrencode
    • Get source from here
    • In a command promptdo the following
      cd qrencode
      mkdir build
      cd buid
      cmake .. -DCMAKE_INSTALL_PREFIX=<qtox rootfs dir> -DWITH_TOOLS=0 -G"Visual Studio 15 2017 Win64"
      cmake --build . --target install --config Release
      
    • Note that iconv isn't found. Im not sure if this is a problem but it seemed to build
  7. Get libsodium binaries
    • Download libsodium-<version>-msvc.zip from here
    • Copy "x64\Release\v141\static\libsodium.lib" to <qtox rootfs dir>\lib (assunming you are on x64)
    • Copy entire include dir to <qtox rootfs dir>\include
  8. Build sqlcipher
    • Get sqlcipher source from here
    • Download and install openssl. I used "Win64 OpenSSL v1.1.1" from here
    • Install a TCL shell environment. I used this after doing next to no research. Make sure tclsh is in your path
    • Open x64 Native Tools Command Prompt for VS 2017
      cd sqlcipher
      nmake /f Makefile.msc OPTS="-DSQLITE_HAS_CODEC=1 -I\"C:\Program Files\OpenSSL\include\"" LDOPTS="/LIBPATH:\"C:\Program Files\OpenSSL\lib\" libcrypto.lib" libsqlite3.lib
      
    • Copy sqlite3.h to <qtox root>\include
    • Copy libsqlite3.lib to <qtox root>\lib\libsqlcpher.lib
  9. Build libvpx
    • install yasm, I used choco install yasm
      • You can probably also install this inside msys2/cygwin
    • Build with MSYS2/Cygwin
      git clone https://github.com/webmproject/libvpx.git
      cd libvpx
      git checkout <desired version>
      ./configure --target=x86_64-win64-vs15
      make
      
      • Note if your working directory has a space in it you'll have to do the msys step somewhere else and move it
      • Retarget solution to windows 10
      • Right click and build the vpx project in release mode
      • I ran into issues with unresolved string.h, this is becasue I forgot to install the windows sdk with the visual studio 2017 build tools.
      • Copy x64/Release/libvpxmd.lib to <qtox root>\lib and vpx/*.h to lib/vpx.lib and include/vpx
  10. Get libopus
    • Get libopus source from here
    • open win32/VS2015/opus.sln and retarget
    • build x64 release
    • copy opus.lib to <qtox root>/lib
    • copy opus/include to <qtox root>/include/
  11. Get pthreads-win32
    • Get from here
    • Extract Pre-built.2/{include, lib} to <qtox-root>
    • Extract Pre-built.2/dll to <qtox-root>/bin
  12. Build toxcore
  13. Get OpenAL SDK and install redistributable from here

Build qTox itself

  1. Build qtox
    cmake .. -DCMAKE_INSTALL_PREFIX=<qtox-root> -DCMAKE_PREFIX_PATH="C:\Qt\5.11.1\msvc2017_64;C:\ffmpeg;C:\Program Files (x86)\OpenAL 1.1 SDK" -DCMAKE_LIBRARY_PATH="C:\Program Files (x86)\OpenAL 1.1 SDK\libs\Win64" -G"Visual Studio 15 2017 Win64" -DCMAKE_CXX_FLAGS="/D SODIUM_STATIC=1"
    
  2. Get QT dlls
     C:\Qt\5.11.1\msvc2017_64\bin\windeployqt.exe .
    
  3. Copy ffmpeg dlls from shared ffmpeg zip
  4. copy pthread dlls
  5. Copy libsodium dlls

This change is Reviewable

@sphaerophoria sphaerophoria force-pushed the qTox-msvc branch 12 times, most recently from 46e8844 to 93d5199 Compare September 21, 2018 08:59
@sudden6
Copy link
Member

sudden6 commented Sep 21, 2018

Great work, it will be really nice if qTox builds also natively under windows.

There seems to be an issue with finding OpenAL in our current windows builds though: https://travis-ci.org/qTox/qTox/jobs/431400408#L3519

@sudden6
Copy link
Member

sudden6 commented Sep 21, 2018

If you need a faster way than our CI to reproduce these errors you can use: https://github.com/qTox/qTox/tree/master/windows/cross-compile it's the same as executed on Travis CI.

@sphaerophoria sphaerophoria changed the title Allow building with visual studio WIP: Allow building with visual studio Sep 22, 2018
@sphaerophoria
Copy link
Contributor Author

sphaerophoria commented Sep 22, 2018

I think I'm going to put this on hold for now. I actually don't like builds that much but I thought I could quickly get something in that worked but it turns out it's not easy :(. If someone else wants to push this one through to the end feel free, but I'll probably come back to it after writing some actual code :)

Changes needed to build under MSVC compiler. Mostly buildsystem changes
with minor changes to source to deal with new header search systems with
cmake and cross-platform compat changes
@sudden6
Copy link
Member

sudden6 commented Sep 23, 2018

What do you think about breaking this up into two chunks to make it smaller?

One chunk would be all the changes in Dependencies.cmake and Findsodium.cmake which could be postponed and the other changes would be merged now?

@sphaerophoria
Copy link
Contributor Author

Thanks for understanding :).

Ill make sure the include changes work with pkgconfigs generated include paths but if so i think that makes a lot of sense

@ArkYk
Copy link

ArkYk commented Oct 24, 2018

@sphaerophoria Hello,Are your method is OK?I need build qTox by Visual studio 2017 nowhere else,but only here . can you help me?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants