Premake (lua) pch create /Yc Visual Studio - creation

In the premake lua script for my solution. How do i set it to create "/Yc" the phc instead of being set to use "/Yu" on first initialisation.
I have searched the online documentation and tried other help sites. I can't find any help.
I assume it's a build option but have tried buildoptions { "/Yc" }
Some help would be much appritiated?

The solution was to set the correct path to the source file.
premake5.lua
pchheader "awepch.h"
pchsource "%{prj.name}/Src/awepch.cpp" // this is where the source file is located on disk
* Also it is mandatory that you use the correct case for the characters. If you use "pch.h" for a file name on disk that must be the file name in this section of your "premake5.lua" script
Sorry to take so long to deliver the answer :)

you need to specify
pchheader('StdAfx.h')
and
pchsource('StdAfx.cpp')

For the current version of premake v5. 0.0-beta1, you must do the following in order for the precompiled header to work across all IDEs (especially for Visual Studio):
Put both pch.h and pch.cpp under the root directory of your project (not solution/workspace).
Set the exact name (not a path) of the pch.h to pchheader().
Set the full path of pch.cpp relative to premake5.lua script in pchsource(). This is IMPORTANT. I don't know why, but if you do not specify the full relative path, then premake will Use (/Yu) (use precompiled header) to the phc.cpp instead of Create (/Yc) (create precompiled header), which results in not creating the precompiled header in Visual Studio.
Include the directory where pch.h and pch.cpp are located in includedirs()
#include "pch.h" IN EVERY .cpp file in your project, IN THE FIRST LINE of each .cpp file. Remember: #include "pch.h", "pch.h" must be excactly the same as the string you set in pchheader() in your premake5.lua script.
If you have .c files, you MUST rename them to .cpp instead, otherwise Visual Studio will complain about using a precompiled header that was compiled using a c++ compiler.
I know it's overcomplicated but this is how it is.
Example:
project "LearnGL"
location "Projects/LearnGL/"
kind "ConsoleApp"
language "C++"
targetdir "builds/"
objdir "obj/%{prj.name}_%{cfg.shortname}"
pchheader "pch.h" --Do not use paths here. Use directly the header file name
pchsource "Projects/LearnGL/src/pch.cpp" --Full path MUST be specified relative to the premake5.lua (this) script.
files {
"Projects/LearnGL/src/**.h",
"Projects/LearnGL/src/**.hpp",
"Projects/LearnGL/src/**.cpp"
}
includedirs {
"Projects/LearnGL/src/", --This is where pch.h and pch.cpp are located.
"Projects/LearnGL/src/external/glad/include/",
"Projects/LearnGL/src/external/stb_image/include/",
"External/glfw/include/",
"External/spdlog/include/"
}

Related

Qt - Add files to project

I'm making an application part of which is reading from an XML which stores some preferences. However, whenever I build the project, all the sources get copied but the preferences file does not! I have added the following to the .pro file -
RESOURCES += rsc.qrc
And my rsc.qrc contains
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>data/preferences.xml</file>
<file>data/gamedata.xml</file>
</qresource>
</RCC>
Now whenever I try to open preferences.xml
QFile preferences(":/data/preferences.xml");
if(!preferences.exists()){
preferences.open(QFile::WriteOnly);
preferences.write("abc");
qDebug() << "Written";
}
else {
qDebug() << "File exists";
}
Absolutely nothing gets printed and even the rest of the application stops working.
You don't use the resource part correctly in your example.
It will most likely not work because you try to write to a resource that is embedded into your executable after you have build your application. Reading is fine, but writing can't work by definition.
If you want a editable setting files, you have to distribute them along with your executable, or use a different method for reading/writing your settings like QSettings.
However using QSettings also means, that you will need to configure all your default settings in your loading function in case the values do not exist if you use the default configuration. Meaning you use registry on windows.
You have the option to force the use of a INI file format in the constructor of QSettings, this can make sense if you want to provide a default settings INI file instead of your xml files.
In case you want to store more complex data a xml file might be needed anyway, so if you want to stick with that you will need a way to copy your setting files to your build path. This can be done within your pro file with QMAKE_POST_LINK.
Example:
COPY_CMD = "$$PWD\\data\\preferences.xml $$OUT_PWD\\release\\data\\preferences.xml"
COPY_CMD = $${QMAKE_COPY} $$replace( COPY_CMD, "/", "\\" ) $$escape_expand( \\n\\t )
QMAKE_POST_LINK += $$COPY_CMD

QtCreator: Include generated UI files when shadow building

