workhorsy / SaltyNES

A NES emulator in WebAssembly
https://workhorsy.org/SaltyNES/
GNU General Public License v3.0
84 stars 6 forks source link

added CMake as a building tool #5

Closed DayBr3ak closed 6 years ago

DayBr3ak commented 6 years ago

The emsdk has been added as a git submodule and files are built with cmake adapted to emscripten.

To init the submodule ./init_web.sh

workhorsy commented 6 years ago

Nice. I'll have to test this tomorrow.

DayBr3ak commented 6 years ago

Thanks for your feedback. I have added your suggestions to the PR.

workhorsy commented 6 years ago

I've been testing the Emscripten version on a few different OSes(Ubuntu, Fedora, Debian) and it works fine.

The only problem is the make_desktop.sh version. It looks like there is some linking problem with SDL_GetKeyboardState:

Building debug version
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- system name: Linux, build: Debug
-- Configuring done
-- Generating done
-- Build files have been written to: /home/matt/Projects/SaltyNES_cmake/build_desktop_debug
Scanning dependencies of target SaltyNES
[  2%] Building CXX object CMakeFiles/SaltyNES.dir/src/InputHandler.cc.o
[  5%] Building CXX object CMakeFiles/SaltyNES.dir/src/Tile.cc.o
[  8%] Building CXX object CMakeFiles/SaltyNES.dir/src/ChannelTriangle.cc.o
[ 10%] Building CXX object CMakeFiles/SaltyNES.dir/src/sha256sum.cc.o
[ 13%] Building CXX object CMakeFiles/SaltyNES.dir/src/Misc.cc.o
[ 16%] Building CXX object CMakeFiles/SaltyNES.dir/src/Logger.cc.o
[ 18%] Building CXX object CMakeFiles/SaltyNES.dir/src/ByteBuffer.cc.o
[ 21%] Building CXX object CMakeFiles/SaltyNES.dir/src/Globals.cc.o
[ 24%] Building CXX object CMakeFiles/SaltyNES.dir/src/Raster.cc.o
[ 27%] Building CXX object CMakeFiles/SaltyNES.dir/src/SaltyNES.cc.o
[ 29%] Building CXX object CMakeFiles/SaltyNES.dir/src/ChannelSquare.cc.o
[ 32%] Building CXX object CMakeFiles/SaltyNES.dir/src/Mapper004.cc.o
[ 35%] Building CXX object CMakeFiles/SaltyNES.dir/src/Memory.cc.o
[ 37%] Building CXX object CMakeFiles/SaltyNES.dir/src/ChannelDM.cc.o
[ 40%] Building CXX object CMakeFiles/SaltyNES.dir/src/Parameters.cc.o
[ 43%] Building CXX object CMakeFiles/SaltyNES.dir/src/CpuInfo.cc.o
[ 45%] Building CXX object CMakeFiles/SaltyNES.dir/src/ChannelNoise.cc.o
[ 48%] Building CXX object CMakeFiles/SaltyNES.dir/src/PAPU.cc.o
[ 51%] Building CXX object CMakeFiles/SaltyNES.dir/src/ROM.cc.o
[ 54%] Building CXX object CMakeFiles/SaltyNES.dir/src/CPU.cc.o
[ 56%] Building CXX object CMakeFiles/SaltyNES.dir/src/Mapper003.cc.o
[ 59%] Building CXX object CMakeFiles/SaltyNES.dir/src/Mapper007.cc.o
[ 62%] Building CXX object CMakeFiles/SaltyNES.dir/src/NES.cc.o
[ 64%] Building CXX object CMakeFiles/SaltyNES.dir/src/base64.cc.o
[ 67%] Building CXX object CMakeFiles/SaltyNES.dir/src/MapperDefault.cc.o
[ 70%] Building CXX object CMakeFiles/SaltyNES.dir/src/NameTable.cc.o
[ 72%] Building CXX object CMakeFiles/SaltyNES.dir/src/PaletteTable.cc.o
[ 75%] Building CXX object CMakeFiles/SaltyNES.dir/src/main.cc.o
[ 78%] Building CXX object CMakeFiles/SaltyNES.dir/src/build_date.cc.o
[ 81%] Building CXX object CMakeFiles/SaltyNES.dir/src/Mapper011.cc.o
[ 83%] Building CXX object CMakeFiles/SaltyNES.dir/src/PPU.cc.o
[ 86%] Building CXX object CMakeFiles/SaltyNES.dir/src/Color.cc.o
[ 89%] Building CXX object CMakeFiles/SaltyNES.dir/src/Mapper018.cc.o
[ 91%] Building CXX object CMakeFiles/SaltyNES.dir/src/Mapper001.cc.o
[ 94%] Building CXX object CMakeFiles/SaltyNES.dir/src/Mapper002.cc.o
[ 97%] Building CXX object CMakeFiles/SaltyNES.dir/src/Mapper009.cc.o
[100%] Linking CXX executable ../SaltyNES
CMakeFiles/SaltyNES.dir/src/InputHandler.cc.o: In function `InputHandler::poll_for_key_events()':
InputHandler.cc:(.text+0xa7): undefined reference to `SDL_GetKeyboardState'
InputHandler.cc:(.text+0x261): undefined reference to `SDL_JoystickGetButton'
InputHandler.cc:(.text+0x2a2): undefined reference to `SDL_JoystickGetButton'
InputHandler.cc:(.text+0x2e0): undefined reference to `SDL_JoystickGetButton'
InputHandler.cc:(.text+0x321): undefined reference to `SDL_JoystickGetButton'
InputHandler.cc:(.text+0x361): undefined reference to `SDL_JoystickGetButton'
CMakeFiles/SaltyNES.dir/src/InputHandler.cc.o:InputHandler.cc:(.text+0x3a2): more undefined references to `SDL_JoystickGetButton' follow
CMakeFiles/SaltyNES.dir/src/InputHandler.cc.o: In function `InputHandler::poll_for_key_events()':
InputHandler.cc:(.text+0x47e): undefined reference to `SDL_JoystickGetAttached'
InputHandler.cc:(.text+0x49c): undefined reference to `SDL_JoystickGetButton'
InputHandler.cc:(.text+0x4dd): undefined reference to `SDL_JoystickGetButton'
InputHandler.cc:(.text+0x51b): undefined reference to `SDL_JoystickGetButton'
InputHandler.cc:(.text+0x55c): undefined reference to `SDL_JoystickGetButton'
InputHandler.cc:(.text+0x59c): undefined reference to `SDL_JoystickGetButton'
CMakeFiles/SaltyNES.dir/src/InputHandler.cc.o:InputHandler.cc:(.text+0x5dd): more undefined references to `SDL_JoystickGetButton' follow
CMakeFiles/SaltyNES.dir/src/PAPU.cc.o: In function `fill_audio_sdl_cb(void*, unsigned char*, int)':
PAPU.cc:(.text+0x16): undefined reference to `SDL_memset'
PAPU.cc:(.text+0x60): undefined reference to `SDL_MixAudio'
CMakeFiles/SaltyNES.dir/src/PAPU.cc.o: In function `PAPU::synchronized_start()':
PAPU.cc:(.text+0xc5): undefined reference to `SDL_PauseAudio'
CMakeFiles/SaltyNES.dir/src/PAPU.cc.o: In function `PAPU::stop()':
PAPU.cc:(.text+0x81a): undefined reference to `SDL_PauseAudio'
CMakeFiles/SaltyNES.dir/src/PAPU.cc.o: In function `PAPU::synchronized_setSampleRate(int, bool)':
PAPU.cc:(.text+0x93a): undefined reference to `SDL_PauseAudio'
PAPU.cc:(.text+0x95b): undefined reference to `SDL_PauseAudio'
CMakeFiles/SaltyNES.dir/src/PAPU.cc.o: In function `PAPU::synchronized_setStereo(bool, bool)':
PAPU.cc:(.text+0x136a): undefined reference to `SDL_PauseAudio'
CMakeFiles/SaltyNES.dir/src/PAPU.cc.o:PAPU.cc:(.text+0x138b): more undefined references to `SDL_PauseAudio' follow
CMakeFiles/SaltyNES.dir/src/PAPU.cc.o: In function `PAPU::Init(std::shared_ptr<NES>)':
PAPU.cc:(.text+0x29b7): undefined reference to `SDL_OpenAudio'
PAPU.cc:(.text+0x2d43): undefined reference to `SDL_GetError'
CMakeFiles/SaltyNES.dir/src/main.cc.o: In function `start_main_loop()':
main.cc:(.text+0xc11): undefined reference to `SDL_Quit'
CMakeFiles/SaltyNES.dir/src/main.cc.o: In function `main':
main.cc:(.text.startup+0xfb): undefined reference to `SDL_Init'
main.cc:(.text.startup+0x121): undefined reference to `SDL_CreateWindow'
main.cc:(.text.startup+0x143): undefined reference to `SDL_CreateRenderer'
main.cc:(.text.startup+0x16d): undefined reference to `SDL_CreateTexture'
main.cc:(.text.startup+0x1fa): undefined reference to `SDL_GetError'
main.cc:(.text.startup+0x245): undefined reference to `SDL_GetError'
main.cc:(.text.startup+0x254): undefined reference to `SDL_GetError'
main.cc:(.text.startup+0x263): undefined reference to `SDL_GetError'
CMakeFiles/SaltyNES.dir/src/PPU.cc.o: In function `PPU::startVBlank()':
PPU.cc:(.text+0xab31): undefined reference to `SDL_UpdateTexture'
PPU.cc:(.text+0xab3d): undefined reference to `SDL_RenderClear'
PPU.cc:(.text+0xab54): undefined reference to `SDL_RenderCopy'
PPU.cc:(.text+0xab60): undefined reference to `SDL_RenderPresent'
PPU.cc:(.text+0xae06): undefined reference to `SDL_PollEvent'
PPU.cc:(.text+0xae45): undefined reference to `SDL_PollEvent'
PPU.cc:(.text+0xaf7d): undefined reference to `SDL_JoystickClose'
PPU.cc:(.text+0xafc1): undefined reference to `SDL_JoystickOpen'
PPU.cc:(.text+0xb3e0): undefined reference to `SDL_Delay'
collect2: error: ld returned 1 exit status
CMakeFiles/SaltyNES.dir/build.make:1004: recipe for target '../SaltyNES' failed
make[2]: *** [../SaltyNES] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/SaltyNES.dir/all' failed
make[1]: *** [CMakeFiles/SaltyNES.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
DayBr3ak commented 6 years ago

It seems g++ can't find your SDL2 lib on linkage, can you do

pkg-config sdl2 --cflags --libs
pkg-config sdl2 --print-provides

and share the output here?

workhorsy commented 6 years ago
pkg-config sdl2 --cflags --libs
-D_REENTRANT -I/usr/include/SDL2 -lSDL2
pkg-config sdl2 --print-provides
sdl2 = 2.0.4
workhorsy commented 6 years ago

I figured out why it was failing to link on the desktop version. It was missing this at the end of the cmake file.

Instead of this:

add_executable(SaltyNES ${SOURCES})

Do this:

add_executable(SaltyNES ${SOURCES})
target_link_libraries(SaltyNES ${SDL2_LIBRARIES})

If you add that, then I can merge this.

DayBr3ak commented 6 years ago

Thank you for figuring it out, I added the change.

workhorsy commented 6 years ago

Thanks a lot.