Newbie questions about building OpenMW on a Mac

Everything about development and the OpenMW source code.
User avatar
Thunderforge
Posts: 503
Joined: 06 Jun 2017, 05:57

Newbie questions about building OpenMW on a Mac

Post by Thunderforge »

So I'm finally going to attempt to build OpenMW on a Mac. The thing is, I have never worked with C++ before (but plenty of Java and Python experience), and I'm having a hard time figuring out how to build it.

I started by looking at the macOS section of the Development Environment Setup page on our wiki. This was clear enough; I installed Xcode 8 from the App Store (and I think the command line tools got installed with it?). I then installed homebrew and used it to install cmake and pkg-config. Next I installed Qt, but chose to do it through the package on the Qt website.

All of that went well, but I was having trouble going from there. I launched Xcode and clicked "Check out an existing project". I pasted the Git URL into the text field, then was prompted with branches (I chose master). Then it prompted me to save it and I selected a location. After it finished downloading, the folder opened in the Finder. I clicked the "Finish" button in Xcode, but then I wasn't prompted with any screens. I tried going to File -> Open, but was told that" Xcode does not support opening folders without a project or workspace."

I'm kind of stuck at this point and am not sure what to do. Does anyone know what more I need to do to set up and build OpenMW in Xcode?
Last edited by Thunderforge on 08 Jul 2017, 00:49, edited 1 time in total.
Naugrim
Posts: 172
Joined: 08 Jan 2016, 01:32
Location: Spain

Re: How do I set up and build the project with Xcode?

Post by Naugrim »

Thunderforge wrote: 29 Jun 2017, 00:41 So I'm finally going to attempt to build OpenMW on a Mac. The thing is, I have never worked with C++ before (but plenty of Java and Python experience), and I'm having a hard time figuring out how to build it.
Seeing your description matches mine I feel obligated to give it a try and help. I work with Java and I've been doing some c++ stuff lately, mainly, small file parsing programs and compiling OpenTES on Windows. Havn't tried on Mac though, but seems pretty straight forward.

I think the problem is you're trying to use Xcode as IDE, but the instructions in the site are solely command line instructions for compiling the project. The whole compile process is done using good-old 'make' command, it's a very similar tool to Java Ant.
So, following the instructions in the shell should be fine to get the final binary.
A couple things that can help you:
1. cmake is a 'make' generation tool. It will look for env variables to set up and create the final make files you need for the compilation. Unless you change libraries, paths, or delete the `build` directory, you only need to run it once. Also, you can use a graphical version if you have problems using it in the command line https://cmake.org/download/. It will highlight any problem with env vars not found and allow you to set them manually. For example, I am not sure the $PATH_TO_DEPENDENCIES_DIR;$PATH_TO_QT_INSTALLATION vars that appear in the wiki as set by Homebrew.
2. Patience. We Java ppl have forgotten about lots of small details related to building real binaries :P

For IDE I'be been using "Eclipse for C/C++" or even IntelliJ (when using the C++ gradle plugin) but still compiling/testing using `make` on the shell. I really wish CLion had a community edition :/ I find that there are not many good C/C++ IDEs for someone that needs a free alternative to work on projects from time to time.
User avatar
psi29a
Posts: 5356
Joined: 29 Sep 2011, 10:13
Location: Belgium
Gitlab profile: https://gitlab.com/psi29a/
Contact:

Re: How do I set up and build the project with Xcode?

Post by psi29a »

It seems that the IDE of choice for OpenMW devs has been:
QTCreator
Clion
Eclipse

There have been those that have used Code::Blocks and XCode as well.

For XCode, you'll need to run cmake with -G to generate XCode xompatible project files.

Code: Select all

mkdir build
cd build
cmake -G Xcode ../openmw
Then point XCode to that build directory.
User avatar
damiel
Posts: 34
Joined: 16 Apr 2016, 11:46

Re: How do I set up and build the project with Xcode?

Post by damiel »

I would like to add that kdevelop also works perfectly fine for openmw development :)
User avatar
Thunderforge
Posts: 503
Joined: 06 Jun 2017, 05:57

Re: How do I set up and build the project with Xcode?

Post by Thunderforge »

psi29a wrote: 29 Jun 2017, 08:03 It seems that the IDE of choice for OpenMW devs has been:
QTCreator
Clion
Eclipse

