tags:

views:

263

answers:

1

I have some problems converting the attached Makefile to an equivalent CMakeLists.txt .

The build process goes like that :

  • Generate src/lexer.cpp given src/lexer.l.cpp with flex.
  • Generate src/parser.cpp given src/parser.y.cpp with bison.
  • Compile almost anything inside src/ into a .so library.
  • Recompile them with different flags to generate an executable.
  • Compile sources inside stdlib/ directories three, output the binaries to build/ so that :

    stdlib/std/hashing/md5.cc

    Would become

    build/std/hashing/md5.so

But i really don't know how to reproduce this process with cmake macros ... any help ?

CXX=g++
WFLAGS= -w
OPTIMIZATION= -O3 -pipe -fomit-frame-pointer -ffast-math
CFLAGS= -Iinclude/ $(WFLAGS) $(OPTIMIZATION) 
LFLAGS= -ldl -lpcre -lpthread
LIBXML_CFLAGS= `xml2-config --cflags`
LIBXML_LFLAGS= `xml2-config --libs`
LIBFFI_CFLAGS= `pkg-config libffi --cflags`
LIBFFI_LFLAGS= `pkg-config libffi --libs`
STDLIB_LFLAGS= -ldl -lpcre -lcurl -lpthread $(LIBXML_LFLAGS) $(LIBFFI_LFLAGS) 
STDLIB_CFLAGS= $(WFLAGS) -L. -I./include/ $(OPTIMIZATION) -fPIC $(LIBXML_CFLAGS) $(LIBFFI_CFLAGS)  -lhybris -lc -shared
PREFIX=/usr
TARGET=hybris

LIBOBJ=src/context.lo \
       src/gc.lo \
       src/common.lo \
       src/engine.lo \
       src/node.lo \
       src/types.lo \
       src/types/binary.lo \
       src/types/char.lo \
       src/types/float.lo \
       src/types/integer.lo \
       src/types/map.lo \
       src/types/matrix.lo \
       src/types/string.lo \
       src/types/structure.lo \
       src/types/class.lo \
       src/types/vector.lo \
       src/hashtable.lo \
       src/vmem.lo \
       src/vcode.lo \
       src/parser.lo \
       src/lexer.lo

SOURCES=src/common.cpp \
        src/gc.cpp \
        src/lexer.cpp \
        src/context.cpp \
        src/hashtable.cpp \
        src/vmem.cpp \
        src/vcode.cpp \
        src/node.cpp \
        src/types.cpp \
        src/types/binary.cpp \
        src/types/char.cpp \
        src/types/float.cpp \
        src/types/integer.cpp \
        src/types/map.cpp \
        src/types/matrix.cpp \
        src/types/string.cpp \
        src/types/structure.cpp \
        src/types/class.cpp \
        src/types/vector.cpp \
        src/engine.cpp \
        src/parser.cpp

STDSRC=stdlib/std/hashing/md5.cc \
       stdlib/std/hashing/crc32.cc \
       stdlib/std/hashing/sha1.cc \
       stdlib/std/hashing/sha2.cc \
       stdlib/std/io/network/http.cc \
       stdlib/std/io/network/tcp.cc \
       stdlib/std/io/network/smtp.cc \
       stdlib/std/io/file.cc \
       stdlib/std/io/console.cc \
       stdlib/std/io/xml.cc \
       stdlib/std/type/reflection.cc \
       stdlib/std/type/string.cc \
       stdlib/std/type/matrix.cc \
       stdlib/std/type/array.cc \
       stdlib/std/type/map.cc \
       stdlib/std/type/type.cc \
       stdlib/std/type/binary.cc \
       stdlib/std/encoding.cc \
       stdlib/std/os/dll.cc \
       stdlib/std/os/time.cc \
       stdlib/std/os/threads.cc \
       stdlib/std/os/process.cc \
       stdlib/std/gc.cc \
       stdlib/std/pcre.cc \
       stdlib/std/math.cc

OBJECTS=$(SOURCES:.cpp=.o)
LOBJECTS=$(SOURCES:.cpp=.lo)
STDOBJ=$(patsubst stdlib%.cc,build%.so, $(STDSRC))

all: src/lexer.cpp src/parser.cpp lib hybris stdlib

lib: $(LOBJECTS)    
    $(CXX) -shared -Wl,-soname,libhybris.so.1 -o lib$(TARGET).so.1.0 $(LIBOBJ) 
    ln -sf lib$(TARGET).so.1.0 lib$(TARGET).so
    ln -sf lib$(TARGET).so.1.0 lib$(TARGET).so.1

hybris: $(OBJECTS)
    $(CXX) src/*.o src/types/*.o -o $(TARGET) $(CFLAGS) $(LFLAGS) 

stdlib: $(STDOBJ)

.cpp.o: 
    $(CXX) -c $< -o $@ $(CFLAGS) 

.cpp.lo:
    $(CXX) -c $< -o $@ $(CFLAGS) -fPIC 

build/%.so: stdlib/%.cc
    mkdir -p $(dir $@)
    $(CXX) $< -o $@ $(STDLIB_CFLAGS) $(STDLIB_LFLAGS) 

src/parser.cpp: src/parser.y.cpp
    bison -y -d -o $@ $?     

src/lexer.cpp: src/lexer.l.cpp
    flex -o $@ $? 
+2  A: 

For the flex/bison part (warning: untested, I usually have .ypp and .lpp suffixes for parser+lexer files):

cmake_minimum_required(VERSION 2.8)
set(SOURCES src/common.cpp src/gc.cpp src/lexer.cpp ...)

include(FindBISON)
include(FindFLEX)
bison_target(parser src/parser.y.cpp ${CMAKE_CURRENT_BINARY_DIR}/src/parser.cpp)
flex_target(lexer src/module/parametrierung/driverlexer.lpp ${CMAKE_CURRENT_BINARY_DIR}/driverlexer.cpp)
add_flex_bison_dependency(lexer parser)

add_library(libhybris SHARED ${BISON_parser_OUTPUTS} ${FLEX_lexer_OUTPUTS} ${SOURCES})
Rudi