Migrating from make to cmake: how to use a wildcard build target

I am trying to convert makefile-build to cmake (to avoid the current state of forced maintenance of windows-build env based on make / msdev and linux based on make / gcc).

In this project, I found a directory full of source code files that are obtained based on the naming convention compiled into libraries. (e.g. c1223.c => c1223.dll (or .sl))

The current makefile consists of some directives using wildcards, for example:

LIB_NO  = $(basename $(subst s,,$@))

OBJ = $(OBJ_PATH)/s$(LIB_NO).o $(OBJ_PATH)/c$(LIB_NO).o\
          $(OBJ_PATH)/b$(LIB_NO).o

$(OBJ_PATH)/%.o : %.c
    -$(CC) $(CFLAGS) -I$(PWD) -c $< -o $@
    -(chmod a+w $@;true)

I searched for a while, but can't find anything like work. Is it even possible that cmake allows you to generate a pattern based on wildcards?

Any comments, tips and suggestions are welcome :)

amuses Marcus

+5
2

globbing ( , ).

file(GLOB TESTSRCS "test/src/*.cpp")

# Compile the test sources.
add_executable(Tests ${TESTSRCS})

target_link_libraries(Tests ${LIB} gtest gtest_main)

make , , . , cmake.

, , .

, - , c:

file(GLOB libfiles "path/to/libs/c*.c")

foreach(libfile ${libfiles})
    GET_FILENAME_COMPONENT(libname ${libfile} NAME) # remove the '.c' part (untested, hopefully this will work)
    add_library(${libname} ${libfile})
endforeach(libfile)

- , .

+3

CMake make , . , .

.o, . CMake , , CMake .

make , ?

, "add_library" , ?

0

All Articles