How to change the Global Settings (compiler, linker) in codelite? - codelite

I am using CodeLite for C++ development.
I can edit AVAILABLE options under Settings/Build settings/Compiler Options or /Linker Options.
I can also change the options of a PARTICULAR project under Workspace/Open Active Project Settings...
What I want to do is to change the default settings for ALL projects (or at least for all NEW projects).
In the active project settings the first field is "Use with Global Settings" what implies that somewhere there should be access to these Global Settings, but I do not find. I only found under Build Settings/Advanced the Include Path and the Libraries Path but I do want to make other defaults as well, e.g. for the compiler "C++ Compiler Options" like e.g. .std=c++17 and for the linker "Linker Options" e.g. -pthread and "Libraries".
I make many little projects and it is a nightmare to change all these manually for every little project.

There is no UI to do this, but this can be done.
To apply a new compiler / linker options to your entire workspace, the easiest way to do this is:
Right click on your workspace icon
There are 2 tabs in this view, select the one that says Environment
To add some new compiler options, set the environment variable CXXFLAGS
To add a new linker options, set the environment variable LinkerOptions
For example, in order to compiler all my sources with -std=c++17 and link the binary with -s (strip) linker option, add the following to the environment variable section of the workspace:
CXXFLAGS=-std=c++17 $(CXXFLAGS)
LinkOptions=$(LinkOptions) -s
the CXXFLAGS is only applied to C++ source files e.g. *.cpp or other common extensions like *.cxx, *.cc etc. To set compiler options for C source files, use the environment variable CFLAGS
Notice that I am also concatenating the previous value, this makes sure that the new value does not override the old value, but adds to it

Related

What are the members of a qmake install set?