I'm using QtCreator to develop a larger application which is set up as .pro files with the SUBDIRS template.
Some of the sub projects need to include the generated ui_*.h files from other sub projects (e.g. in order to extend a generic GUI class). Each sub project has a line like
UI_DIR = gen/ui/$${CONFIGURATION_NAME}
where CONFIGURATION_NAME is "static_debug" or "static_release".
Now what I usually do is add the following includes when necessary:
#if _DEBUG
#include <OtherProject/gen/ui/static_debug/ui_SomeClass.h>
#else
#include <OtherProject/gen/ui/static_release/ui_SomeClass.h>
#endif
However, this does not work when shadow building, as the generated files are in the shadow build folder while the source files are in the source folder.
Is there a way to make this work with shadow builds, or is there a more sophisticated way to handle such cases in general?
The SUBDIRS template is an awesome feature although not documented well enough I think.
Here's a link from the Qt wiki which is of help in this case: http://qt-project.org/wiki/QMake-top-level-srcdir-and-builddir
To re-cap a bit:
Qt4-based solution
myproject.pro
TEMPLATE = subdirs
SUBDIRS = initvars.pro subdir1 subdir2 #subdir1 and subdir2 are your project subdirs
initvars.pro
TEMPLATE=subdirs
SUBDIRS= # don't build anything, we're just generating the .qmake.cache file
QMAKE_SUBSTITUTES += .qmake.cache.in
\.qmake.cache.in
top_srcdir=$$PWD
top_builddir=$$OUT_PWD
Qt5-based solution
Here things get easier
top_srcdir=$$PWD
top_builddir=$$shadowed($$PWD)
Now, having access to the actual build dir, your subprojects will go in the relevant subdirs. You can use this information to fill in the INCLUDEPATH in your subprojects .pro files to make it easier to include what you need from your sibling projects.
I personally have not had this problem but the problem could be arising because
It’s probably looking for them in current dir.Take a look at how you
include the ui_.h files in your headers.Add UI files path to qmake’s includepath.
You can change where to create them using the UI_DIR variable in
your .pro file.

Qt Installer framework component installation location

