Makefile 到 CMakeLists.txt

发布于 2024-08-30 02:55:00 字数 3739 浏览 3 评论 0原文

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

构建过程如下:

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

    stdlib/std/hashing/md5.cc

    会变成

    build/std/hashing/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 $@ $? 

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 
lt; -o $@ $(CFLAGS) 

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

build/%.so: stdlib/%.cc
    mkdir -p $(dir $@)
    $(CXX) 
lt; -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 $@ $? 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

药祭#氼 2024-09-06 02:55:00

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

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})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文