[CMake] Hi and some newbie questions

Goswin von Brederlow brederlo at informatik.uni-tuebingen.de
Thu Sep 13 16:47:33 EDT 2007


Hi everyone.

A friend of mine keeps cursing about autotools and suggests cmake
instead. So I looked into it for a small project. Like all newbies I
run into a lot of unknowns and I'm somewhat stuck now.

My CMakeLists.txt looks like below. My questions are in the comments.

----------------------------------------------------------------------
project (MOOSE)

# Building subdirectories recursively not done to mimik original
# Makefile, not because I don't know how.
#add_subdirectory (lib)

# How do I specify those more correctly? I need/want those flags and I
# probably want them for all or most subdirs.
ADD_DEFINITIONS(-fno-builtin -g -O2 -W -Wall -Werror -Wredundant-decls -Wno-format -Wstrict-prototypes -Wnested-externs -Wpointer-arith -Winline -D__XEN_INTERFACE_VERSION__=0x00030203 -m64 -mno-red-zone -fpic -fno-reorder-blocks -fno-asynchronous-unwind-tables -Wno-unused)

# Again, how do I specify those that I don't have to repeat it in subdirs?
include_directories (${MOOSE_SOURCE_DIR}/include)
include_directories (${MOOSE_SOURCE_DIR}/include/x86)

# How do I put the architecture there? I need x86_64 or i486 or fail.
include_directories (${MOOSE_SOURCE_DIR}/include/x86/x86_64)

add_library (minios STATIC events.c gnttab.c hypervisor.c kernel.c mm.c sched.c time.c lib/math.c lib/printf.c lib/string.c lib/xmalloc.c xenbus/xenbus.c console/console.c console/xencons_ring.c  arch/x86/mm.c arch/x86/sched.c arch/x86/setup.c arch/x86/traps.c)

# There would be multiple dirs here: lib, console, arch, ...
#link_directories (.)

# Now here is my first big problem. CMake doesn't know how to handle
# any of these:
#add_executable (mini-os.gz mini-os.elf x86_64.o)

# And it can't figure out that mini-os.elf is a normal elf binary just
# from the static library.
#target_link_libraries (mini-os.elf minios)

# How do I make a rule for assembler files? Doesn't seem to be preset.
ADD_CUSTOM_COMMAND (OUTPUT x86_64.o
                    COMMAND gcc -D__ASSEMBLY__ -Iinclude  -Iinclude/x86     -Iinclude/x86/x86_64 -c x86_64.S -o x86_64.o
                    COMMENT Assembler pass) 

# Or define my own linker script?
ADD_CUSTOM_COMMAND (OUTPUT mini-os.elf
                    COMMAND ld -N -T minios-x86_64.lds -m elf_x86_64 x86_64.o -L. -lminios -o mini-os.elf
                    DEPENDS x86_64.o minios
                    COMMENT Link kernel into shape)

# And a rule to gzip the result?
ADD_CUSTOM_COMMAND (OUTPUT mini-os.gz
                    COMMAND gzip -f -9 -c mini-os.elf >mini-os.gz
                    DEPENDS mini-os.elf
                    COMMENT compress kernel)

# And last why can't I add a custom command to the all target as in
#ADD_CUSTOM_TARGET (all DEPENDS mini-os.gz)
# or
#ADD_CUSTOM_COMMAND (TARGET all PRE_LINK COMMAND make mini-os.gz)

ADD_CUSTOM_TARGET (mini-os DEPENDS mini-os.gz)

----------------------------------------------------------------------

MfG
        Goswin


More information about the CMake mailing list