There have been those that have used Code::Blocks and XCode as well.
I wouldn't mind trying Clion (Intellij IDEA is my primary Java IDE), but I'm not sure I'm ready to pay for it. I may try Eclipse if I can't get Xcode to work out.
psi29a wrote: 29 Jun 2017, 08:03 For XCode, you'll need to run cmake with -G to generate XCode xompatible project files.

Code: Select all

mkdir build
cd build
cmake -G Xcode ../openmw
Then point XCode to that build directory.
I tried this and I get the following error:

Code: Select all

-- Using Qt4
CMake Error at /usr/local/Cellar/cmake/3.8.2/share/cmake/Modules/FindQt4.cmake:1318 (message):
  Found unsuitable Qt version "" from NOTFOUND, this code requires Qt 4.x
Call Stack (most recent call first):
  CMakeLists.txt:136 (find_package)
This is despite me installing the Qt 5.1.1 package as described in the development setup. Is there something extra I have to do?
User avatar
psi29a
Posts: 5356
Joined: 29 Sep 2011, 10:13
Location: Belgium
Gitlab profile: https://gitlab.com/psi29a/
Contact:

Re: How do I set up and build the project with Xcode?

Post by psi29a »

Try adding: -D DESIRED_QT_VERSION=5

Code: Select all

mkdir build
cd build
cmake -G Xcode -D DESIRED_QT_VERSION=5 ../openmw
There are other options as well that might help for XCode, you'll have to google around a bit.

We default to Qt4 because Qt5 has a bug with OpenGL context being used within Qt, but this is related to OpenMW-CS and not to the launcher or openmw itself.
User avatar
Thunderforge
Posts: 503
Joined: 06 Jun 2017, 05:57

Re: How do I set up and build the project with Xcode?

Post by Thunderforge »

psi29a wrote: 30 Jun 2017, 08:19 Try adding: -D DESIRED_QT_VERSION=5
That resulted in this:

Code: Select all

-- Configuring OpenMW...
-- Using Qt5
CMake Error at CMakeLists.txt:138 (find_package):
  By not providing "FindQt5Widgets.cmake" in CMAKE_MODULE_PATH this project
  has asked CMake to find a package configuration file provided by
  "Qt5Widgets", but CMake did not find one.

  Could not find a package configuration file provided by "Qt5Widgets" with
  any of the following names:

    Qt5WidgetsConfig.cmake
    qt5widgets-config.cmake

  Add the installation prefix of "Qt5Widgets" to CMAKE_PREFIX_PATH or set
  "Qt5Widgets_DIR" to a directory containing one of the above files.  If
  "Qt5Widgets" provides a separate development package or SDK, be sure it has
  been installed.
I tried running

Code: Select all

export Qt5Widgets_DIR=/Users/Will/Qt5.5.1
But that didn't solve the problem.
User avatar
psi29a
Posts: 5356
Joined: 29 Sep 2011, 10:13
Location: Belgium
Gitlab profile: https://gitlab.com/psi29a/
Contact:

Re: How do I set up and build the project with Xcode?

Post by psi29a »

Have you tried running our OSX scripts from /CI directory? We use these to setup what we need to build an OpenMW on macOS on Travis-CI.
User avatar
Thunderforge
Posts: 503
Joined: 06 Jun 2017, 05:57

Re: How do I set up and build the project with Xcode?

Post by Thunderforge »

psi29a wrote: 30 Jun 2017, 15:10 Have you tried running our OSX scripts from /CI directory? We use these to setup what we need to build an OpenMW on macOS on Travis-CI.
I tried running before_install.osx.sh followed by before_script.osx.sh, but it didn't make a difference unfortunately. I also tried uninstalling the packaged version of Qt and ran "brew install [email protected]" as described in the instructions, but it didn't make a difference.

I'm open to any new ideas with Xcode. I also tried switching to Eclipse (and created a new thread based on questions I had with getting that to work).
User avatar
psi29a
Posts: 5356
Joined: 29 Sep 2011, 10:13
Location: Belgium
Gitlab profile: https://gitlab.com/psi29a/
Contact:

Re: How do I set up and build the project with Xcode?

Post by psi29a »

I don't believe the problem is with your IDE, it is that CMake can't find your Qt installation.
Post Reply