Search code examples
makefilecmakeqmake

Creating automated makefile to build two targets


It's been a while that I've been looking for this, I need a tool to automatically create a makefile for my project I've seen qmake and cmake, the problem is that I have two targets (Client and server) they both use a common library (which I wrote) and I want it to create two targets for me, cmake and qmake don't do this ty


Solution

  • set(servers_srcs
        server.cpp
        foo.cpp
        bar.cpp
    )
    
    set(client_srcs
        client.cpp
        xyz.cpp
        abc.cpp
    )
    set(library_srcs
        lib.cpp
    )
    
    add_library(library ${library_srcs})
    add_executable(client ${client_srcs})
    target_link_libraries(client library)
    target_link_libraries(server library)
    

    This automatically creates your Makefile, with three targets: client server and library.