How can I stop a sub-project from getting built? - qt-creator

I have a large-ish Qt project that has multiple subprojects.
One of the sub-projects is intentionally unbuildable, and I don't want QtCreator to try to build it. I still want all its source files visible in the project tree, however.
How can I prevent a project from getting built?
Is there a TEMPLATE = NONE or TARGET = PLZ_DONT_BUILD?

The hacky solution I've come up with is wrapping all my source files with:
DisableBuild {
SOURCES = DummyMain.cpp
} else {
SOURCES = main.cpp \
...many other files...
} #...at the bottom of the .pro file.
DummyMain.cpp just contains an empty int main() function, so the compiler doesn't complain about empty entry points.
If there is a better solution, I'd like to hear it!

Related

How do you create custom build rules in QTCreator for code generation?

I'm working on a GTK3 application, but using QTCreator as my IDE, just because I happen to like it. It works fine, I can easily turn off all the QT-specific stuff and link the GTK libraries. There's just one little issue.
GTK uses XML files to define its resources. It comes with a program, "glib-compile-resources", which takes a .gresource.xml file and produces a .c file*, which can then be included in your project. The problem is that QTCreator doesn't know about glib-compile-resources, so I have to remember to run the program manually every time I make any change to them.
I've tried using a custom build step, but if I do that, then QT rebuilds the file every time, even if it hasn't changed, which slows the process down. In addition, if the C file doesn't already exist, it will fail with a "No rule to make target 'x.c' needed by 'x.o'. Stop." error, so I have to run the program manually anyway.
Is there any way to tell QTCreator to run glib-compile-resources whenever it encounters a .gresource.xml file, and include the resulting C file into the final compilation?
*There are other options available then just a straight C source file, but C source is the simplest and easiest for me.
You can add a custom target in your qmake file (rather than in your QtCreator project config). See the qmake docs at https://doc.qt.io/qt-5/qmake-advanced-usage.html#adding-custom-targets and/or https://doc.qt.io/qt-5/qmake-advanced-usage.html#adding-compilers.
Update: this is a simple example which shows how to do this for a single file, using the custom target mechanism in your .pro file:
glib_resources.target = glib-resources.c
glib_resources.depends = glib-resources.xml
glib_resources.commands = glib-compile-resources --target $$glib_resources.target --generate-source $$glib_resources.depends
QMAKE_EXTRA_TARGETS += glib_resources
PRE_TARGETDEPS += glib-resources.c ## set this target as a dependency for the actual build
QMAKE_CLEAN += glib-resources.c ## delete the file at make clean
Here's how I wound up solving my own issue:
I found in the QT documentation how to add your own custom compiler to a QT project file. The exact lines needed are:
GLIB_RESOURCE_FILES += \
resources.gresource.xml
# Add more resource files here.
glib_resources.name = glibresources
glib_resources.input = GLIB_RESOURCE_FILES
glib_resources.output = ${QMAKE_FILE_IN_BASE}.c
glib_resources.depend_command = glib-compile-resources --generate-dependencies ${QMAKE_FILE_IN}
glib_resources.commands = glib-compile-resources --target ${QMAKE_FILE_OUT} --sourcedir ${QMAKE_FILE_IN_PATH} --generate-source ${QMAKE_FILE_IN}
glib_resources.variable_out = SOURCES
glib_resources.clean = ${QMAKE_FILE_OUT}
QMAKE_EXTRA_COMPILERS += glib_resources
(Thanks to #zgyarmati, who's post lead me to the right answer.)

Importing GeneratedSource in Gradle

I'm generating some source files via ANTLR. I want to use those files while writing my own source code.
When I use the generateGrammarSource task the code is perfectly generated but goes to the build\generated-src directory. When I import classes from that directory, both my build task and the make project compiles successfully. But IntelliSense is generating a metric ton of errors and warnings (mostly indicating that the imports are non-existent - Cannot resolve Symbol, even though they really are there).
Is this a problem with IntelliJ, what can I do to appease IntelliSense, so I can continue my work in peace?
Basically you should have the following setup:
def generatedDir = 'src/main/gen'
sourceSets {
main {
java {
srcDirs += [generatedDir]
}
}
}
task generateGrammarSource // need to generate the file under src/main/gen
compileTask.dependsOn(generateGrammarSource) // don't know the exact name of the compile task
clean << {
project.file(generatedDir).deleteDir()
}
You'll also need to add the generated sources to IntelliJ, google for it.

Hide common parent folders of project files in Premake

I am new to Premake. I am using Premake 4.4 beta 5 because Premake 5 has a few issues where it does not generate proper VS2010 solutions (generates VS2012 solutions with 2010 compiler), and it setting libdirs and links for all projects when written under one project.
Anyways, the issue I am having is that I wrote a Premake script. It all works fine, but there is an annoyance where it includes multiple parent folders in common between all the files included in the project. So you have to open multiple folders containing nothing but a single folder, before you get to the meat. Here's is an image so that you understand: premake_common_parent_folders
My folder structure on disc looks something like this:
build
premake4.lua
premake4.4-beta5.exe
src
StaticLib
include
Example.h
Example.cpp
Test
Example.cpp
Here is my Premake:
_targetdir = '../bin/' .. _ACTION
local function ProjectCommon()
targetdir( _targetdir .. '/' .. project().name )
files {
'../src/' .. project().name .. '/**.*',
}
includedirs {
'../src/' .. project().name .. '/include',
}
end
solution( 'Example' )
location( _ACTION )
configurations { "Release", "Debug" }
project( 'Test' )
ProjectCommon()
language( 'C++' )
kind( 'ConsoleApp' )
includedirs {
'../src/StaticLib/include',
}
libdirs {
_targetdir .. '/StaticLib',
}
links {
solution().name,
}
project( 'StaticLib' )
ProjectCommon()
targetname( solution().name )
language( 'C++' )
kind( 'StaticLib' )
I want to know if there is a way to have the implementation files directly under the project with the single include folder. Hiding the parent folders common between all project files (src and [Project Name]).
The hope is to have it look something like this: premake_no_common_parent_folders
In theory (untested, I haven't used Premake 4 in a long time) you can use virtual paths to rewrite the structure.
vpaths {
["*"] = "../src/"
}
Premake 5, on the other hand, automatically trims otherwise empty groups from the top of the path, so this isn't necessary if you upgrade.
Speaking of Premake 5, I'm not familiar with either of the bugs you mention; you should open an issue if you haven't already. I'd be willing to bet "setting libdirs and links for all projects when written under one project" is an issue with your project script rather than Premake itself, as that would be a pretty fundamental flaw.

boost build b2/bjam build configuration

I'm currently working on a c++ project that uses bjam (boost build) as a builder. For now I was quite happy with this build system and everything works nicely, however with one exception which I could not find an easy solution for:
I would like to have a build configuration of this project, in which the user is able to switch on or off certain modules and its dependencies (also automatic checks if software is not found -> disable module..). With dependencies I mean for example applications that require this module to work. So these applications should also not be built when the module is disabled.
Since I found nothing out there that could do this job for me, I created some variables in the jamroot (top level jamfile) that resemble the module structure of the project, and I use these variables in if statements within the appropriate jamfiles to switch on and off things. See below for an example:
Jamroot excerpt:
constant build_DataReader : 1 ;
constant build_RootReader : 1 ;
constant build_AsciiReader : 1 ;
if $(build_DataReader) {
build-project DataReader ;
}
Jamfile for DataReader Module:
sources = [ glob *.cpp ] ;
if $(build_RootReader)
{
build-project RootReader ;
sources = $(sources) $(DATAREADER)/RootReader//RootReader ;
}
if $(build_AsciiReader)
{
build-project AsciiReader ;
sources = $(sources) $(DATAREADER)/AsciiReader//AsciiReader ;
}
# Build libDataReader.so
lib DataReader :
$(sources)
;
install dist : DataReader : <location>$(TOP)/lib ;
However this is not a very elegant solution, as I would constantly have to update these hardcoded if statements when dependencies change etc.. In addition it is annoying to have to construct this tree structure of the modules in the project myself, as boost build is constructing the same thing internally by itself. Is there some kind of option in boost build to make the building of applications optional in case some requirements are not built in the current build process?
The only solution I see at the moment would be to construct a complete new config tool that would create the jamfiles for me like I want them (preprocessor). However this is work I do not want to start, and I don't really believe that there is nothing out there that is able to do what seems to me like pretty common stuff. But probably I missed something completely...
Hope I explained it in an understandable way, thanks in advance!
Steve

Can clang be told not to analyze certain files?

I'm trying to use clang to profile a project I'm working on. The project includes a rather large static library that is included in Xcode as a dependency.
I would really like clang to not analyze the dependencies' files, as it seems to make clang fail. Is this possible? I've been reading the clang documentation, and I haven't found it.
As a last resort, there is a brute force option.
Add this to the beginning of a file:
// Omit from static analysis.
#ifndef __clang_analyzer__
Add this to the end:
#endif // not __clang_analyzer__
and clang --analyze won't see the contents of the file.
reference: Controlling Static Analyzer Diagnostics
So, this isn't really an answer, but it worked well enough.
What I ended up doing was building the static library ahead of time, and then building the project using scan-build. Since there was already an up-to-date build of the static library, it wasn't rebuilt and thus wasn't scanned.
I'd still love to have a real answer for this, though.
Finally, in 2018 the option was implemented.
Use --exclude <path> [1] [2] option
--exclude
Do not run static analyzer against files found in this directory
(You can specify this option multiple times). Could be useful when
project contains 3rd party libraries.
I don't use XCode, but using scan-build in linux the following works for me. I my case, I want to run the static analysis on all first party, non-generated code. However, I want to avoid running it on third_party code and generated code.
On the command line, clang-analyzer is hooked into the build when scan-build sets CC and CXX environment variables to ccc-analyzer and c++-analyzer locations. I wrote two simple scripts called ccc-analyzer.py and c++-analyzer.py and hooked them in to the compile in place of the default. In these wrapper scripts, I simply looked at the path of the file being compiled and then run either the raw compiler directly (if I wish to avoid static analysis) or the c*-analyzer (if I wish for static analysis to occur). My script is in python and tied to my specific build system, but as an example that needs modification:
import subprocess
import sys
def main(argv):
is_third_party_code = False
for i in range(len(argv)):
arg = argv[i]
if arg == '-c':
file_to_compile = argv[i + 1]
if '/third_party/' in file_to_compile or \
file_to_compile.startswith('gen/'):
is_third_party_code = True
break
if is_third_party_code:
argv[0] = '/samegoal/bin/clang++'
else:
argv[0] = '/samegoal/scan-build/c++-analyzer'
return subprocess.call(argv)
if __name__ == '__main__':
sys.exit(main(sys.argv))
For Xcode users, you can exclude individual files from static analyzer by adding the following flags in the Target -> Build Phases -> Compile Sources section: -Xanalyzer -analyzer-disable-all-checks

Resources