How to add all files in some sub-directory in qt project file.
for example, my source tree is:
src
app/
foo/
ui/
common/
Now I add all files like this
SOURCES += ./*.cpp \
./app/*.cpp \
./app/foo/*.cpp \
./ui/*.cpp \
./common/*.cpp
Is there any way to add all these files under src directory to SOURCES?
You have to use the files function:
SOURCES += $$files("*.cpp", true)
Related
Minimal example .zip
I'm trying to use SoLoud in my Qt project.
I managed to successfully compile & use it with this cmake file:
file(GLOB_RECURSE AUDIOSOURCE ${CMAKE_CURRENT_LIST_DIR}/SoLoud/src/audiosource/*.c*)
file(GLOB_RECURSE CORE ${CMAKE_CURRENT_LIST_DIR}/SoLoud/src/core/*.c*)
file(GLOB_RECURSE FILTER ${CMAKE_CURRENT_LIST_DIR}/SoLoud/src/filter/*.c*)
add_compile_definitions(WITH_MINIAUDIO)
set(SOLOUD_SRCS
SoLoud/src/backend/miniaudio/soloud_miniaudio.cpp
${CMAKE_CURRENT_LIST_DIR}/SoLoud/src/c_api/soloud_c.cpp
${AUDIOSOURCE}
${CORE}
${FILTER}
)
add_executable(output main.cpp ${SOLOUD_SRCS})
target_include_directories(output PUBLIC ${CMAKE_CURRENT_LIST_DIR}/SoLoud/include)
My main project is built with Qmake. So I'm trying to translate it...
INCLUDEPATH += SoLoud/include
DEFINES += "WITH_MINIAUDIO=\"\""
SOURCES += SoLoud/src/backend/miniaudio/soloud_miniaudio.cpp \
SoLoud/src/c_api/soloud_c.cpp \
$$files("SoLoud/src/audiosource/*.c*", true) \
$$files("SoLoud/src/core/*.c*", true) \
$$files("SoLoud/src/filter/*.c*", true)
HEADERS += $$files("SoLoud/include/*.h", true) \
This produces a wall of errors:
https://pastebin.com/pUQuysEr
Why?
BTW: i'm aware that recursive search of *.c* files is bad practice. However, that's what library's authors recommend and I gave up trying to find every single .cpp i need (there were MANY).
I modified my c++ Qt4 project to that all the sources are in an src directory. All the temporary file are stored in a build directory and the target file in a bin directory. Here a snapshot of my .pro file
SOURCES += src/*.cpp
HEADERS += src/*.h
FORMS += gui/myguy.ui
INCLUDEPATH += src/ # Source directory to be included
DESTDIR = bin # Target file directory
OBJECTS_DIR = build # Intermediate object files directory
MOC_DIR = build # Intermediate moc files directory
my problem is the following. When I build the application qt automatically transforms ui_mygui.h. This is by default stored on the root of the project. How can I specify the location where I want this file to be put?
Thanks
Use the UI_DIR variable. This is where those files will be generated.
I have a program that draws the Earth and it uses the following code to read the texture file:
Images::RGBImage surfaceImage;
surfaceImage=Images::readImageFile("",Vrui::openFile("/home/rodrtu/Desktop/SolarSystem/land_shallow_topo_2048.png"));`
The way I have it set up it only works on my desktop, but I want other people to have access to my program files and pictures, and be able to get the program working on their computer. What should I use instead of using "/home/rodrtu/Desktop/SolarSystem/land_shallow_topo_2048.png"
If I add a folder to the same place as my .cpp file, should I make changes to my makefile?
Here is my makefile
VRUI_MAKEDIR := /opt/local/Vrui-2.6/share/make
ifdef DEBUG
VRUI_MAKEDIR := $(VRUI_MAKEDIR)/debug
endif
INSTALLDIR := $(shell pwd)
# Set resource directory: I added this images folder to the same place as my
# .cpp file, but it still doesn't work
RESOURCEDIR = images
########################################################################
########################################################################
# Include definitions for the system environment and system-provided
# packages
include $(VRUI_MAKEDIR)/SystemDefinitions
include $(VRUI_MAKEDIR)/Packages.System
include $(VRUI_MAKEDIR)/Configuration.Vrui
include $(VRUI_MAKEDIR)/Packages.Vrui
# Set installation directory structure:
BININSTALLDIR = $(INSTALLDIR)/$(EXEDIR)
RESOURCEINSTALLDIR = $(INSTALLDIR)/$(RESOURCEDIR)
########################################################################
########################################################################
PACKAGES = MYVRUI
########################################################################
########################################################################
ALL = $(EXEDIR)/NewPlanet
.PHONY: all
all: $(ALL)
########################################################################
#'make clean'
########################################################################
.PHONY: extraclean
extraclean:
.PHONY: extrasqueakyclean
extrasqueakyclean:
# Include basic makefile
include $(VRUI_MAKEDIR)/BasicMakefile
########################################################################
########################################################################
$(EXEDIR)/NewPlanet: $(OBJDIR)/NewPlanet.o $(OBJDIR)/drawShape.o
You should use relative path like Beta suggested. Put a "data" folder on the same folder than your executable and use :
Vrui::openFile("./data/land_shallow_topo_2048.png")
File opening should be relative to the program directory, so you could create a sub directory inside your source dir for pictures. Make sure to let the user know where to place these pictures however,
g-dev#g$ mkdir dat
g-dev#g$ mv pic.jpg dat/pic.jpg
then in source:
::readImageFile("", Vrui::openFile("pic.jpg")
adding the directory in CMake:
include_directories ("${PROJECT_SOURCE_DIR/dat}")
adding the directory in VS:
here
(make sure you're using provided MSVS macros for your file path $(ProjectDir) or $(SolutionDir) )
I have a codebase where there are some shared libraries. For example LIB1 does some sort of processing that APP1 needs (depends on).
The qmake *.pro files are setup like the following. There is one root *.pro that is a TEMPLATE=subdirs that lists APP1 and LIB1 as it's subdirs.
LIB1.pro:
TARGET = LIB1
TEMPLATE = lib
QT += core
QT += xml
DESTDIR = path/to/libs/directory
SOURCES += \
File1.cpp \
FileN.cpp
HEADERS += \
File1.h \
FileN.h
APP1.pro:
#------ dependencies ------#
LIBS += -Lpath/to/libs/directory
# LIB1
INCLUDEPATH += path/to/libs/directory/LIB1lib
DEPENDPATH += path/to/libs/directory/LIB1lib
LIBS += -lLIB1
HEADERS = \
FileNplus1.h \
FileM.h
SOURCES = \
FileNplus1.cpp \
FileM.cpp
The problem is that when you compile the root *.pro file LIB1 will compile but APP1 fails to compile with the error QDomElement: No such file or directory because APP1.pro doesn't have QT += xml.
There is a hack that I use but I would like to overcome this hack. The hack involves adding the following line to APP1.pro:
# add this to APP1.pro... let's it compile again
QT += xml
Is there anyway to setup your qmake *.pro files such that, APP1.pro depends on LIB1 without needing to modify APP1.pro to add the QT += xml?
(The reason for this question is let's say you have other libraries that depend on other stuff... I would like to have Qt/Qmake take care of the dependencies like for example the Qt += xml dependency.)
qmake allows you to create your own configuration features. (last paragraph)
So you can create your own feature and move your lib1-linking code to it. You can add QT+=xml here. And in app.pro you'll just write CONFIG += lib1
I need to convert Qt Project to CMake , as i want to integrate it with other projects which are already in CMake .
The Qt .Pro file is as follows ,
TEMPLATE = app
INCLUDEPATH += ./lib
# Input
HEADERS += dollar/GestureTemplate.h \
dollar/PathWriter.h \
dollar/GeometricRecognizerTypes.h \
dollar/GeometricRecognizer.h \
dollar/SampleGestures.h \
lib/GestureTemplate.h \
lib/PathWriter.h \
lib/GeometricRecognizerTypes.h \
lib/GeometricRecognizer.h \
lib/SampleGestures.h \
lib/MultiStrokeGestureTemplate .h \
lib/MultiStrokeGestureTemplate .h \
lib/MultiStrokeGestureTemplate .h \
lib/MultiStrokeGestureTemplate .h \
lib/SampleMultiStrokeGestures.h \
lib/MultipleStrokeGestureTemplate.h \
lib/utils.h
SOURCES += main.cpp \
lib/GeometricRecognizer.cpp
LIBS += -L/usr/lib \
-lml \
There is only one directory Lib and in the main path there is main.cpp , all the other files are inside Lib directory .
I don't know much about cmake i have come up with the following cmake list for the above qt project.
cmake_minimum_required (VERSION 2.6)
Project(dollar)
INCLUDE_DIRECTORIES("lib")
# Make Executable
ADD_EXECUTABLE(main main.cpp)
# Link the executable to the Hello library.
TARGET_LINK_LIBRARIES(main -lml -L/usr/lib)
cmake succeeds but after that make gives me many errors ,see the error log -> http://www.text-upload.com/read,4022366863337 .What all additions i require to make in CMake List ?.
It seems that you have missed lib/GeometricRecognizer.cpp file
# Make Executable
ADD_EXECUTABLE(main main.cpp lib/GeometricRecognizer.cpp)