Sitelet https://github.com/NetHack/NetHack/pull/1558
Skip to content

Add CMake for 5.0 - #1558

Closed
mark-z-r wants to merge 26 commits into
NetHack:NetHack-5.0from
mark-z-r:cmake
Closed

mark-z-r wants to merge 26 commits into
NetHack:NetHack-5.0from
mark-z-r:cmake

Conversation

@mark-z-r

@mark-z-r mark-z-r commented May 28, 2026 •

Copy link
Copy Markdown

commits from cmake 3.7 (scraped most, if not all, of the files from this)

  • CMakeLists.txt files from NetHack 3.6.6.
  • CMakeLists.txt for NetHack 3.7.
  • Specify lua build output
  • Add missing panic.c dependency to makedefs
  • Add libdl and libm dependencies
  • List sources without GLOB.

My commits

  • Basically entirely rewrote CMakeLists.txt
  • and more...

I thought i would use the 3.7 attempt as a starting point, but so much has changed
since then that I decided to start over

What the PR plans to cover:

  • buildable on chimera linux (this means llvm and musl)
  • UBSAN & ASAN (soft requirements for chimera linux packages)
  • most of the options detailed in sys/unix/README.hints, some of them might be dummy
    switches for now
    (no longer planned)
  • Only system vendored lua

I dont remeber why I decided to do this. (probably something to do with creating a chimera port)

I would like some confirmation that this pr will get accepted if it is up to snuff. or
in other words, I want to make sure that this PR will not get rejected just because CMake support
is unwanted

Heinrich Kuttler and others added 24 commits January 20, 2022 23:53
libm math functions are used by lua and NetHack and Lua both need to
link to libdl.a.
Updates to NetHack 3.7 CMakeLists.txt
Be able to carry out uplifts during minor release
lifetimes.

Document a way to be able to uplift struct content
without incrementing EDITLEVEL and breaking existing savefiles.
Use the mechanics outlined to uplift the contents instead, where
it is feasible to do so. The uplift is currently one-way only. An
uplifted savefile cannot be used with an earlier build of NetHack
, one built with a lower SAVEFILE_REVISION_LEVEL, than the one which
wrote the savefile.

The final byte (byte 79) of the 80 critical bytes in the savefile,
of which 10 are reserved for future expansion and not currently
used, will now be used for holding the savefile revision level
(SAVEFILE_REVISION_LEVEL in include/patchlevel.h) at the time
the savefile was written.

That leaves 9 of the bytes available for future use.
The directories and permissions portion of the linux.500 and macOS.500
hints files and their included files has been consolidated to
dirs-perms.500.

The builder can edit that one file now, to identify
the folders that will be utilised as part of the build.

Alternatively, you can set those folders and permissions in a
make.perms file in the top of the NetHack folder tree and
they should take precedence over the ones in dirs-perms.500
because dirs-perms.500 uses '?=' variable assignment, which
means "set the value of the variable if no value has been set."

* NOTE: BUILD CHANGE *

This also makes WANT_SOURCE_INSTALL=1 the default over
WANT_SHARED_INSTALL=1, if neither is explicitly set.
The new default is the safer and less-impacting default,
but it will change where things get installed over earlier
Makefile builds. You can be explicit with WANT_SHARED_INSTALL=1
in your make command to get that..

These are the differences between the two:

make WANT_SHARED_INSTALL=1    Place the results of the install/update portion
                              of the build into a shared area on a multiuser
                              system.

make WANT_SOURCE_INSTALL=1    Place the results of the install/update portion
                              of the build into a subfolder of the source
                              tree, rather than in a system-wide shared area.

Also note that the macOS hints file behaves slightly differntly depending
on whether WANT_SOURCE_INSTALL=1 was set versus letting it be the default.
That's not new, it behaved that way before.
It was using dupstr(), so strutil had to be added to the project.
There is no unintentional spelling mistake.
Close NetHack#1523
and split out the options into a seperate file
	modified:   CMakeLists.txt
	new file:   CMakeOptions.txt
the resultant binary don't work though
lots done, probably should have split this up into more commits...

important to note is that I changed report.c to not output a backtrace
if NO_BACKTRACE if defined. NO_BACKTRACE gets defined if `backtrace()` is
not defined.

still missing a lot of features that the makefiles have, but it is hard
dechipering the current build system...

	modified:   CMakeLists.txt
	modified:   CMakeOptions.txt
	new file:   src/CMakeLists.txt
	modified:   src/report.c
	new file:   sys/CMakeLists.txt
	modified:   util/CMakeLists.txt
	new file:   win/CMakeLists.txt
	new file:   win/curses/CMakeLists.txt
	new file:   win/tty/CMakeLists.txt
	modified:   CMakeOptions.txt
	modified:   src/CMakeLists.txt
	modified:   sys/CMakeLists.txt
	new file:   sys/share/CMakeLists.txt
