linleyh / liberation-circuit

Trapped in a hostile computer system, you must make a way out - RTS/coding game
GNU General Public License v3.0
382 stars 40 forks source link

CMake issues #8

Closed toofar closed 2 years ago

toofar commented 7 years ago

TL;DR: On linux install liballegro5-dev, go to src/, curl -LO https://github.com/apenwarr/redo/raw/master/minimal/do && chmod +x ./do && ./do then run g_game from where you unzipped the release archive to.

I'm on Linux Debian testing and I know nothing about cmake, nor do I want to know. Since you didn't actually provide any compilation instructions I did the old mkcd build && cmake .. and it complained about not being able to find allegro and math. I got as for as commenting out the previous allegro check stuff from CMakeLists.txt and replacing it with

find_package(PkgConfig)
pkg_check_modules (ALLEGRO allegro-5)
target_link_libraries(liberation-circuit ${ALLEGRO_LIBRARIES})
target_include_directories(liberation-circuit PUBLIC ${ALLEGRO_INCLUDE_DIRS})
target_compile_options(liberation-circuit PUBLIC ${ALLEGRO_CFLAGS_OTHER})

because the package liballegro5-dev includes pkg-config info that cmake can use. But it was still complaining about undefined references to al_* functions. Probably because it was only linking the main allegro file and not all the other ones (that package doesn't provide a monolithic build).

Then I looked in the source directory and saw the .do files. Once I rememered what they were from I just grabbed the redo/minimal/do shell script, ran that then ran g_game from where I unzipped the release to. So that was nice and easy but I wasted an embarresing amount of time googling cmake bullshit.

Also I am not getting any sound, but that seems to be the case with basic allegro sound test programs too. Probably choosing the wrong soundcard with alsa. Ah yup, running it and the aoss script from alsa-oss makes sound work.

Everything else I have tested (just clicking around the first level...) works fine!

linleyh commented 7 years ago

Your persistence is admirable! I don't know anything about cmake either; the cmake configuration is Kyle Finlay's contribution. Actually the one time a few years ago when I tried to use cmake to build something I had an experience a lot like yours; it was extremely painful.

Now, I just use Code::blocks to build the game, and I don't know much about how to build it in other environments (the .do files are a contribution from Nils Dagsson Moskopp). What kinds of compilation instructions would be useful here?

LeComm commented 7 years ago

For me, it's not the CMake that is the cancer here, but Allegro. I had first tried to hack link.txt to link in all the needed libs and when I was finished, it told me that there was a crisscross between those Allegro modules and Allegro itself, and that the modules included the Allegro library file, which conflicted with itself for other modules etc. Now I did the steps with those do/redo scripts and all I get is "Error: failed to initialize Allegro.". A shame I have to run the windows binary on wine now. At least it's still fast. But damn, such a great game.

ghost commented 7 years ago

All I had to do was to replace allegro_monolith with allegro in CMake/FindAllegro.cmake and run

mkdir build
cd build
cmake .. -DCMAKE_EXE_LINKER_FLAGS="-lallegro_image -lallegro_primitives -lallegro_color -lallegro_acodec -lallegro_audio -lallegro_dialog -lallegro_font -lallegro_main -lallegro -lm"
make

Here's the patch for FindAllegro.cmake (@linleyh probably shouldn't apply this to master, because it's dependent on system configuration and happens to work on Arch):

diff --git a/CMake/FindAllegro.cmake b/CMake/FindAllegro.cmake
index 1bdb99b..6fd3953 100644
--- a/CMake/FindAllegro.cmake
+++ b/CMake/FindAllegro.cmake
@@ -9,7 +9,7 @@ find_path (ALLEGRO_INCLUDE_DIR allegro.h
     $ENV {MINGDIR}/include)

 find_library (ALLEGRO_LIBRARY
-    NAMES allegro_monolith
+    NAMES allegro
     PATHS /usr/lib /usr/local/lib $ENV {MINGDIR}/lib)

 if (ALLEGRO_INCLUDE_DIR AND ALLEGRO_LIBRARY)
kennethdhau commented 7 years ago

I tried the diff (both using patch and manually) but neither worked. I ended up commenting out any reference to Allegro in CMakeLists.txt. Built fine with the compiler flags @bacondropped mentioned. Not exactly a great solution, but it was a functional dirty fix.

ericho commented 7 years ago

Hi

First of all, this is an awesome game, congratulations!!

I also had some problems with compilation and I end using the do script. However I created a docker image in case someone just wants to try the game.

To use it:

docker pull erichcm/liberation-circuit

And run:

docker run -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix --device /dev/dri --device /dev/snd:/dev/snd erichcm/liberation-circuit

You can find the source code here

I hope this can help :smile:

linleyh commented 7 years ago

Thanks! I'm not familiar with docker, but would it be useful for me to mention this in the readme.txt, or to include the source code in the /bin/misc directory?

ericho commented 7 years ago

The intention of the docker image is just to provide an easy way to take a quick look into the game without the pain of compilation for Linux users. However this image doesn't provide the full support of the game, the bin/ folder is stored in the docker image and is not persistent.

So, to answer the question, it might be useful for new users to take a quick look, but it doesn't have support to save progress or whatever task the game does on the bin/ folder.

I can send you a PR if you want to add the Dockerfile and instructions on how to use it 😃

linleyh commented 7 years ago

Ah, thanks for the explanation. Unfortunately the game will be quite limited without the ability to save - both the mission progress and also any process designs the player makes need to be saved.

akien-mga commented 7 years ago

For the reference, for users with a system-installed allegro with split codecs (i.e. not allegro_monolith), you should be able to build with this patch:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1660002..65bfbca 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,6 +2,8 @@
 project (liberation-circuit)
 cmake_minimum_required (VERSION 3.4)

+include(FindPkgConfig)
+
 # Set binary output directory
 set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")

@@ -18,12 +20,13 @@ if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_C_COMPILER_ID}" STREQUAL
 endif ()

 # Base library
