(c) make-resursive compile

Suppose I have directories such as:

dir1
    main.cpp
    dir2
        abc.cpp
    dir3
        def.cpp
        dir4
            ghi.cpp
            jkl.cpp

And suppose that main.cpp includes dir2 / abc.cpp and dir3 / def.cpp, def.cpp includes dir4 / ghi.cpp and dir4 / jkl.cpp.

My question is: how can I do one Makefile / CMakeLists.txt in dir1 /, which recursively goes to each directory and compiles * .cpp and then "joins" them?

Sorry for my English, I hope I explained my question well!

Thanks!

+3
source share
3 answers

For a makefile, dir1 / Makefile should:

  • declare that main.o depends on dir2 / abc.o and dir3 / def.o
  • , dir2/abc.o dir3/def.o

cmake, "" ( dir2/abc.o dir3/def.o), .

+1

CMakeLists.txt:

file(GLOB_RECURSE MAIN_SOURCES "dir1/*.cpp")

add_executable(MainExecutable ${MAIN_SOURCES})
# or
add_library(MyLibrary ${MAIN_SOURCES})

, "" . , .

+1

, make . . .

0

Source: https://habr.com/ru/post/1723614/


All Articles