just that. added some info on finding config values for cmake too
mark-z-r added 2 commits June 3, 2026 23:37
nethack can run now. requires manual setup of data dirs, but it runs!

next steps: data files (makedefs) and installs
@satmandu

Copy link
Copy Markdown

Thank you for this!

We're trying to get a proper build done and having CMake support makes everything better.

What's left to do with the data dirs?

satmandu added a commit to chromebrew/chromebrew that referenced this pull request Jun 30, 2026
Signed-off-by: Satadru Pramanik <satadru@gmail.com>
@satmandu

Copy link
Copy Markdown

I'm getting this error building from your branch:

/usr/local/tmp/packages/NetHack.git64e9cf847cf9ffef2dddf454608c1172553c8bb1.tar.zst: OK
Building from source, this may take a while...
Additional Cmake options being used:
cmake_build_relative_dir: .
cmake_options: -DCURSES_INCLUDE_PATH=/usr/local/include/ncursesw -DHACKDIR=/usr/local/var/lib/nethackdir
-- The C compiler identification is GNU 16.1.0
-- The CXX compiler identification is GNU 16.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/local/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/local/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Build type: Release.
-- Building NetHack version: 5.0.0.
-- Found Lua: /usr/local/lib64/liblua.so;/usr/local/lib64/libm.so (found suitable version "5.4.8", minimum required is "5.4")
-- Looking for backtrace
-- Looking for backtrace - found
-- Found Curses: /usr/local/lib64/libcurses.so
-- Configuring done (0.8s)
-- Generating done (0.0s)
CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_INSTALL_LIBDIR


-- Build files have been written to: /usr/local/tmp/crew/nethack5.20260630180914.dir/builddir
ninja: Entering directory `./builddir'
ninja: Jobserver mode detected:  -j8 --jobserver-auth=fifo:/usr/local/tmp/crew/nethack5.20260630180914.dir/jobserver_pool
[1/149] Building C object CMakeFiles/NetHack.dir/src/alloc.c.o
FAILED: [code=1] CMakeFiles/NetHack.dir/src/alloc.c.o
/usr/local/bin/cc -DHACKDIR=\"/usr/local/var/lib/nethackdir\" -DNETHACK_LUA_SUPPORT -DNetHack -DPUBLIC -DSYSCF -I/usr/local/tmp/crew/nethack5.20260630180914.dir/include -O3 -pipe -ffat-lto-objects -fPIC  -f
lto=auto -flto=auto -O3 -DNDEBUG -std=gnu99 -flto=auto -fno-fat-lto-objects -MD -MT CMakeFiles/NetHack.dir/src/alloc.c.o -MF CMakeFiles/NetHack.dir/src/alloc.c.o.d -o CMakeFiles/NetHack.dir/src/alloc.c.o -c
 /usr/local/tmp/crew/nethack5.20260630180914.dir/src/alloc.c
/usr/local/tmp/crew/nethack5.20260630180914.dir/src/alloc.c:13:10: fatal error: nhlua.h: No such file or directory
   13 | #include "nhlua.h"
      |          ^~~~~~~~~
compilation terminated.

Looks like the nhlua.h generation isn't working?

@satmandu

Copy link
Copy Markdown

I had to manually add a include/nhlua.h file to get past that error:

/* nhlua.h - generated file */
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
/*nhlua.h*/

@satmandu

Copy link
Copy Markdown

(That's done in the CMakeLists.txt in https://patch-diff.githubusercontent.com/raw/NetHack/NetHack/pull/662.diff )

@satmandu

Copy link
Copy Markdown

I also had to manually pass a -DCMAKE_C_FLAGS='-I#{CREW_PREFIX}/include/ncursesw' despite setting
-DCURSES_INCLUDE_PATH=#{CREW_PREFIX}/include/ncursesw since curses.h wasn't being found.

That lets me build successfully, however, I'm still missing an install target.

This is the build log from our Chromebrew build:

Additional Cmake options being used:
cmake_build_relative_dir: .
cmake_options: -DCURSES_INCLUDE_PATH=/usr/local/include/ncursesw -DHACKDIR=/usr/local/var/lib/nethackdir -DCMAKE_C_FLAGS='-I/usr/local/include/ncursesw'
-- The C compiler identification is GNU 16.1.0
-- The CXX compiler identification is GNU 16.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/local/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/local/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Build type: Release.
-- Building NetHack version: 5.0.0.
-- Found Lua: /usr/local/lib64/liblua.so;/usr/local/lib64/libm.so (found suitable version "5.4.8", minimum required is "5.4")
-- Looking for backtrace
-- Looking for backtrace - found
-- Found Curses: /usr/local/lib64/libcurses.so
-- Configuring done (0.6s)
-- Generating done (0.0s)
CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_INSTALL_LIBDIR


-- Build files have been written to: /usr/local/tmp/crew/nethack5.20260630185049.dir/builddir
ninja: Entering directory `./builddir'
ninja: Jobserver mode detected:  -j8 --jobserver-auth=fifo:/usr/local/tmp/crew/nethack5.20260630185049.dir/jobserver_pool
[74/149] Building C object CMakeFiles/NetHack.dir/src/nhlua.c.o
/usr/local/tmp/crew/nethack5.20260630185049.dir/src/nhlua.c: In function ‘nhl_error’:
/usr/local/tmp/crew/nethack5.20260630185049.dir/src/nhlua.c:218:1: warning: ‘noreturn’ function does return
  218 | }
      | ^