-find_package (Allegro REQUIRED)
+#find_package (Allegro REQUIRED)
+pkg_check_modules(ALLEGRO allegro-5 REQUIRED)

 if (ALLEGRO_FOUND)

-    include_directories (${ALLEGRO_INCLUDE_DIR})
-    target_link_libraries (liberation-circuit ${ALLEGRO_LIBRARY})
+    include_directories (${ALLEGRO_INCLUDE_DIRS})
+    target_link_libraries (liberation-circuit ${ALLEGRO_LIBRARIES} m allegro_audio allegro_acodec allegro_font allegro_image allegro_primitives allegro_dialog)

 else ()
     message (FATAL_ERROR "Could not find Allegro")

It's not meant to be merged upstream of course, it's just a local hack. The proper fix would be to find (or write) a FindAllegro.cmake that can handle both types of distribution.

za-mi commented 7 years ago

about docker as mechanism for packaging, appimage or flatpack might be better approaches for end user apps.

See this game packagings for linux with appimage https://portablelinuxgames.org/ http://appimage.org/

oglinuk commented 2 years ago

I am wondering if it would be alright to submit a PR to clean up the build process for Linux as there are currently 3 ways. The Makefile and do script both build fine on Ubuntu 20.04, but I have not been able to get cmake to build, even when using the suggested CMAKE_EXE_LINKER_FLAGS above. Wanted to get thoughts on this first though.

linleyh commented 2 years ago

Sounds good to me. What kinds of changes do you have in mind?

oglinuk commented 2 years ago

Either updating CMakeLists.txt to work without needing to pass anything (unless I am just missing something and someone else has gotten cmake to work), and using it as the primary build process. Or remove it and just stick with the Makefile and do script.

linleyh commented 2 years ago

I've been told that cmake is too much for a small project like this, and I can't get it to work anyway. So I think makefile and do are probably the way to go.