https://doc.qt.io/archives/qt-4.8/qmake-environment-reference.html#installs
To help in the install process qmake has the concept of a install set.
It looks like a install set have members, i.e. path, files and extra:
documentation.path = /usr/local/program/doc
documentation.files = docs/*
Are there other members?
What members need to be set in order to consider the install set fully described?
Where the create_docs come from in the case below
unix:documentation.extra = create_docs; mv master.doc toc.doc
QMake is documented... not. Whenever you want to know something you go browse source code. In this case, it's in qmake/generators/makefile.cpp, function Makefilegenerator::writeInstalls().
As we can see, it's path, files, base, extra, CONFIG, uninstall and depends. extra (or commands) is an arbitrary line to insert at the top.
What members need to be set in order to consider the install set fully described?
QMake is Makefile generator. Whatever human does it simply outputs some Makefile. Whether it will work or not, that's a human's problem.

Premake override for Vcpkg

I would like to be able to create a custom override to add a VcpkgConfiguration Property based on our current configuration.
We have a C++ project that uses Premake and vcpkg. We have found vcpkg to conflict with other projects that include their own versions of similar libraries, so we cannot use the global integration that it provides. Instead we have added it as a sub-module to our project and linked it through premake with a custom override:
p.override(p.vstudio.vc2010, "importExtensionTargets", function(base, prj)
p.push('<ImportGroup Label="ExtensionTargets">')
p.callArray(p.vstudio.vc2010.elements.importExtensionTargets, prj)
p.pop('</ImportGroup>')
p.push('<ImportGroup Label="ExtensionTargets">')
p.w('<Import Project="$(SolutionDir)External/vcpkg/scripts/buildsystems/msbuild/vcpkg.targets"/>')
p.pop('</ImportGroup>')
end)
Unfortunately we do not use the regular "Debug" or "Release" configurations in our project, so vcpkg by default does not link correctly. To get past that problem, we modified the vcpkg.targets file to recognize our configuration in a local branch. This is not ideal, as it forces us to rebase our branch off vcpkg in order to update it, and could potentially conflict if that file is ever modified in their repo.
The targets file allows you to set the VcpkgConfiguration property before including the target, which is what we would like to do.
Basically what we would like is to be able to call a command through the filters like this:
filter {"configurations:<SomeConfiguration>"}
VcpkgConfig "Debug"
Which would add this inside the propertygroup
<VcpkgConfiguration>Debug</VcpkgConfiguration>
How can we accomplish this?
The problem seems to be that importExtensionTargets is per project but you want this per configuration.
You can try to register your key word
api.register {
name= "VcpkgConfig",
scope = "config",
kind = "string",
}
then in your custom function
-- loop over all configurations
for _, cfgName in ipairs(prj.configurations) do
-- find config
local cfg = project.findClosestMatch(prj, cfgName)
if cfg.VcpkgConfig then
p.push('<ImportGroup Label="ExtensionTargets">')
p.push('<VcpkgConfiguration>'.. cfg.VcpkgConfig .. '</VcpkgConfiguration>')
p.w('<Import Project="$(SolutionDir)External/vcpkg/scripts/buildsystems/msbuild/vcpkg.targets"/>')
p.pop('</ImportGroup>')
end
Not tested.
Would this work ?

How to pass strip flag to linker in release mode in QBS?

I'm using QBS 1.10.1 in Qt Creator 4.5.1 , under MSYS2.
I would like to pass -s to g++ when invoked for the link step, to reduce the size of the release mode binary. How do I do this?
So far I have tried as suggested by the documentation:
cpp.driverFlags: ["-municode", "-static", "-static-libgcc", "-static-libstdc++"]
Properties {
condition: qbs.configuration === "Release"
cpp.driverFlags: outer.concat("-s")
}
however it does not actually pass the -s in Release mode, i.e. it's as if the Properties block were not there.
Note: The cpp.driverFlags option actually passes flags to all instances of g++, not just link steps; however I have been unable to find a way to only specify flags for the link step. The g++ is smart enough to ignore those flags if it wasn't a link step. The cpp.linkerFlags field actually transforms the flags to a -Wl,"flag" option which is not the right behaviour for these flags.
There are two problems with your code:
You should not test for the value of qbs.configuration, which is an arbitrary string set by users. Instead, use qbs.buildVariant, where "release" (all lower case!) is a known value.
-s is not a driver flag, but an actual linker flag, i.e. an option that ld understands. Therefore, you should use cpp.linkerFlags. The option will be automatically escaped if the gcc frontend is used for linking.

Qt - Don't append major version number to the end of executable/library name

How can I stop Qt from renaming my DLL to MyDLLName{MAJOR_VERSION_NUM}.dll?
This only happens when I set the VERSION in my project file, but I also want to set the version. For example, if I have:
VERSION = 1.2.3.4
And my library is named MyDll, it will create my DLL in the debug folder as MyDLL1.dll. If I take the version number away, it keeps the name as I want it (MyDLL.dll).
Thanks.
Use this:
CONFIG += skip_target_version_ext
See this answer (on SO) for why it is there: Why library name gets an additional 0 in its name?
You can "not-set" the version to remove it from the generated name, but are you sure you want to do that? (It's there to avoid DLL Hell.)
The "proper-answer" is that the LIB template is adding the version number.
Also, note:
VERSION is used to define VER_MAJ and VER_MIN
msvc_nmake generator adds /VERSION:major.minor to link flags if !empty
msvc_vcproj generate adds /VERSION:major.minor to link flags and MSVCPROJ_VERSION if !empty
You can explicitly set those yourself, or "unset" any of them.
You can explicitly remove the version number from the target name with the TARGET_EXT variable, for example, see: http://qt-project.org/faq/answer/how_can_i_add_version_information_to_my_application
If you want to create your own plugin to decide how to generate the target name (without the version number), you can make your own plugin as described in this answer (on SO): How to avoid having version numbers in .so file name

How can I programmatically add build files to Xcode4?

I've been trying to figure out how to programmatically add files to an Xcode4 project and it seemed like AppleScript would be the way to go, however I'm running into "missing value" errors.
Here's the code I've got:
tell application "Xcode"
set theProject to first project
set theTarget to first target of theProject
set theBuildPhase to compile sources phase of theTarget
tell first group of theProject
set theFileRef to make new file reference with properties {full path:"/Users/jeff/Projects/XcodeTest/XcodeTest/MyViewController.h", name:"MyViewController.h", path:"XcodeTest/MyViewController.h", path type:group relative}
add theFileRef to theProject
end tell
--tell theBuildPhase to make new build file with properties {build phase:theBuildPhase, name:"MyViewController.h", file reference:theFileRef, target:theTarget, project:theProject}
end tell
I've tried the commented-out line instead of the add-command as well, but that doesn't work either (I get "missing value").
The 'add' error is:
error "Xcode got an error: file reference id \"251AD3431432472E006E300F\" of Xcode 3 group id \"251AD32C14324645006E300F\" of project \"XcodeTest\" of workspace document \"XcodeTest.xcodeproj/project.xcworkspace\" doesn’t understand the add message." number -1708 from file reference id "251AD3431432472E006E300F" of Xcode 3 group id "251AD32C14324645006E300F" of project "XcodeTest" of workspace document "XcodeTest.xcodeproj/project.xcworkspace"
The "make new reference" does add the file to the list of files in Xcode, but I also need it to be added to the project target so that I can add actions and outlets to the file from Xcode w/o having to first check the checkbox to add it to the "target membership".
I ended up sending this question to the devs on the xcode developer list and the response I got was effectively "you can't".
This appears to be completely broken in Xcode4, but I've seen a project that does it. I think what they are doing is parsing and modifying the "project.pbxproj" file directly. (this file is hidden inside the xcodeproj bundle)
The file is a GUID soup, but once you look at it for a while it seems possible to safely modify it, especially if you are only adding stuff.
Edit:
Found this stackoverflow answer that might help.
Tutorial or Guide for Scripting XCode Build Phases
There is a poorly documented user defined build setting that can be added. Files can be both excluded and included from compilation
Go to your target's Build Settings > Tap the + button > Add User-Defined Setting
The key is either INCLUDED_SOURCE_FILE_NAMES or EXCLUDED_SOURCE_FILE_NAMES
The value is a space separated list of file paths
See reference:
http://lists.apple.com/archives/xcode-users/2009/Jun/msg00153.html

Resources