Makefile到CMakeLists.txt

时间:2010-04-22 20:32:55

标签: makefile cmake

我在将附加的Makefile转换为等效的CMakeLists.txt时遇到了一些问题。

构建过程如下:

  • 使用flex为src / lexer.l.cpp生成src / lexer.cpp。
  • 使用bison为src / parser.y.cpp生成src / parser.cpp。
  • 将src /中的几乎任何内容编译成.so库。
  • 使用不同的标志重新编译它们以生成可执行文件。
  • 在stdlib /目录中编译三个源代码,输出二进制文件来构建/以便:

    STDLIB / STD /散列/ md5.cc

    会变成

    构建/ STD /散列/ md5.so

但我真的不知道如何使用cmake宏重现这个过程...任何帮助?

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 $@ $? 

1 个答案:

答案 0 :(得分:2)

对于flex / bison部分(警告:未经测试,我通常有.ypp和.lpp后缀用于解析器+词法分析器文件):

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})