[149/149] Linking C executable NetHack
Preconfiguring package...
ninja: Entering directory `./builddir'
ninja: error: unknown target 'install', did you mean 'win/all'?
/usr/local/lib/crew/lib/package.rb:429:in 'Package.system': Command failed with exit 1: DESTDIR=/usr/local/tmp/crew/dest ninja -C ./builddir install
nethack5 failed to build: `CFLAGS="-O3 -pipe -ffat-lto-objects -fPIC -fuse-ld=mold  -flto=auto -flto=auto" CXXFLAGS="-O3 -pipe -ffat-lto-objects -fPIC -fuse-ld=mold  -flto=auto -flto=auto" FCFLAGS="-O3 -pipe -ffat-lto-objects -fPIC -fuse-ld=mold  -flto=auto -flto=auto" FFLAGS="-O3 -pipe -ffat-lto-objects -fPIC -fuse-ld=mold  -flto=auto -flto=auto" LDFLAGS="-flto=auto" CREW_PRELOAD_ENABLE_COMPILE_HACKS="1" CC_LD="mold" CXX_LD="mold" CREW_PRELOAD_NO_MOLD="0" DESTDIR=/usr/local/tmp/crew/dest ninja -C ./builddir install` exited with 1

What's the suggested build command? We tend to just use a default of DESTDIR=/usr/local/tmp/crew/dest ninja -C ./builddir install for all of our cmake builds before packaging.

satmandu added a commit to chromebrew/chromebrew that referenced this pull request Jun 30, 2026
Signed-off-by: Satadru Pramanik <satadru@gmail.com>
@mark-z-r

mark-z-r commented Jun 30, 2026 •

Copy link
Copy Markdown
Author

sorry for the slow updates! finals are over now, and I can get back to working on this, I may have some un-pushed commits, I'll check in around 6 hrs. I vaguely remember doing something with that file, although I don't remember what. UPDATE: looking at my last pushed commit, I am almost 100% sure I have un-pushed commits/edits

@mark-z-r

Copy link
Copy Markdown
Author

I also had to manually pass a -DCMAKE_C_FLAGS='-I#{CREW_PREFIX}/include/ncursesw' despite setting -DCURSES_INCLUDE_PATH=#{CREW_PREFIX}/include/ncursesw since curses.h wasn't being found.

That lets me build successfully, however, I'm still missing an install target.

This is the build log from our Chromebrew build:

Additional Cmake options being used:
cmake_build_relative_dir: .
cmake_options: -DCURSES_INCLUDE_PATH=/usr/local/include/ncursesw -DHACKDIR=/usr/local/var/lib/nethackdir -DCMAKE_C_FLAGS='-I/usr/local/include/ncursesw'
-- The C compiler identification is GNU 16.1.0
-- The CXX compiler identification is GNU 16.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/local/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/local/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Build type: Release.
-- Building NetHack version: 5.0.0.
-- Found Lua: /usr/local/lib64/liblua.so;/usr/local/lib64/libm.so (found suitable version "5.4.8", minimum required is "5.4")
-- Looking for backtrace
-- Looking for backtrace - found
-- Found Curses: /usr/local/lib64/libcurses.so
-- Configuring done (0.6s)
-- Generating done (0.0s)
CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_INSTALL_LIBDIR


-- Build files have been written to: /usr/local/tmp/crew/nethack5.20260630185049.dir/builddir
ninja: Entering directory `./builddir'
ninja: Jobserver mode detected:  -j8 --jobserver-auth=fifo:/usr/local/tmp/crew/nethack5.20260630185049.dir/jobserver_pool
[74/149] Building C object CMakeFiles/NetHack.dir/src/nhlua.c.o
/usr/local/tmp/crew/nethack5.20260630185049.dir/src/nhlua.c: In function ‘nhl_error’:
/usr/local/tmp/crew/nethack5.20260630185049.dir/src/nhlua.c:218:1: warning: ‘noreturn’ function does return
  218 | }
      | ^
