Outpost Universe Forums

Projects & Development => Projects => OutpostHD => Topic started by: leeor_net on November 17, 2019, 10:47:39 PM

Title: Guide to Building from Source
Post by: leeor_net on November 17, 2019, 10:47:39 PM
I started putting together a guide for building OutpostHD from source: https://wiki.outpost2.net/doku.php?id=outposthd:building_from_source

Aside from what to do with NAS2D and the data assets, it should be pretty complete. Please let me know if you have any issues with the steps used in this guide.
Title: Re: Guide to Building from Source
Post by: Hooman on November 18, 2019, 01:55:23 PM
Instructions look clear so far.

When cloning the OPHD Git repository, is there an option somewhere to do a recursive clone? If so, that should automatically fetch the NAS2D library code as well. From the command line it is specified with --recursive. From a GUI (maybe TortoiseGit?) there was a checkbox for "recursive".
Title: Re: Guide to Building from Source
Post by: leeor_net on November 18, 2019, 07:43:49 PM
There is, I never really investigated what that option was. Through visual studio there is also a recursive option, I just don't remember exactly where.
Title: Re: Guide to Building from Source
Post by: Goof on November 23, 2019, 06:24:01 AM
Hi guys/girls

Just to add a Prerequisites for non english devs.
When you launch the command
Code: [Select]
vcpkg install glew:x86-windows glew:x64-windows physfs:x86-windows physfs:x64-windows
The tool warn about the missing english language package
Code: [Select]
Warning: The following VS instances are excluded because the English language pack is unavailable.
    C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
Please install the English language pack.

Add the english language to fix it and run the command again .

