Get file of current macro file in CMake [duplicate] - c++

This question already has answers here:
In CMake, how can I find the directory of an included file?
(4 answers)
Closed 4 years ago.
I'm writing a .cmake file that handles a bunch of stuff and needs access to an executable in a fixed relative path to the .cmake file. In this instance, the orgianization looks like this:
CMakeLists.txt
- cmake
- tools.cmake
- bin
- exectuable.exe
The issue is that tools.cmake is included using include and thus, CMAKE_CURRENT_SOURCE_DIR returns the directory of the CMakeLists.txt. The reason I don't want to hardcode the path is that I want to put the tools.cmake and binary in a separate GIT repository and I don't want to force the user to place it in some specific folder.
Only solution I can come up with right now is to supply a function that sets and stores the path to tools.cmake. That's not really elegant.

Answered here: https://stackoverflow.com/a/12854575/2532768
CMAKE_JUCE_TOOLS_PATHdoes not return the correct path within functions or macros in tools.cmake but it results in the correct path outside any function. So one can us
set(PATH_TO_TOOLS_CMAKE ${CMAKE_JUCE_TOOLS_PATH})
to store the path while it can be accessed in a variable and than access PATH_TO_TOOLS_CMAKE in functions and macros

Related

Ignore other library files in GitHub so they do not appear in project's (programming) Languages [duplicate]

