CMake: check for standard library file using CheckIncludeFileCXX - c++

I am trying to figure out if the current compiler supports std::format, however the following code is populating the variable CXX_FORMAT_SUPPORT with nothing. I assume I may need to add an include path, but I'm not sure how to get that for the compiler if that is the case.
# check std::format support
include(CheckIncludeFileCXX)
check_include_file_cxx("format" CXX_FORMAT_SUPPORT)
message(STATUS "CXX_FORMAT_SUPPORT: ${CXX_FORMAT_SUPPORT}")
How can I correctly populate CXX_FORMAT_SUPPORT?

The documentation is less than clear but check_include_file_cxx sets the output variable to 1 if the header is found and doesn't set the variable if it is not found.

Related

Crystal module path require issue

This is my first post so please excuse the brevity. I'm learning crystal and trying to include a file which has a shared name with another file in another path. According to the documentation I can use require "path/to/modules/" and include all files within, but when I do this I and then use the imported class, it tells me the class does not exist...
Nothing in the documentation seems to work. Is there some addon module I need to get the paths to work properly or am I misunderstanding something or do I have some syntax error?
This is my code (Using the example on the home page)
require "http/server"
require "modules/HttpRequest"
server = HTTP::Server.new do |context|
context.response.print(request.result)
end
server.listen(80)
And the file HttpRequest.cr is in /modules/.
The error I get
Error in Server.cr:2: while requiring "modules/HttpRequest": can't find file 'modules/HttpRequest'
If you're trying to require a shard:
- Did you remember to run `shards install`?
- Did you make sure you're running the compiler in the same directory as your shard.yml?
require "modules/HttpRequest"
^
Using require "modules/HttpRequest" will look up modules/HttpRequest in CRYSTAL_PATH according to the require rules.
To require a file relative to the current file you need to use require "./modules/HttpRequest".

How to use the original filename in a multi file template in resharper?

I have a multi file template in resharper and I can use $NAME$ macro to get the name of the original file to use to name the other files in the template. But I also want to use the $NAME$ of the original file in the content of the other file template.
Is this possible? I can't see a macro which seems suitable for the internal variables as onlt the Current File Name seems available.
Anyone know if this is possible or how I might workaround this?
As a workaround, you may create a parameter $FILENAME$ (macro "Current file name without extension") in the first file e.g. in the comments, like:
class Foo
{
//$FILENAME$
}
Then you may call this parameter in other files of the multifile template - this parameter will contain the name of the first file since the first file will be generated before other ones.
Unfortunately, there isn't a macro that will give you this. I've added a feature request that you can vote on and track (and more specific detail as to what your requirements are would be useful) - http://youtrack.jetbrains.com/issue/RSRP-415055
It is possible to write your own macros as part of a plugin, but there isn't a sure-fire way of getting the name of the first document in the created file set. The IHotspotSessionContext instance that is passed to the macro via IHotspotSession.Context property includes an enumerable of IDocument, from which you can get IDocument.Moniker, which will be the full path for file based documents. However, there's no guarantee of the order of the enumerable - it's backed by a hashset. You might be able to rely on implementation details (small set, no removes) to be able to use the first document as the original, but there is really no guarantee of this.

Doxygen globally defined reference links

