Adding file extension for new qmake variable
-
It is possible to add new compiler:
new_comp.output = ${QMAKE_FILE_BASE}.o new_comp.commands = mycomp ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT} new_comp.input = NEW_COMP_FILES QMAKE_EXTRA_COMPILERS += new_comp
It is also possible to interpret files with some extension as a source file by adding the extension to QMAKE_EXT_CPP. It makes QtCreator to add files with new extension to SOURCE variable. But how can I make QtCreator to add files with new extension to NEW_COMP_FILES variable which is from the example above?
-
Hi and welcome to devnet,
If I understand what you ask correctly,
OTHER_FILES
might be what you are looking for.Hope it helps
-
@SGaist Hi. I make a wizard for adding new files to a Qt project in QtCreator. The new files have specific extension, say ".cpp_ext". There is a special compiler which can compile files with ".cpp_ext" extension into objects. Look at following code:
new_comp.output = ${QMAKE_FILE_BASE}.o new_comp.commands = mycomp ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT} new_comp.input = NEW_COMP_FILES QMAKE_EXTRA_COMPILERS += new_comp
There is the new variable "NEW_COMP_FILES". If I put my files like "foo.cpp_ext" into the variable:
NEW_COMP_FILES += foo1.cpp_ext \ foo2.cpp_ext \ ...
I find these files in "source" folder in project tree of QtCreator. I suppose it is so just because I have defined rules (new_comp) for compilation the files from NEW_COMP_FILES variable into objects. The problem is that I can't make a wizard for adding such new files just into NEW_COMP_FILES. The files with ".cpp_ext" extension are added by this wizard into DISTFILES variable and I find these files in "other files" folder in project tree of QtCreator. It is cause that compilation rules don't take the files for compilation. I need to replace them into NEW_COMP_FILES variable manually by editing .pro file. And it is so sad. I can change NEW_COMP_FILES to DISTFILES, but it isn't what I want because in this case I find .cpp_ext files in "other files" folder in project tree of QtCreator and there are may be other files in DISTFILES, say .txt for example, but it is bad idea to compile .txt files.
-
The following code solves a part of the problem:
NEW_COMP_FILES += $$find(DISTFILES, .*\.cpp_ext$)
But it is difficult to exclude the ".cpp_ext" files from DISTFILES list. I try to add the following snippet:
DISTFILES -= $$NEW_COMP_FILES message(dist: $$DISTFILES)
Result of "message" function doesn't contain the ".cpp_ext" files but I see them in "other files" folder in project tree of QtCreator. Nevertheless if I change the snippet above to following snipped:
DISTFILES -= $$NEW_COMP_FILES DISTFILES = message(dist: $$DISTFILES)
result of "message" function doesn't contain the ".cpp_ext" files and I don't see them in "other files" folder in the project tree of QtCreator. The problem in this way is that if I want to add some files, say ".txt", to project the command "DISTFILES =" removes it from the project tree.
-
That might be because you are using cpp in the extension (just guessing)
Can you explain what your goal is with these .cpp_ext files ?
-
The .cpp_ext is just an abstraction meaning some another type of files with the special compiler. For example: .hs files and GHC compiler which produces object files (.o) like what g++ produces. There is no problem to compile and link these files into one executable binary. But I also want to work with these source files using QtCreator in more comfortable way where I find .hs files in "source" folder in project tree of QtCreator.
-
Then it might be something to look into Qt Creator for.
Maybe a plugin is is needed in order to handle the input variable for a custom compiler in a more suitable manner.
You should check the bug report system to see if there's something related or the Qt Creator mailing list. You'll find there Qt Creator's developers/maintainers.
-
@SGaist Thank you for your help. The problem is solved. I just move files from DISTFILES excluding .cpp_ext files to OTHER_FILES and then clear DISTFILES variable. Now the snippet from .pro file looks like this:
NEW_COMP_FILES += $$find(DISTFILES, .*\.cpp_ext$) DISTFILES -= $$NEW_COMP_FILES OTHER_FILES += $$find(DISTFILES, .*\.(?!cpp_ext$).*$) DISTFILES =