I've created an installer package based on the Qt installer framework with multiple components.
I needed to install each component in the appropriate directory.
Is it possible to specify the target directory for the individual component? I am referring to something like this:
var appData = installer.environmentVariable("AppData");
if (appData != "")
component.setValue("TargetDir", appData+ "/MyComponent");
Thank you in advance.
This question has already been answered, but I thought I would add a more detailed answer.
The documentation states that "for each component, you can specify one script that prepares the operations to be performed by the installer."
The Qt installer framework QtIFW comes with a set of examples, one of which is called modifyextract. Using this, I modified my package.xml file to include the line
<Script>installscript.qs</Script>
I then added a file installscript.qs to my package meta directory with the following content
function Component()
{
}
Component.prototype.createOperationsForArchive = function(archive)
{
// don't use the default operation
// component.createOperationsForArchive(archive);
// add an extract operation with a modified path
component.addOperation("Extract", archive, "#TargetDir#/SubDirectoryName");
}
The files in the package data folder were then installed in the subfolder SubDirectoryName
You need this based on the documentation:
Extract "Extract" archive target directory Extracts archive to target directory.
In my case, the component.addOperation("Extract", ... line resulted in extracting to #TargetDir#.
Instead, use one of the 'Operations> options in the Package.xml file.

Why can't Xcode 4 find my .h files during a build?

I have a project that won't build because the compiler (?) can't seem to find the .h files. I have tried using the full path, relative path and setting the Project Search Paths (both Header and User Header) and nothing seems to work. What I find very strange is even with the full path it gives an error: No such file or directory (the file does indeed exist in the specified path).
What could be the problem?
import statements:
#import <Foundation/Foundation.h>
#import <zxing/common/Counted.h>
#import <zxing/Result.h>
#import <zxing/BinaryBitmap.h>
#import <zxing/Reader.h>
#import <zxing/ResultPointCallback.h>
Headers are located in:
/Users/rolfmarsh/iPhoneCodeLibrary/BarcodeLibrary/zxing-1.6/cpp/core/src/zxing
Header search path is:
$(inherited)
"$(SRCROOT)/zxing/common"
and
/Users/rolfmarsh/iPhoneCodeLibrary/BarcodeLibrary/zxing-1.6/cpp/core/src
Full path of the include files:
/Users/rolfmarsh/iPhoneCodeLibrary/BarcodeLibrary/zxing-1.6/cpp/core/src/zxing/Result.h
I also had quite a bit of pain with ZXing's dependencies. Here's some tips that will hopefully be of assistance to others with similar issues.
This line does an import:
#import <zxing/common/Counted.h>
For the compiler to find Counted.h, the header search path must be specified.
Now, because the import statement will look for Counted.h relative to two subfolders zxing/common, we need to give it the parent folder of zxing.
In this case, the parent folder is going to be something like:
/ .. my full path here ../cpp/core/src/
So, under the src directory you'll find zxing.
How do we configure this in Xcode? Best to do it relatively. Otherwise, the project will fail on a different user's machine.
To do this, we specify a path relative to the project directory. As follows:
$(PROJECT_DIR)/../cpp/core/src
That goes in the Header Search Path of Build Settings for the ZXingWidget target.
The crucial thing with this header path stuff is to specify the relative directory to search from. In our case, we specify search relative to $(PROJECT_DIR). That variable specifies the directory of our subproject ZXingWidget.
Other caveats. Be careful to specify these in the build settings of your target. If you do it at project level you'll still need to specify it at target level using the $(inherited) variable.
Also, don't forget that the build transcript can be very useful. Look at the header paths included with the -I flag.
As a general debugging technique, I like to specify the absolute path in my settings. That gives a clean build and I know that the files can be included, and where they definitely are. Having done that I then use the $(PROJECT_DIR) to specify a relative path.
I am posting this in order to make things simple for newbies like me that are integrating zxing qr reader in their projects and to bring closure to a couple of threads related to zxing integration.
1.
Main thing - Be absolutely sure you have the latest version.
http://zxing.googlecode.com/svn/trunk/
[By now, January 18th, you will have no more issues with that zxing/common/ folder. Easiest fix for this: get the latest code!]
2.
Go to zxing -> iphone -> ZXingWidget.
Drag ZXingWidget.xcodeproj file and drop it onto the root of your Xcode project's "Groups and Files" sidebar.
[you should now have ZXingWidget.xcodeproj listed there and it has to drop down and list it's content]
3.
In the same place, project navigator, select:
Your project file - > Targets -> 'your project name' -> Build phases -> Link binary with libraries.
You should find a folder named 'Workspace'. Add 'libZXingWidget.a' from within.
4.
Still in Build phases, expand Target Dependencies and add ZXingWidget.
5.
Select Build Settings and search for Header Search Paths.
You need to add 2 records to Header Search Paths. You do not need to associate values to User Header Search Paths. You achieve this by double clicking the column on the right. A small popover window will apear. Use the + button to add the first record. Add:
../zxing/iphone/ZXingWidget/Classes
Now use the + button to add the second record. Add:
../zxing/cpp/core/src
These are the values I use. These values work because I use the same folder to host both my project and the zxing folder.
[Be sure to refer your folder properly in case you decide to have a different file structure.]
6.
Go back to Build Phases and add the following ios frameworks required:
AVFoundation
AudioToolbox
CoreVideo
CoreMedia
libiconv
AddressBook
AddressBookUI
7.
Create a set of files (.h&.m) and change it's .m extension to .mm
8.
Test the integration by including the following in the file previously created:
#import <ZXingWidgetController.h>
#import <QRCodeReader.h>
At this point you should run into missing files only if you are not running the latest version. Hope this helps.
Some things to check:
- file permissions
- can you build from the command line using xcodebuild?
I went over many blog posts on how to fix this. This one helped me well.
http://alwawee.com/wordpress/2011/12/01/zxingwidgetcontroller-h-not-found-zxing-installation-problem-solution/
The problem was that header search paths were not properly defined.
So I...
1) Downloaded zxing 2.1
2) From the download I copied: iphone, cpp, objc and readme and pasted in a folder names "zxing"
3) I added the new folder "zxing" to my project (on my mac) not to the xcode app.
4) From the created folder zxing I dragged the zxingwidget.xproje to my xcode project
5) I followed all the steps you find in all the blogs
KEY TO SOLVE THIS
6) I followed this steps for xcode errors https://stackoverflow.com/a/14703794/1881577
7) I followed this steps for header path file errors http://alwawee.com/wordpress/2011/12/01/zxingwidgetcontroller-h-not-found-zxing-installation-problem-solution/
IMPORTANT NOTE: I had to do follow step 7) twice, I had to select the project target and assign header paths, and I had to select the project project and assign header paths.
8) Build zxingwidget project (from the scheme select options)
9) Build Run the project.
Hope this helps other people as well.

Adobe AIR - reading a file in the same folder outside AIR package

How may I know File.nativepath from the folder that my .app or .exe AIR app is running?
When I try this I just get
'/Users/MYNAME/Desktop/MYAPP/Contents/Resources/FILETHATINEED.xml'
I need put this on any folder and read a xml file in the same folder. I don't need my xml file inside the package.
I need this structure
/folder/AIRAPP.exe
/folder/FILE.xml
Thanx in advance.
From what I can find there is no way to get that without doing some work yourself. If we assume that the File.applicationDirectory points to the wrong place only on Mac (which seems like the case), we can do this:
var appDir = File.applicationDirectory
if ( appDir.resolvePath("../../Contents/MacOS").exists ) {
appDir = appDir.resolvePath("../../..");
}
That is, check if the parent directories of the app directory match the Mac .app bundle directory structure, and in that case use the parent's parent's parent (which should then be the directory containing the .app bundle).
I believe you want to use File.applicationDirectory.

Resources