(https://forum.outpost2.net/index.php?action=dlattach;topic=6321.0;attach=1794;image)
Title: Re: Guide to Building from Source
Post by: Hooman on November 23, 2019, 07:47:33 PM
Huh, I wonder what causes that.

Thank you for the report.
Title: Re: Guide to Building from Source
Post by: leeor_net on February 09, 2020, 11:59:43 AM
I updated the Building From Source article on the wiki. Since we moved everything to using vcpkg for dependencies and have now included NAS2D as part of the OutpostHD solution it should be a lot easier to build.
Title: Re: Guide to Building from Source
Post by: Hooman on February 09, 2020, 01:18:56 PM
I was about to add a note about running the InstallVcpkgDeps.bat file to install the vcpkg dependencies, though I just remembered that's already done automatically now as part of the NAS2D build step.

Does the Git integration with Visual Studio do a recursive Git checkout by default? I'm uncertain if it will really fetch NAS2D by default, or if an extra step is needed there.
Title: Re: Guide to Building from Source
Post by: Goof on February 10, 2020, 01:26:10 AM
It seems to work as i only clone the OPHD repository and import the 2 projects.
Title: Re: Guide to Building from Source
Post by: Vagabond on February 10, 2020, 10:45:28 AM
Quote
Does the Git integration with Visual Studio do a recursive Git checkout by default? I'm uncertain if it will really fetch NAS2D by default, or if an extra step is needed there.

Hooman, I tested this out. When cloning the repository using Visual Studio's built in Git functions, it automatically pulled NAS2D. I could not compile OPHD out of the box because it was missing the SDL dependency. I assume this is because SDL is installed via vcpkg and I don't believe vcpkg dependencies are automatically downloaded like nuget packages, but I didn't look into it at all.

Glad to see work going into streamlining OPHD's build flow.

-Brett
Title: Re: Guide to Building from Source
Post by: leeor_net on February 10, 2020, 07:28:49 PM
I haven't looked at the batch file as I don't have vcpkg installed in the environment so calling vcpkg from the command line results in a "command not found" type of issue so I haven't paid any attention to it. In the build setup on the Wiki I have a guide to install vcpkg, integrate with Visual Studio and then issue the commands to download and build the dependencies.

I'm still annoyed that the ttf and mixer dependencies link against debug sdl2 in release mode, so waiting on a patch for that but I doubt that'll take too long, the vcpkg team seems really responsive to those kinds of issues.
Title: Re: Guide to Building from Source
Post by: The_Blight on April 21, 2020, 04:42:59 PM
I've built the OPHD project on Linux (Ubuntu 19.10). However, I did build this project also a long time ago, so some dependencies might already be on my system.
I do know I relied heavily on the Docker instructions (https://forum.outpost2.net/index.php/topic,6092.0.html) but ran them on my own machine and if it couldn't find something, I used a search engine to look for the missing apt package.

These are the steps I did to be able to build and run the "openhd.exe" (which probably shouldn't be named .exe on Linux  ;) ).

Code: [Select]
git clone https://github.com/OutpostUniverse/OPHD.git
cd OPHD
git submodule init
git submodule update
cd nas2d-core
make
cd ..
make
wget -4 https://www.outpost2.net/files/ophd/data.zip
unzip data.zip -d data
./openhd.exe

Had a lot of fun trying to play on a Mars like planet, died twice already though  ;D, and it's so reminiscient of the old days, only better!

(https://i.imgur.com/ZyMpLZD.png)
(https://i.imgur.com/QJybN3n.png)

Hope this helps someone!

Title: Re: Guide to Building from Source
Post by: Hooman on April 22, 2020, 01:12:40 AM
Oh hey, interesting to hear about your experiences. I'm glad you were able to get that built and running.


I would be curious to know if there is something we can do to make building the project easier, or more obvious. In particular, where did you spend most of your time getting it working?


At one point I did add makefile rules to install dependencies using apt, though it's buried in the NAS2D makefile, so probably not super obvious when trying to build OPHD. The two projects have the same set of dependencies. There's probably more we can do to streamline first time setup.
Title: Re: Guide to Building from Source
Post by: The_Blight on April 22, 2020, 11:49:14 AM
Hi Hooman,

Well the place I looked for build instructions initially was on the GitHub page, for an INSTALL.MD or a reference on the Wiki, but couldn't find any there.
Naively I tried to do "make" in the root directory but that didn't work.
After some Googling I found the link to the docker setup.
Even though I work with git on a professional basis, I didn't know git submodules were a thing, so it took some figuring out.
This gave me the clue that the nas2d probably was a dependency, and that I should build that first.
After that I was able to compile OPHD, and then was able to launch the executable, only to be greeted with an error regarding a missing asset.  :)
The data.zip is mentioned somewhere in the forum, but that too I had forgotten about.
The -4 flag in the wget command is so that it defaults to IPv4, as it seems to hang when I don't specify it.

I've now also got a debug build working in Eclipse (freshly downloaded 2020-03 version, c++ development edition):
- Import as Makefile Project (select the folder which contains the topmost makefile, this is usually the folder in which you checked out from git.)
- This should allow you to build the code based on the makefile (it will call the "all" targate by default)
- Should you require a debug build (handy if one wants to develop), we need to build our code with the debug information contained in it.
- To do so, edit the MakeFile, by adding the following target below the "all" target and its configuration:

Code: [Select]
.PHONY: debug
debug: DEPFLAGS += -g -O0
debug: $(EXE)

This appends some extra flags to the DEPFLAGS variable, the -g flag makes sure the debug info is added, and the -O0 (minus oh zero) flag makes sure no code optimizations when compiling are done so the debugger will still see everything as-is.

Save the makefile.

Then in Eclipse, in Project > Properties, select the C/C++ Build, and select the "Behavior" tab.
Here change the "Build (incremental build)" value from "all" to "debug".

Rebuild your code.

Set a breakpoint somewhere and launch the Debug configuration:



(https://i.imgur.com/slhYtHR.png)
Title: Re: Guide to Building from Source
Post by: Hooman on May 21, 2020, 09:38:37 PM
Sorry if this reply is a little slow coming.

I was thinking about adding a debug build target to the makefile, but then I realized this can be done with the already setup make variables:
Code: [Select]
make CXXFLAGS_EXTRA="-g -O0"

Additionally, you can change the build folder so the debug build intermediate files don't interfere with release builds. That way you can switch between build configurations without having to do a clean and full rebuild.
Code: [Select]
make CXXFLAGS_EXTRA="-g -O0" BUILDDIR=".build/debug/"

I was thinking about adding additional targets to set those variables, though I realized there can be quite a few targets for some projects. It's not so noticeable for OPHD itself, but for the NAS2D dependency, there are more build targets. In particular: all, test, check, test-graphics, run-test-graphics. It seemed to make less sense to create special targets for each of them. Mind you, that's basically what was done for the instructions to build the Docker images. Guess I haven't really made up my mind about which direction to go. It does seem more user friendly to have a build target name, rather than specify the details of the build flags.

Anyway, this kind of gets me thinking the Linux side of things could use a bit more support for build configurations.



Another thought I had was to detect when the submodule is missing, inform the user, and try to automatically initialize and download the git submodule. That should reduce the potential for confusing problems for a first time install.
Title: Re: Guide to Building from Source
Post by: Kyrros on May 27, 2020, 10:21:11 AM
Been a while since I've last looked at this project, also very glad you're doing better now!
Anywho, built a new personal/gaming rig awhile back, so I don't have Visual Studio (or VCC) installed since this is a recreational box and not a work box.

Had some trouble with the initial bootstrap-vcpkg.bat, seems it calls a sub .bat, bootstrap.ps1.bat and I kept getting thrown this...

"Could not detect a Windows SDK / TargetPlatformVersion"

here's the block where that exception comes from.

Code: [Select]
    # Selecting
    if ($withWinSDK -ne "")
    {
        foreach ($instance in $validInstances)
        {
            if ($instance -eq $withWinSDK)
            {
                return $instance
            }
        }

        throw "Could not find the requested Windows SDK version: $withWinSDK"
    }

    foreach ($instance in $validInstances)
    {
        if (!$DisableWin10SDK -and $instance -match "10.")
        {
            return $instance
        }

        if (!$DisableWin81SDK -and $instance -match "8.1")
        {
            return $instance
        }
    }

    throw "Could not detect a Windows SDK / TargetPlatformVersion"
}

Had to add an OS specific SDK (in my case, Win10) to get it to work, may want to make a note of that in the "to add" list as well on the VCPkg page (since it also adds an additional ~2.7GB to the VS install download)

(http://Windows10SDK_VS2019.png) SEE ATTACHED IMAGE

Also, VCPkg sends 'anonymous' usage metric data back to Microsoft, maybe make a note to suggest including -disableMetrics parameter with the intial bootstrap-vcpkg call at the users discretion.
Title: Re: Guide to Building from Source
Post by: Kyrros on May 27, 2020, 06:49:23 PM
Several build attempts later... heh.

So, VCPkg does not natively execute from VS2019, even after installation/integration, I had to add the VCPkg directory to my %PATH% manually before the build/rebuild would attempt to run correctly.

After resolving the 'vcpkg not found' error, I was able to run a proper build, but then it, too, failed for (finally) a legitimate reason.  NAS2D fails to build, so then when OPHD try, it, too, then fails due to reference errors.

VS2019 error
The command "..\Package.bat C:\Program Files (x86)\GAMES\Outpost HD\OPHD\x64\Debug\NAS2D.lib x64 Debug:VCEnd" exited with code 1.
 
Build output snippet
Code: [Select]
1>Compress-Archive : The path 'nas2d-1.5.0-1379-g2299b30-Windows.Files.(x86)\GAMES' either does not exist or is not a
1>valid file system path.
1>At line:1 char:1
1>+ Compress-Archive -Path 'NAS2D.lib', 'include/' -DestinationPath 'nas2 ...
1>+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1>    + CategoryInfo          : InvalidArgument: (nas2d-1.5.0-137...les.(x86)\GAMES:String) [Compress-Archive], InvalidO
1>   perationException
1>    + FullyQualifiedErrorId : ArchiveCmdletPathNotFound,Compress-Archive
1>
1>A duplicate file name exists, or the file
1>cannot be found.

The 'C:/Program Files (x86)/GAMES' reference looks like it's been truncated somehow (error'd to "nas2d-1.5.0-1379-g2299b30-Windows.Files.(x86)\GAMES").... I isolated the line from the referenced Package.bat file below


Code: [Select]
powershell -Command "Compress-Archive -Path 'NAS2D.lib', 'include/' -DestinationPath '%PackageName%' -Force"

... possible syntax error?
Title: Re: Guide to Building from Source
Post by: leeor_net on May 27, 2020, 07:55:12 PM
Could be, but you have it in Program Files which is a restricted set of directories in Windows 7+ -- Windows 10 enforces this even more strictly. Try building from a location outside of Program Files and see if you get any changes?

Thank you for your patience with this. I generally assume that anybody trying to build OutpostHD would already have Visual Studio 2019 installed.

Adding vcpkg to the environment path is something I need to add to the Wiki documentation -- it's a bit lacking since I originally wrote it and we've improved the build process considerably since I first started using vcpkg. This will help me improve documentation.
Title: Re: Guide to Building from Source
Post by: Kyrros on May 27, 2020, 09:26:31 PM
Oh yeah, I definitely remember the 'old' build days, haha.

I run VS in admin to avoid access error like that.  I moved to a different disk but the same path, same error, renamed to a simpler path, it works, turns out pathnames with spaces is what was causing the error. Now I'm finally just getting regular old code errors it seems.

Code: [Select]
D:\GAMES\OPHD\OPHD\PopulationPool.cpp(174,8): error C2039: 'string': is not a member of 'std'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\include\vector(24): message : see declaration of 'std'
D:\GAMES\OPHD\OPHD\PopulationPool.cpp(174,15): error C2065: 'string': undeclared identifier
D:\GAMES\OPHD\OPHD\PopulationPool.cpp(174,15): error C2146: syntax error: missing ';' before identifier '_popRole'
D:\GAMES\OPHD\OPHD\PopulationPool.cpp(174,15): error C2065: '_popRole': undeclared identifier
D:\GAMES\OPHD\OPHD\PopulationPool.cpp(177,44): error C2065: '_popRole': undeclared identifier
D:\GAMES\OPHD\OPHD\PopulationPool.cpp(178,46): error C2065: '_popRole': undeclared identifier
D:\GAMES\OPHD\OPHD\PopulationPool.cpp(179,46): error C2065: '_popRole': undeclared identifier
D:\GAMES\OPHD\OPHD\PopulationPool.cpp(183,14): error C2039: 'runtime_error': is not a member of 'std'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\include\vector(24): message : see declaration of 'std'
D:\GAMES\OPHD\OPHD\PopulationPool.cpp(183,98): error C2065: '_popRole': undeclared identifier
D:\GAMES\OPHD\OPHD\PopulationPool.cpp(183,27): error C3861: 'runtime_error': identifier not found

The rest of the .cpp's seem to do just fine.

Looks like someone forgot to add #include <string> and #include <stdexcept> statements before/after they were done with PopulationPool.cpp file. Thankfully an easy fix, assuming by the std:: that the standard library was indeed intended.

Edited the file on my end, and it compiled just fine.

Now it's some sort of on execution error with the .exe itself... not familiar with this one, though.

SEE ATTACHED IMAGE
Title: Re: Guide to Building from Source
Post by: leeor_net on May 27, 2020, 09:54:39 PM
That was going to be my next question. Might need to make judicious use of '"'s in the scripts.

You need the assets. https://www.outpost2.net/files/ophd/data.zip

Extract everything into 'data' in the project root folder (e.g., the one with the solution file).

Odd that the include file isn't included properly. Works on my machine, a virtual windows environment, a virtual mac environment, a virtual linux environment and live linux environment. /me shrugs Oh well, will look into it further another time.
Title: Re: Guide to Building from Source
Post by: Kyrros on May 28, 2020, 03:11:01 PM
I couldn't get the data folder to work until I put it into the resultant compiled/output folder with the exe.

Where would you like playthrough feedback posted? Post a new 'issue' on Git? Start a thread here?
Title: Re: Guide to Building from Source
Post by: leeor_net on May 30, 2020, 01:20:35 PM
Posting here is probably the best way to do it for now since the game is in heavy development. Open a new topic for issues you come across -- it's always helpful to get feedback from users! :D