.pro file which creates one .so per .cpp
-
I have a directory full of files (eg: dog.cpp, dog.h, cat.cpp, cat.h). I want to compile each of these into its own .so file (eg: dog.so, cat.so). My .pro file below compiles fine, but it puts all of the animal files into a single lib called libMYPROJ.so.1.0.0
How can I tell QMake to create one lib per source file? BTW, I want to be able to drop more .cpp files into the directory without having to update the .pro file (so not looking to add each manually to the .pro)
TEMPLATE = lib # Get a list of all the animal .cpp files in the libs directory ANIMAL_SOURCES = $$files(../src/cpp/*.cpp) message($$ANIMAL_SOURCES) # Create a library for each animal .cpp file for(FILE, ANIMAL_SOURCES) { # Extract the name of the animal from the file name ANIMAL = $$basename(FILE) # Create the library target for this animal LIBNAME = $${ANIMAL}.so # message($$replace(LIBNAME, animal, test)) $${ANIMAL}.target = $$LIBNAME $${ANIMAL}.sources = $$FILE # Add the library target to the list of targets SUBDIRS += $$ANIMAL # LIBS += -l$$ANIMAL } # Build each animal type library define_build_subdirs { for(dir, SUBDIRS) { message("Building $$dir") SUBDIR = $$dir include($$dir/$${SUBDIR}.pro) } } # Link the libraries to the main project LIBS += -L$$PWD -
By the time you are doing that level of QMake, you may just want to switch to using CMake. It's much better documented and more widely supported, so it's generally much easier to do unusual things with it.