[149/149] Linking C executable NetHack
Preconfiguring package...
ninja: Entering directory `./builddir'
ninja: error: unknown target 'install', did you mean 'win/all'?
/usr/local/lib/crew/lib/package.rb:429:in 'Package.system': Command failed with exit 1: DESTDIR=/usr/local/tmp/crew/dest ninja -C ./builddir install
nethack5 failed to build: `CFLAGS="-O3 -pipe -ffat-lto-objects -fPIC -fuse-ld=mold  -flto=auto -flto=auto" CXXFLAGS="-O3 -pipe -ffat-lto-objects -fPIC -fuse-ld=mold  -flto=auto -flto=auto" FCFLAGS="-O3 -pipe -ffat-lto-objects -fPIC -fuse-ld=mold  -flto=auto -flto=auto" FFLAGS="-O3 -pipe -ffat-lto-objects -fPIC -fuse-ld=mold  -flto=auto -flto=auto" LDFLAGS="-flto=auto" CREW_PRELOAD_ENABLE_COMPILE_HACKS="1" CC_LD="mold" CXX_LD="mold" CREW_PRELOAD_NO_MOLD="0" DESTDIR=/usr/local/tmp/crew/dest ninja -C ./builddir install` exited with 1

What's the suggested build command? We tend to just use a default of DESTDIR=/usr/local/tmp/crew/dest ninja -C ./builddir install for all of our cmake builds before packaging.

I believe I also ended up doing that, but can't remember, also, although the commits say I got it building, I had to do a lot of manual work to get it running

@mark-z-r

Copy link
Copy Markdown
Author

yes, there is not an install target yet, as although the main binary can compile, the other files necessary for the game are not yet handled.

satmandu added a commit to chromebrew/chromebrew that referenced this pull request Jul 1, 2026
Signed-off-by: Satadru Pramanik <satadru@gmail.com>
@mark-z-r

mark-z-r commented Jul 1, 2026 •

Copy link
Copy Markdown
Author

Okay, update, I've looked at the current state of things, and my biggest problem is the NETHACKDIR
I am unsure the purpose of this directory, and it by default living in /usr/games/lib is a problem
for me because:

  1. /usr is supposed to be owned solely by the package manager on chimera linux
    • excluding /usr/local
  2. /usr/games does not, and will not exist (q66 has decreed such)

Can u give me a rundown of directorys on chromebrew? I need to know what types of things I need to allow the user to specifiy

@satmandu

satmandu commented Jul 1, 2026

Copy link
Copy Markdown

We try to be fhs compliant, but also, due to our situation as an overlay for ChromeOS, all of our files are under /usr/local.

@satmandu

satmandu commented Jul 1, 2026

Copy link
Copy Markdown

Also, we are setting the nethackdir to {/usr/local}/var/lib/nethackdir, but just moving it under /var/lib might be sufficient as a reasonable default that doesn't violate the FHS rules that don't allow for a /usr/games/ dir...

@mark-z-r

mark-z-r commented Jul 1, 2026 •

Copy link
Copy Markdown
Author

Well, 1. Chimera Linux does not attempt to follow FHS, but our layout is similar, and 2. Anything in the /var directory is forbidden from being present in a package. This is because it is not meant to be persistent across boots

Ideally, the global record file would go in /etc/nethack, the read-only data would go in /usr/lib/nethack, and user specific data would go in the appropriate XDG_* directory

@satmandu

satmandu commented Jul 1, 2026

Copy link
Copy Markdown

As long as NETHACKDIR is available as a variable, or the NETHACKDIR defaults are sanely under PREFIX/lib in some manner, I don't have a problem with it. The NetHack maintainers may have thoughts on that though.

I've put my package update on hold at chromebrew/chromebrew#17217 until you have that and a cmake install ready to go.

Happy to test again if you want me to run this further through our automated build insfrastructure!

@mark-z-r mark-z-r closed this Jul 4, 2026
@mark-z-r

mark-z-r commented Jul 4, 2026

Copy link
Copy Markdown
Author

I am closing this pr because I did not know enough about the build system, so I probably broke the makefile build system
and because the git history is a mess. not saying I am going to abandon this, but I decided to just clean the slate and start again

@mark-z-r mark-z-r mentioned this pull request Jul 4, 2026
satmandu added a commit to chromebrew/chromebrew that referenced this pull request Jul 7, 2026
Signed-off-by: Satadru Pramanik <satadru@gmail.com>
@satmandu

satmandu commented Aug 7, 2026

Copy link
Copy Markdown

@mark-z-r Any further luck?

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.

5 participants