In Doxygen you use reference links: define them separately and then refer to them from within the text.
/**
* This is a documentation. Here I link [std::string] to an external web page.
*
* The next line is the link definition:
*
* [std::string]: http://en.cppreference.com/w/cpp/string/basic_string "std::string documentation"
*/
However it seems that the link definition is seen only within the documentation block. It is not seen even on other documentation blocks on the same page.
I want to define some links once, and then use them everywhere (on different pages).
Is that possible?
Edit (follow-up question)
In order to achieve your aim I think your best bet is to make use of the ALIAS facility.
I have managed to set it up with alias like this:
ALIASES += std_string="std::string "
ALIASES += std_vector="std::vector "
And using it:
#std_string
#std_vector
Basically I have one alias for each link.
Can it be achieved with one alias with parameters? The use would be:
#std_ref std::string
#std_ref std::vector
The problem is that some sort of map is needed between the name (the parameter) and the link:
std::string -> http://en.cppreference.com/w/cpp/string/basic_string
std::vector -> http://en.cppreference.com/w/cpp/container/vector
I know it can be done if one parameter would be the different part of the link, like :
#std_ref std::string string/basic_string
#std_ref std::vector container/vector
But this is ugly, error prone and would require to check each time what the link should be.
It's worth noting that what you are currently using is the notation that comes only with Doxygen's support for Markdown - it's not the doxygen method for external links. The original Doxygen method is to insert an HTML link inline...
link text
... but that makes no difference to your original problem.
In order to achieve your aim I think your best bet is to make use of the ALIAS facility. The relevant manual page is here. Using them, you should be able to define an alias like std-string and have it insert the HTML link everywhere you use the alias.
ALIASES are set up in the doxyfile config file (in this section of the manual)
You could set up aliases manually for every C++ keyword, that you want to link to, but the better way to do this is to use the doxygen TAGFILES feature.
A tag file is basically a compact representation of the entities found in the external sources. Doxygen can both generate and read tag files.
To generate a tag file for your project, simply put the name of the tag file after the GENERATE_TAGFILE option in the configuration file.
To combine the output of one or more external projects with your own project you should specify the name of the tag files after the TAGFILES option in the configuration file.
Doxygen has a whole page dedicated to explaining how to link to external documentation
And cppreference.com has already setup a tag file for you with some basic instructions.
For the impatient:
Download File:cppreference-doxygen-web.tag.xml for linking directly to cppreference.com website.
Add this line to your Doxyfile:
TAGFILES += "location/of/cppreference-doxygen-web.tag.xml=http://en.cppreference.com/w/"

QPixmap::save() returns successful, but yields no file

The docs say this should work:
bool did=pixmap.save( "hoppy.png" );
qDebug("did is: %d",did);
My logging returns 1 suggesting, as per docs, that the save was successful. However, no file appears on my drive. According to the docs, this save() should indeed save a file, so what is missing?
According to the docs, this save() should indeed save a file, so what is missing?
Nothing missing; it is simply saved to the folder of where you run the qt executable from. If it is a direct invocation, then it is beside the executable, otherwise it is beside the script or other program that calls the qt executable (sure, the other program could modify the current working directory, but let us forget about that for a bit).
If that is not what you would like to do, you better use an absolute path to the location where you wish to save it. However, if it is some common location, consider using QStandardPaths.
Another answer notes:
Nothing missing; it is simply saved to the folder of where you run the qt executable from
However my question indicated that this is actually not the case here.
Using the full path rather than a relative path or instead of using the ~ character, resolved it.

Customizing include-guard for Eclipse CDT

I want an automatically generated include-guard by creating a new C++-class with Eclipse/CDT, but I don't find any way to change the ${include_guard_symbol} attribute.
My wish is an include-guard with a namespace prefix like following:
#ifndef NAMSPACE1_NAMESPACE2_HEADER_HPP
But if I use #ifndef ${namespace_name}_${include_guard_symbol} for this, it will produce:
namepace1::namespace2::_HEADER_HPP
How can I do this?
I had a dig around in the source for CDT, and found an undocumented preference setting you can use to change what is generated by ${include_guard_symbol}. There's no GUI for it either, but if you add the codetemplates.includeGuardGenerationScheme setting to <projectpath>/.settings/org.eclipse.cdt.ui.prefs, you can choose between file name (the default), file path or UUID.
Given the file <projectpath>/src/include/Class.h, the following values give these results:
0 gives an upper-case filename, i.e. CLASS_H_
1 gives a UUID, for example. HC9ABE718_D04E_411C_B5A2_F9FE1D9F9409
2 gives an upper-case file path, that is, SRC_INCLUDE_CLASS_H_
To avoid any doubt, here's the contents of our .settings/org.eclipse.cdt.ui.prefs:
codetemplates.includeGuardGenerationScheme=2
eclipse.preferences.version=1
formatter_settings_version=1
It's obviously not exactly what you're after, but we use 2 to give us an approximation of our namespaces since, generally speaking, our namespaces follow our folder structure.
The relevant code is in these files in the CDT source:
core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java for the constants for each option
core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/codemanipulation/StubUtility.java for the generateIncludeGuardSymbol() method that does the work.
It would be really nice to see an extra option added for using the namespace, and a GUI too.
I'm using Eclipse Oxygen (CDT 9.3) and as Eelke described in their comment, there has been a UI setting for this for a while now.
However it only lets you choose from the preset schemes, no namespace or richer customisation options available yet.
Search for 'guard' in the preferences dialog, or navigate to C/C++ > Code Style > Name Style and select Code > Include Guard and then choose from the available guard schemes.