Skip to content

Support for MSVC 2013 -- Take 2#190

Merged
thp merged 19 commits into
thp:masterfrom
rovarma:vs2013
Jan 8, 2016
Merged

Support for MSVC 2013 -- Take 2#190
thp merged 19 commits into
thp:masterfrom
rovarma:vs2013

Conversation

@rovarma
Copy link
Copy Markdown
Contributor

@rovarma rovarma commented Dec 26, 2015

I needed VS2013 support, but noticed that the pull request for it (#182) is in a bit of a limbo state. As @cboulay suggested in the comments, I took his original changes and finished them; the credit for the CMake work goes to him.

I've further extended his CMake changes and fixed some code which, as far as I can tell, never should have compiled/worked in the first place (?).

With this, the VS2013 solution is correctly generated and all projects now build without warnings or errors (I have not tested the bindings because I don't know how).

Note: I've tried to keep all my cmake changes in IF(MSVC), so it shouldn't affect other platforms/compilers, but I don't have a linux or osx system to test on, so I can't be sure.

cboulay and others added 19 commits July 13, 2015 22:56
…oved OpenCV searching/installing, instead rely on cmake find_package. Tested in Windows Mingw64-32 bit, Ubuntu local and system OpenCV, OSX local and system OpenCV.
… Also

switched libusb to a submodule. Note that the MSVC build currently does
not work with OpenCV3 whereas all other builds do.
…event mismatches in debug/release CRT libraries in applications linking to libusb

- /W4 instead of /Wall (/Wall in msvc is not equivalent to -Wall in gcc)
- Support for msvc solution folders
- Set cmake project
… using the PS3EyeDriver was inside the PSMOVE_USE_PSEYE block, which seems to be used for capturing through opencv
- Disabled some unimportant (spammy) warnings
…d in the generated VS2013 solution

- Fixed some warnings in cmaera_control_win32.c
- When using the PS3EyeDriver, camera control settings are no longer saved/restore from the registry
- Added SDL2 support (FindSDL2.cmake) to examples/CMakeLists.txt
- OpenGL examples now build again. Most of the work done by cboulay (psmoveservice@348c1d2). I simply took the relevant changes and modified them a bit (FindSDL2 finds both debug & release versions of the libs so there is no mismatching of debug/release CRT going on + post-build command copy correct debug/release version of SDL2.dll)
- Fixed bug in test_opengl2 (particles were incorrectly removed from the particles list)
- Suppressed some more warnings
…h PSMoveAPI instead of relying on OpenCV camera capture support
…busb and ps3eyedriver) still have warnings, but I don't know how to get changes to files in submodules back to GitHub.
- Enabled debug information for all configurations on msvc, not just Debug
- Fixed some incorrect code when building Release. Code inside assert(...) is compiled out in release, causing things like setsockopt not to be called, which is probably wrong. Moved critical code inside asserts outside of the assert and assert on the result value instead.
@thp
Copy link
Copy Markdown
Owner

thp commented Dec 30, 2015

Thanks for the work; that's a big change. I could start by cherry-picking some changes and then review the rest? There are nearly 40.000 lines removed and only 1.300 added; is this intended?

@cboulay
Copy link
Copy Markdown
Contributor

cboulay commented Dec 30, 2015

@thp , the reason for the almost 40k lines removed is that the libusb source has been removed and replaced with a submodule. A large chunk of the added 1.3k lines is adding pthreads-w32 to external.

If you deem it necessary, it might be possible for @rovarma to first do the libusb replacement (and corresponding changes to the build system) as a separate pull request (A), then do the pthreads addition by itself as another (B, based on A), and finally this PR (C, based on B). Then you can more easily browse the detailed changes to psmoveapi after you've merged B (> A).

One problem with this is that 'B' will be pointless without the changes in C so you'll have to merge B on faith that C is forthcoming.

@rovarma
Copy link
Copy Markdown
Contributor Author

rovarma commented Dec 30, 2015

@cboulay already explained what the reason is for the removal of 40k lines, but to summarize what's changed at a high level:

  • LibUSB has been removed from the repository and has been added as a submodule (this is where most of the 40k lines removed comes from)
  • The CMake files have been split up into multiple files per directory. This is where some of both the removal and addition of new lines comes from. Actually, now that I'm browsing the other pull requests, I think this is probably the same change as described here: Separated CMakeLists into self-contained files in subdirectories. #180
  • MSVC13 compiles with warning level 4. This led to a lot of warnings, which I've fixed. Most of these warnings were of type "C4244: conversion from 'type1' to 'type2', possible loss of data". The fixes for these just entailed adding lots of explicit casts all over the place.
  • SDL2 has been added as a submodule
  • pthreads-w32 has been added to the repository. I've been looking at the reason for that and I don't think it's actually neccessary; it's a bit of a heavy-weight dependency for something that's not used much in the code. It should be possible to remove it and just use Win32 threading primitives directly (probably with some platform wrapper around it) in the few places that need it. If you prefer to keep this PR as small as possible, I can probably remove pthreads altogether and add it to this PR (or do that in a separate PR)
  • getopt.c and unistd.c have been added to (I believe) support some linux-specific functionality on Win32. Like pthreads, I believe we can probably do without them as well.

Altogether, if you disregard the removal of libusb and addition of pthreads, this is actually a surprisingly small change. I can imagine though that it's a bit hard for you to review in its current form; I'm open to redoing this in a way that makes it easier for you.

I could do the thing @cboulay suggested (issueing seperate pull requests), but I'd need someone to walk me through how to do that; I'm a complete Git(Hub) noob.

@cboulay
Copy link
Copy Markdown
Contributor

cboulay commented Dec 30, 2015

You're absolutely right that pthreads-w32 is not needed. I actually don't have it in my fork's master anymore. But getting rid of pthreads-w32 means lots of little changes to the code that makes it a bit harder to evaluate. Same with getopt.c and unistd.c. That's why my simpler_msvc branch has pthreads-w32 still. Getting rid of pthreads was to be the next step after the first attempt was merged.

I haven't tested it exactly, but your git flow would look something like the following (please backup the directory before attempting this):

  1. git checkout master
  2. git checkout -b pristine_upstream
  3. git remote add upstream https://github.com/thp/psmoveapi.git
  4. git fetch upstream
  5. git reset --hard upstream/master # Now your pristine_upstream branch is in the same state as thp/master
  6. git checkout -b libusb_submodule
  7. Do the libusb submodule changes.
  8. git checkout -b win32_posix
  9. Do the changes so you can use posix-like functions in win32. Whether this is adding libraries or creating platform-dependent wrappers is up to you.
  10. Depending on the order of your commits in your vs2013 branch, this next step may be really easy using rebase, or it may be really hard.
    • You can try using rebase
      • git checkout vs2013
      • git checkout -b vs2013_b
      • git rebase win32_posix
      • Hopefully you will have very few conflicts to deal with.
    • If using rebase gives you many conflicts, it's probably easier to just do the changes manually.
      • git checkout win32_posix
      • git branch -D vs2013_b
      • git checkout -b vs2013_b
      • Do the remaining changes.
  11. git checkout vs2013
  12. git reset --hard vs2013_b
  13. git push -f # This overwrites the vs2013 branch remotely, and also will update this pull request.
  14. git branch -d vs2013_b # Delete vs2013_b locally
  15. git push --all -u # Pushes the remaining new branches to the remote.
  16. Go to github and create pull requests from each of the new branches.

When thp views the pull requests, the libusb_submodule PR will have only the changes in that branch, the win32_posix will have the libusb_submodule changes AND the changes from its branch, and the last PR will have all the changes. Viewing the vs2013 PR will be like viewing the present PR, unless he first merges the previous PRs or he uses github URL trickery to compare the vs2013 PR against (e.g.) the win32_posix PR.

@nitsch
Copy link
Copy Markdown
Collaborator

nitsch commented Dec 30, 2015

If you deem it necessary, it might be possible for @rovarma to first
do the libusb replacement (and corresponding changes to the build
system) as a separate pull request (A), then do the pthreads addition
by itself as another (B, based on A), and finally this PR (C, based
on B). Then you can more easily browse the detailed changes to
psmoveapi after you've merged B (> A).

BTW, since this exact same problem with submodules comes up from time to
time, we might consider solving this by either using git subtrees
instead of submodules or by handling the dependencies in the build
configuration step instead (using CMake's external projects for
instance). I actually planned to use the latter approach for a locally
built OpenCV, but never found the time to actually do it.

@rovarma
Copy link
Copy Markdown
Contributor Author

rovarma commented Dec 31, 2015

@cboulay Thanks for the detailed instructions. It seems like quite a bit of work (having to redo the changes in different branches, basically). I'll leave it up to @thp if he wants me to do that or not.

@nitsch Actually, one of the changes @cboulay has made as part of the CMake refactor is that OpenCV can now be a locally built version. I believe it first searches for a version in /external/ and if it can't find it there, use the system version.

@nitsch
Copy link
Copy Markdown
Collaborator

nitsch commented Dec 31, 2015

@nitsch Actually, one of the changes @cboulay has made as part of the
CMake refactor is that OpenCV can now be a locally built version. I
believe it first searches for a version in /external/ and if it
can't find it there, use the system version.

The option for a locally built OpenCV was part of the build system
already. This feature is not new and also not what I meant. I was only
talking about a way to implement it differently using Git and CMake.

@rovarma
Copy link
Copy Markdown
Contributor Author

rovarma commented Jan 2, 2016

@nitch Okay -- I misunderstood what you meant then.
@cboulay Regarding OpenCV -- In the msvc readme you mention that on Windows, PSMoveAPI only works with OpenCV 2.4. What were the problems you were seeing with using OpenCV 3.0? I haven't tried using 3.0 myself (yet), but it would be nice if we could solve those issues and use the same OpenCV version for all platforms.

@cboulay
Copy link
Copy Markdown
Contributor

cboulay commented Jan 2, 2016

@rovarma , Honestly, I can't remember. And that was at a time when OpenCV3 was still in beta. It might work now. You'll probably have to make some changes, especially in the cmake files, but it may work now.

@rovarma
Copy link
Copy Markdown
Contributor Author

rovarma commented Jan 4, 2016

@cboulay Okay. I tested OpenCV 3.0 and while it builds & links fine (no changes needed to the CMake files), it crashes when running test_tracker in cvGetSize during psmove_tracker_blinking_calibration.

Looking at the disassembly, it appears that incorrect code is generated for cvGetSize (it's reading the argument to cvGetSize from the wrong register, causing it to basically work with a garbage pointer). This is probably due to some disagreement between PSMoveAPI and OpenCV 3.0 about what the memory layout of CvSize is, causing caller and callee not to match up during code gen.

I haven't tracked it down exactly yet, but it should be relatively straightforward to find and fix. It's not a high priority for me right now, but I might have a look at it over the weekend.

@thp Any news on how you want to proceed with this PR?

@thp thp mentioned this pull request Jan 8, 2016
@thp
Copy link
Copy Markdown
Owner

thp commented Jan 8, 2016

Reviewing this one right now

@thp thp merged commit c963664 into thp:master Jan 8, 2016
@rovarma rovarma deleted the vs2013 branch February 16, 2016 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants