CMake multiple-option setting - build

I'm working on a project which is built with CMake, so I'm writing up a CMakeLists.txt for it. In this file I want to have a (cached) CMake variable that can only take one of several options (which I would specify somehow), rather than any arbitrary string. For simplicity, let's take it to be a string which can take "red", "green" or "blue" - but nothing else.
Can I achieve this with a recent CMake version, other than setting an arbitrary string then checking it for validity?

The answer is to be found in one of Kitware's Blog Posts named "Constraining Values with ComboBoxes in CMake (cmake-gui)":
So here’s how it works: for each cache entry that you want to constrain to some set of values, define it as usual with a default value as a STRING cache variable, for example:
set(BaseName "binary" CACHE STRING "BaseName chosen by the user at CMake configure time")
Now, after defining the cache entry with its initial default value, define the set of strings to which its value should be constrained:
set_property(CACHE BaseName PROPERTY STRINGS binary octal decimal hexadecimal)
After the set_property call, cmake-gui knows to present a drop-down combo box for editing the “BaseName” cache entry, and it knows that the four valid choices for this entry that it should present are binary, octal, decimal and hexadecimal.

Related

CMake: check for standard library file using CheckIncludeFileCXX

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.

Reading dates from filenames

I want to extract dates from the suffixes of files in a particular folder. The contents of such a folder look something like:
Packed_Folder_1_2016.06.10
Packed_Folder_1_2016.08.06
Packed_Folder_1_2015.09.03
packed_Folder_1_2015.01.08
... (so on and so forth, always in the same path just different suffixes)
There is no pattern to the dates. I need to make a VS form (2013) to read the name of the files and store the date differences.
Notice how the filenames always follow a pattern? It's always Packed_Folder_1_####.##.##, where the last part is a date.
So what you want to do is list the file names in the folder, and try to find a file that matches the pattern. You could use a regular expression to match the filename (it would be something like R"(Packed_Folder_1_\d{4}\.\d{2}\.\d{2})").
You are talking about Forms, so I am assuming you are able to use Visual C++. If that is the case, you can check FileSystemWatcher Class.
You instantiated it with a given path ( file or directory ), and it will trigger events based on some changes on the target (simple change, creation, rename - you can select which one). You could then update your reference, in case its change suits your needs.

How do I provide default YAML configuration values in a static library?

I have a configuration file system written in C++ which uses the yaml-cpp library to parse and write to YAML files. I have this as part of my static library.
I would like the ability to return a default value for a field that is requested by a user of the library (calling from their code), but which has not been defined in the user's YAML file.
For example say the user wants to use the field foo from their custom config.yaml file:
int bar = config_reader.read<int>( "config.yaml", "foo" );
If they have foo: 10 in their config.yaml then bar will be set to 10. However I would also like to provide a default value (for example 4) in the case where foo is omitted from config.yaml.
There are two possibilities I have thought of:
Have a set of static maps between field names and default values in a cpp file which gets compiled into the static library, however I will need to have different maps for different types and I feel this could get messy with type checking and maybe requiring template specialization methods.
Have a YAML file which contains all of the default values for expected fields, which the configuration system falls back on if it cannot find the field in the user's config file. I think this would be the preferred solution for me, but I cannot think of a neat way of packaging this YAML file. I would rather the user didn't have to copy or point to this file each time they set up a new project linking the static library.
I would provide the defaults in a YAML file in a global (i.e. non-user specific place) and allow to override the values with user-specific ones.
Consider just throwing an error if the global defaults are missing an entry, this will not happen by accident.
The global defaults you can put in /etc/default/YOUBLIBNAME.yaml. The user's configuration nowadays mostly follows the XDG base directory specification. For that use $XDG_CONFIG_HOME/YOURLIBNAME/config.yaml if XDG_CONFIG_HOME is set in the environment, if not set use $HOME/.config/YOURLIBNAME/config.yaml.
If your library has to work under Windows, I would put the user specific data under %APPDATA% in a subdir YOURBLINAME.

i have headers separately, how to import it to informatica target

I have source and target in an informatica powercenter developer. I heed some other header name to be imported in the target file automatically without any manual entry. How can I import customized headers to informatica target.
What have you tried?
You can use a header command in the session configuration for the target, I haven't used it, and couldn't find any documentation on it (i.e. what is possible and how, whether parameters can be used or not, etc.). I did test using (on Windows) an ECHO command to output its text to the header row, but it didn't seem to recognize parameters.
Or you can try to include the header as the first data output row. That means your output will have to be all string types and length restrictions may compound the issue.
Or you can try using two mappings, one that truncates the files and writes the header and one which outputs the data specifying append in the session. You may need two target definitions pointing to the same files. I don't know if the second mapping would attempt to load the existing data (i.e. typecheck), in which case it might throw an error if it didn't match.
Other options may be possible, we don't do much with flat files.
The logic is,
In session command, there is an option called user defined headers. Type echo followed by column name separated by comma delimited
echo A, B, C

Find member variable using Locator in Qt Creator

Qt Creator has the Locator box, which allows you to easily find classes, methods, etc. Is there a way to use it to find class member variables, as well?
Using . <expr> will show member variables too, but that is only for searching inside the current file, not globally.
This the Locator:
By default, there is not such feature, but as said in the doc you can create a filter (I can't test it now, but I'll try this soon):
To create a locator filter:
In the locator, select Options > Configure to open the Locator options.
In the Filter Configuration dialog:
Name your filter.
Select at least one directory. The locator searches directories recursively.
Define the file pattern as a comma separated list. For example, to search all .h and .cpp files, enter *.h, *.cpp
Specify the prefix string.
To show only results matching this filter, select Limit to prefix.
Click OK.
QtCreator have no such feature - member variables are not good candidates for pivot points in search. If you want find usages of particular member, use "find symbol usages" (Ctrl+Shift+U when cursor is under symbol). If you want to find members of particular type, use usual search in regular expressions mode, something like:
\w+\s*\*\s*\w+\s*;
And limit scope to headers only (i.e use "*.h" file mask).
Have you tried using the 'Advanced...' option in the locator? You can change the scope of the search to the Current Project, All Projects, Files on the System, etc. I use this to even search for strings I use for debug output in my code.