[Cmake] How do you get Cmake to work with MinGW?

Eric Wing ewing2121 at yahoo.com
Thu, 15 Jan 2004 08:43:10 -0800 (PST)


I'm guessing that MAME uses /bin/sh though I don't
know for sure. MAME seems to be using an older version
of MinGW and I can't get the current version of MinGW
to work with it. But as far as I can figure out, they
didn't make their own modifications to the tools so
the differences are a result of changes in MinGW.

I've enclosed the root level "makefile" for MAME and
"windows.mak" which seems to be the most interesting
of the makefile dependencies. They do have a variable
in "windows.mak" called CURPATH where the comments
mention quirks in /bin/sh.

I also tried your nmake solution. It didn't work for
me. (I currently don't have nmake on this machine.)
And when I tried to force Cmake to change my project
from Unix Makefile to Nmake, Cmake kept reverting back
to Unix Makefile when I hit Configure. When I tried
creating a new project based on Nmake, CMake could not
get past the simple compile test.


In makefile:
# set this to mame, mess or the destination you want
to build
# TARGET = mame
# TARGET = mess
# TARGET = neomame
# TARGET = cpmame
# TARGET = mmsnd
# example for a tiny compile
# TARGET = tiny
ifeq ($(TARGET),)
TARGET = mame
endif

# uncomment next line to include the debugger
# DEBUG = 1

# uncomment next line to include the symbols for
symify
# SYMBOLS = 1

# uncomment next line to generate a link map for
exception handling in windows
# MAP = 1

# uncomment next line to use Assembler 68000 engine
X86_ASM_68000 = 1

# uncomment next line to use Assembler 68020 engine
# X86_ASM_68020 = 1

# uncomment next line to use cygwin compiler
# COMPILESYSTEM_CYGWIN	= 1


# set this the operating system you're building for
# MAMEOS = msdos
# MAMEOS = windows
ifeq ($(MAMEOS),)
MAMEOS = windows
endif

# extension for executables
EXE = .exe

# CPU core include paths
VPATH=src $(wildcard src/cpu/*)

# compiler, linker and utilities
AR =  at ar
CC =  at gcc
LD =  at gcc
#ASM =  at nasm
ASM =  at nasmw
ASMFLAGS = -f coff
MD = -mkdir
RM =  at rm -f
#PERL =  at perl -w


ifeq ($(MAMEOS),msdos)
PREFIX = d
else
PREFIX =
endif

ifdef DEBUG
NAME = $(PREFIX)$(TARGET)$(SUFFIX)d
else
ifdef K6
NAME = $(PREFIX)$(TARGET)$(SUFFIX)k6
ARCH = -march=k6
else
ifdef I686
NAME = $(PREFIX)$(TARGET)$(SUFFIX)pp
ARCH = -march=pentiumpro
else
NAME = $(PREFIX)$(TARGET)$(SUFFIX)
ARCH = -march=pentium
endif
endif
endif

# build the targets in different object dirs, since
mess changes
# some structures and thus they can't be linked
against each other.
OBJ = obj/$(NAME)

EMULATOR = $(NAME)$(EXE)

DEFS = -DX86_ASM -DLSB_FIRST -DINLINE="static
__inline__" -Dasm=__asm__

ifdef SYMBOLS
CFLAGS = -Isrc -Isrc/includes -Isrc/$(MAMEOS)
-I$(OBJ)/cpu/m68000 -Isrc/cpu/m68000 \
	-O0 -Wall -Werror -Wno-unused -g
else
CFLAGS = -Isrc -Isrc/includes -Isrc/$(MAMEOS)
-I$(OBJ)/cpu/m68000 -Isrc/cpu/m68000 \
	-DNDEBUG \
	$(ARCH) -O3 -fomit-frame-pointer -fstrict-aliasing \
	-Werror -Wall -Wno-sign-compare -Wunused \
	-Wpointer-arith -Wbad-function-cast -Wcast-align
-Waggregate-return \
	-Wshadow -Wstrict-prototypes -Wundef \
#	try with gcc 3.0 -Wpadded -Wunreachable-code
-Wdisabled-optimization
#	-W had to remove because of the "missing
initializer" warning
#	-Wlarger-than-262144  \
#	-Wcast-qual \
#	-Wwrite-strings \
#	-Wconversion \
#	-Wmissing-prototypes \
#	-Wmissing-declarations
endif

CFLAGSPEDANTIC = $(CFLAGS) -pedantic

ifdef SYMBOLS
LDFLAGS =
else
#LDFLAGS = -s -Wl,--warn-common
LDFLAGS = -s
endif

ifdef MAP
MAPFLAGS = -Wl,-M >$(NAME).map
else
MAPFLAGS =
endif

# platform .mak files will want to add to this
LIBS = -lz

OBJDIRS = obj $(OBJ) $(OBJ)/cpu $(OBJ)/sound
$(OBJ)/$(MAMEOS) \
	$(OBJ)/drivers $(OBJ)/machine $(OBJ)/vidhrdw
$(OBJ)/sndhrdw
ifdef MESS
OBJDIRS += $(OBJ)/mess $(OBJ)/mess/systems
$(OBJ)/mess/machine \
	$(OBJ)/mess/vidhrdw $(OBJ)/mess/sndhrdw
$(OBJ)/mess/tools
endif

ifeq ($(TARGET),mmsnd)
OBJDIRS	+= $(OBJ)/mmsnd $(OBJ)/mmsnd/machine
$(OBJ)/mmsnd/drivers $(OBJ)/mmsnd/sndhrdw
endif

all:	maketree $(EMULATOR) extra

# include the various .mak files
include src/core.mak
include src/$(TARGET).mak
include src/rules.mak
include src/$(MAMEOS)/$(MAMEOS).mak

ifdef DEBUG
DBGDEFS = -DMAME_DEBUG
else
DBGDEFS =
DBGOBJS =
endif

ifdef COMPILESYSTEM_CYGWIN
CFLAGS	+= -mno-cygwin
LDFLAGS	+= -mno-cygwin
endif

extra:	$(TOOLS) $(TEXTS)

# combine the various definitions to one
CDEFS = $(DEFS) $(COREDEFS) $(CPUDEFS) $(SOUNDDEFS)
$(ASMDEFS) $(DBGDEFS)

# primary target
$(EMULATOR): $(OBJS) $(COREOBJS) $(OSOBJS) $(DRVLIBS)
# always recompile the version string
	$(CC) $(CDEFS) $(CFLAGS) -c src/version.c -o
$(OBJ)/version.o
	 at echo Linking $ at ...
	$(LD) $(LDFLAGS) $(OBJS) $(COREOBJS) $(OSOBJS)
$(LIBS) $(DRVLIBS) -o $ at  $(MAPFLAGS)
ifndef DEBUG
	upx -9 $(EMULATOR)
endif

romcmp$(EXE): $(OBJ)/romcmp.o $(OBJ)/unzip.o
	 at echo Linking $ at ...
	$(LD) $(LDFLAGS) $^ -lz -o $ at 

hdcomp$(EXE): $(OBJ)/hdcomp.o $(OBJ)/harddisk.o
$(OBJ)/md5.o
	 at echo Linking $ at ...
	$(LD) $(LDFLAGS) $^ -lz -o $ at 

ifdef PERL
$(OBJ)/cpuintrf.o: src/cpuintrf.c rules.mak
	$(PERL) src/makelist.pl
	 at echo Compiling $<...
	$(CC) $(CDEFS) $(CFLAGSPEDANTIC) -c $< -o $ at 
endif

# for Windows at least, we can't compile OS-specific
code with -pedantic
$(OBJ)/$(MAMEOS)/%.o: src/$(MAMEOS)/%.c
	 at echo Compiling $<...
	$(CC) $(CDEFS) $(CFLAGS) -c $< -o $ at 

$(OBJ)/%.o: src/%.c
	 at echo Compiling $<...
	$(CC) $(CDEFS) $(CFLAGSPEDANTIC) -c $< -o $ at 

# compile generated C files for the 68000 emulator
$(M68000_GENERATED_OBJS):
$(OBJ)/cpu/m68000/m68kmake$(EXE)
	 at echo Compiling $(subst .o,.c,$ at )...
	$(CC) $(CDEFS) $(CFLAGSPEDANTIC) -c $*.c -o $ at 

# additional rule, because m68kcpu.c includes the
generated m68kops.h :-/
$(OBJ)/cpu/m68000/m68kcpu.o:
$(OBJ)/cpu/m68000/m68kmake$(EXE)

# generate C source files for the 68000 emulator
$(OBJ)/cpu/m68000/m68kmake$(EXE):
src/cpu/m68000/m68kmake.c
	 at echo M68K make $<...
	$(CC) $(CDEFS) $(CFLAGSPEDANTIC) -DDOS -o
$(OBJ)/cpu/m68000/m68kmake$(EXE) $<
	 at echo Generating M68K source files...
	$(OBJ)/cpu/m68000/m68kmake$(EXE) $(OBJ)/cpu/m68000
src/cpu/m68000/m68k_in.c

# generate asm source files for the 68000/68020
emulators
$(OBJ)/cpu/m68000/68000.asm:  src/cpu/m68000/make68k.c
	 at echo Compiling $<...
	$(CC) $(CDEFS) $(CFLAGSPEDANTIC) -O0 -DDOS -o
$(OBJ)/cpu/m68000/make68k$(EXE) $<
	 at echo Generating $ at ...
	 at $(OBJ)/cpu/m68000/make68k$(EXE) $ at 
$(OBJ)/cpu/m68000/68000tab.asm 00

$(OBJ)/cpu/m68000/68020.asm:  src/cpu/m68000/make68k.c
	 at echo Compiling $<...
	$(CC) $(CDEFS) $(CFLAGSPEDANTIC) -O0 -DDOS -o
$(OBJ)/cpu/m68000/make68k$(EXE) $<
	 at echo Generating $ at ...
	 at $(OBJ)/cpu/m68000/make68k$(EXE) $ at 
$(OBJ)/cpu/m68000/68020tab.asm 20

# generated asm files for the 68000 emulator
$(OBJ)/cpu/m68000/68000.o: 
$(OBJ)/cpu/m68000/68000.asm
	 at echo Assembling $<...
	$(ASM) -o $ at  $(ASMFLAGS) $(subst -D,-d,$(ASMDEFS)) $<

$(OBJ)/cpu/m68000/68020.o: 
$(OBJ)/cpu/m68000/68020.asm
	 at echo Assembling $<...
	$(ASM) -o $ at  $(ASMFLAGS) $(subst -D,-d,$(ASMDEFS)) $<

$(OBJ)/%.a:
	 at echo Archiving $ at ...
	$(RM) $ at 
	$(AR) cr $ at  $^

makedir:
	 at echo make makedir is no longer necessary, just type
make

$(sort $(OBJDIRS)):
	$(MD) $ at 

maketree: $(sort $(OBJDIRS))

clean:
	 at echo Deleting object tree $(OBJ)...
	$(RM) -r $(OBJ)
	 at echo Deleting $(EMULATOR)...
	$(RM) $(EMULATOR)

clean68k:
	 at echo Deleting 68k files...
	$(RM) -r $(OBJ)/cpuintrf.o
	$(RM) -r $(OBJ)/drivers/cps2.o
	$(RM) -r $(OBJ)/cpu/m68000

In windows.mak
# only Windows specific output files and rules
# the first two targets generate the prefix.h header
# note this requires that OSOBJS be the first target
#
OSOBJS = $(OBJ)/windows/winmain.o
$(OBJ)/windows/fileio.o $(OBJ)/windows/config.o \
	 $(OBJ)/windows/ticker.o $(OBJ)/windows/fronthlp.o
$(OBJ)/windows/video.o \
	 $(OBJ)/windows/input.o $(OBJ)/windows/sound.o
$(OBJ)/windows/blit.o \
	 $(OBJ)/windows/snprintf.o $(OBJ)/windows/rc.o
$(OBJ)/windows/misc.o \
	 $(OBJ)/windows/window.o $(OBJ)/windows/winddraw.o
$(OBJ)/windows/asmblit.o \
	 $(OBJ)/windows/asmtile.o

# uncomment this line to enable guard pages on all
memory allocations
OSOBJS += $(OBJ)/windows/winalloc.o

# video blitting functions
$(OBJ)/windows/asmblit.o: src/windows/asmblit.asm
	 at echo Assembling $<...
	$(ASM) -o $ at  $(ASMFLAGS) $(subst -D,-d,$(ASMDEFS)) $<

# tilemap blitting functions
$(OBJ)/windows/asmtile.o: src/windows/asmtile.asm
	 at echo Assembling $<...
	$(ASM) -o $ at  $(ASMFLAGS) $(subst -D,-d,$(ASMDEFS)) $<

# add our prefix files to the mix
CFLAGS += -mwindows -include src/$(MAMEOS)/winprefix.h

# add the windows libaries
LIBS += -luser32 -lgdi32 -lddraw -ldsound -ldinput
-ldxguid -lwinmm

# due to quirks of using /bin/sh, we need to
explicitly specify the current path
CURPATH = ./

# if building with a UI, set the C flags and include
the ui.mak
ifneq ($(WINUI),)
CFLAGS+= -DWINUI=1
include src/ui/ui.mak
endif


--- "William A. Hoffman" <billlist at nycap.rr.com>
wrote:
> OK, I just checked, and the makefiles have this in
> them:
> SHELL = /bin/sh.
> 
> There are if statements in that use shell commands
> in the makefiles.
> I am not sure if there is a way around this.   All
> makes use
> a shell to run commands.  nmake uses cmd.com and
> gnumake uses
> /bin/sh.   The makefiles generated by cmake are
> complicated enough
> that we require the use of an if command that is not
> part of make itself.
> What shell is used by MAME's makefiles?
> 
> You could try using nmake with gcc from mingw as the
> compiler.
> If you set CXX to c++.exe and CC to gcc.exe then run
> CMakeSetup
> it should use them.  I am not sure if they will be
> able to understand
> the paths used, but you could try.
> 
> 
> -Bill
> At 08:51 AM 1/15/2004, Eric Wing wrote:
> >Interesting...but it's not working for me. gcc.exe
> and
> >mingw32-make.exe are in my path. But when the build
> >starts, I get an error...something about an
> >exclamation mark which I don't understand. Below is
> my
> >dos shell output.
> 


__________________________________
Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
http://hotjobs.sweepstakes.yahoo.com/signingbonus