This question already has answers here:
Is it possible to exclude files from git language statistics?
(2 answers)
Closed 2 months ago.
Solution:
Create .gitattributes in git folder and paste linguist-languate=text after the file path. Example:
/other_libraries/* linguist-language=text
/linguist_ignore.c linguist-language=text
Note: linguist-vendored=false didn't solve the problem. GitHub still detected marked files as C code.
Problem:
My C++/OpenGL project is compiled using glad.c, and stb_imbage.h is included in mail.cpp file. Both located in root folder which contains .git directory. These two files have to be present in order to compile the project, so I want to keep them.
Issue: GitHub indexes these files and adds them to Language statistic. It is undesirable since it is not the files containing my code.
How do I keep certain files tracked by Git but exclude them from Languages?
I've tried looking for solution in GitHub docs about Linguist and Stack Overflow but without success.
I know how to ignore files using .gitignore. But it's not the solution since ignored files just won't be commited.
GitHub uses Linguist library to generate the language stats.
At https://github.com/github/linguist/blob/master/docs/overrides.md you can read about the ways to override the default behavior using a .gitattributes file. It looks like the following section fits your case the most:
Vendored code
Checking code you didn't write, such as JavaScript libraries, into your git repo is a common practice, but this often inflates your project's language stats and may even cause your project to be labeled as another language. By default, Linguist treats all of the paths defined in vendor.yml as vendored and therefore doesn't include them in the language statistics for a repository.
Use the linguist-vendored attribute to vendor or un-vendor paths:
(exmaple follows)

Include instructions from other file in CMakeLists.txt [duplicate]

This question already has answers here:
How to include an additional CMakeLists.txt
(2 answers)
Closed 10 months ago.
I want to create a second file, for example Instructions.txt, and be able to include it's CMake instructions to the main CMakeLists.txt, for example:
// Instructions.txt
set(MY_VARIABLE value)
set(MY_SECOND_VARIABLE 1234)
// CMakeLists.txt
<HERE INCLUDE INSTRUCTIONS.TXT>
// And be able to use those variables, for example
project(MY_VARIABLE)
You usually do that simply by using another cmake.
Contrary to what you might believe, the file extension is different for other file than build files.
Let's call this file instructions.cmake:
set(MY_VARIABLE value)
set(MY_SECOND_VARIABLE 1234)
Then you can include it like this inside your CMakeLists.txt:
include(instructions.cmake)
If the file is in the module path, you can include it like that:
include(instructions)
There are some other filename that are important for CMake though.
For example, any file that start with Find then ends with .cmake like FindXYZ.cmake, the XYZ part is assumed to be a package name and in that case you should use find_package(XYZ REQUIRED).

Using 'rename' command for all files in subfolders [duplicate]

This question already has answers here:
Rename files and directories recursively under ubuntu /bash
(8 answers)
Closed 5 years ago.
I am using this command to replace a word with another in many filenames (batch):
rename 's/oldname/newname/g' **
But it works for the current open folder only. I am not sure how to make it work for that directory and all the sub-directories.
Thanks.
Mike,
Try this: Create new folders, move files, delete old folder. Then, move over directories.
Regards

Is it possible to include csv file as part of python package [duplicate]

This question already has answers here:
How to include package data with setuptools/distutils?
(14 answers)
Closed 6 years ago.
Is it possible to include a csv file as part of python package?
I am creating a package and want some default config files which are imported at runtime.
I know I can store as a list or other structure in a .py file, but this will break the pattern I'm building against.
This can be done in a two-step process, as detailed here.
You need one file in the root of your source, MANIFEST.in which reads:
include path/to/yourfile.csv
and you also need to add include_package_data=True, to the setup() function in setup.py.
Tried and tested.
I guess that you may use a specific module more than an "homemade version" to store configuration.
In your case:
The Python standard library includes the ConfigParser module, which handles ini-style configuration files for you.

How to install programs on Linux from a makefile? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
What should Linux/Unix 'make install' consist of?
I'm making a program that can be invoked from the command line, like ./prog arg1 arg2. I was wondering, how can I make it so that I can run it from anywhere on the system? I know that I could put prog into /usr/bin/, but what if my program needs resources from its install directory (that can be wherever the user downloaded it)?
put the directory in which your program resides into the path environment variable or move your program into one of the directories already in path (usually requires superuser permission, which I gather you don't have for then you wouldn't ask this question).
to add a directory to the front of the search path and have the system refresh its database on tcsh, say
setenv "my/directory:"$PATH
rehash
on bash, I think, it's
PATH=/my/directory:$PATH
export PATH
(no need to rehash). Note that the above commands put your directory at the top of the search path, i.e. these will be searched before any other. Thus, if your program is called "gcc", then your program will be executed rather than the GNU C compiler. Alternatively, you can add your directory to the end of the search path, in which case your program will only be picked up if no other program of the same name is found in any of the other directories in the search path.
You probably also want to become familiar with the Linux Filesystem Hierarchy: the standard definition for "what goes where". Here's more information:
https://superuser.com/questions/90479/what-is-the-conventional-install-location-for-applications-in-linux
Environment variables can be defined globally ("for everybody", e.g. /etc/profile), or locally ("per user", e.g. ~/.bashrc). Here's a good summary of some of your options:
https://wiki.archlinux.org/index.php/Environment_Variables
When you execute a programme using prog arg1 arg2, it's thanks to your shell, which search in the $PATH environement variable for folders where programs are. (Try env | grep PATH to see those folder).
You need eather to add a new directory in this variable (export PATH="/new/directory/path/:$PATH" if under bash, setenv PATH "/new/directory/path/:$PATH" if with tcsh) or copy your program and all the files it need to execute in one of the PATH folder.
There are two ways of dealing with this (and Makefiles have nothing to do with them)
Your installer could just put the files where it wants them, so your program doesn't have to search -- it can use hardcoded paths. Or you could put the path to the data directory into yet another file, which would be hardcoded (like /etc/programname.config).
You put all your stuff into one directory (often something like /opt/programname). You can hardcode that too, of course, or your program can readlink() the /proc/pid/exe file for a good chance (no guarantee, though. In particular, it works if for example a symlink is used to point from /usr/bin/programname to your /opt/programname/bin/programname or whatever, but it won't work if that's a hardlink)
to get the path to the executable. From there you should be able to reach your data files.
If prefer the second solution, but that's just me. The first solution works well with package managers, and it's less overkill if you don't really have a lot of data files.