Append bin folder to PATH environement variable after installation - c++

I have done a C++ program for Windows and an NSIS installer using CPack.
I want that after the installation, the user can call my program from the terminal without giving the whole path of the exe.
Sometimes some installers even add an Add useful environment variables checkbox at the end of the installation to give the user a choice.
Is it possible to add to the PATH environment variable the path to our bin folder at the end of the installation using CPack and NSIS Generator?
If this is not possible, how do other programs add environment variables during installation?

As always, check the documentation... https://cmake.org/cmake/help/latest/cpack_gen/nsis.html
CPACK_NSIS_MODIFY_PATH
   Modify PATH toggle. If this is set to ON, then an extra page will appear in the installer that will allow the user to choose whether the program directory should be added to the system PATH variable.
Note that this is hard-coded to be the $INSTDIR\bin path and is not configurable. In particular, setting CMAKE_INSTALL_BINDIR to anything other than bin will break.

Related

Setting up bazel as an environment variable windows

I've been trying to use bazel on Windows 10 Pro, and I was following the instructions located at https://docs.bazel.build/versions/3.7.0/install-windows.html
I found the place to add user-specific and system-wide environment variables, and I added the path to bazel.exe and called the variable bazel, but when I try to type bazel into a command prompt window, it still isn't recognized.
Let me know if you need any more detail to help answer my question, I'm confused where I'm going wrong.
I think that you have to add the bazel binary path to your 'path' environment variable.
So search for Edit system environment variables -> Advanced -> Environment variables
and then under System Variables -> path -> edit you can add the path of your bazel bin (C:\User\Panda\Documents) and it should work. Detailed description with screenshots it's here: https://www.architectryan.com/2018/03/17/add-to-the-path-on-windows-10/
You are trying to use bazel as a command, not as an environment variable. When you want to use the value of an environment variable, you need to surround the name in %s, ie:
C:\Users\Panda>%bazel% version
UPDATE: otherwise, since the .exe file you want to execute is also named bazel, it can be executed as a command, you would just need to add the path to bazel.exe's installation folder (C:\Users\Panda\Documents) to your system's %PATH% environment instead 1, as #Fed's answer explained, and then you can execute bazel normally:
C:\Users\Panda>bazel version
1: I don't recommend installing apps in your user profile's Documents folder! You should create a new folder for installing bazel into, preferrably under C:\Program Files (64bit) or C:\Program Files (x86) (32bit). Then you can add %ProgramFiles%\bezel\ to your %PATH% environment.

Relative path of Cpack installed application (windows)

I have an application that need to access some files in a folder located inside the application directory.
myAppDir
|-bin/myApp.exe
|-scripts/need_to_find_this_file.py
I can't use configure_file(...) or other hardcoding method because they are processed at cmake-time.
I can't even have access to the installation directory choosen by the user because not an information that can be accessed by cpack.
How could I retrieve the path ~/myAppDir/scripts at the run-time? I want to use it inside my c++ code.

Link qt dlls to multiple executables

I have four different .exes in differend subdirs of one specific directory. All of the programs need the exact same .dlls (Qt5Core, Qt5Gui and Qt5Widgets). Is there a way of having theese three .dlls just in the root directory insted of having to copy them into each subdirectory?
Here you find the order in which DLL paths are searched on Windows:
Since Safe DLL search mode is enabled by default, the order is
The directory from which the application loaded.
The system directory. Use the GetSystemDirectory function to get the path of this directory.
The 16-bit system directory. There is no function that obtains the path of this directory, but it is searched.
The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
The current directory.
The directories that are listed in the PATH environment variable. Note that this does not include the per-application path specified by the App Paths registry key. The App Paths key is not used when computing the DLL search path.
So the easiest thing to do is to ensure that you run your app from the working directory where you put the DLLs (5.). That could be done by writing a starter .bat file that navigates there first and then runs the application relative to the DLL direcory.
The other way would be to add the DLL directory to PATH in a starter .bat file (6.).
In both cases you need a wrapper script for each .exe that you want to run.
You could avoid that if you can make sure that links to the application set the working directory properly. This would work if you have an installer creating the shortcuts for the user and you know the user will not create one himself by just right-clicking the .exe.
There might also be a way using hardlinks or junctions but I don't know if you can copy and deploy those like symbolic links on Linux or if you need to create them on the target system.
Yes, you are using Windows and you can add your root directory as a path in Environment Varibles from
Computer-> Properties->Advanced System Settings -> Environment Variables

Set QT base directory through system variable

I've compiled QT and copied it over to a network drive. But now I've got the problem that the platform plugins are only found on my computer because it seems that those path got compiled into the binaries. How can I make QT to look into another directory? I thought that the system variable QTDIR should work but it gets ignored completely. Also tried to add a bunch of directories to the PATH variable which didn't work either.
I need a solution which is useable without changing the code itself.
If you need to load Qt plugins from different path you must use environment variable QT_PLUGIN_PATH.
Qt also looks for the plugins in directories relative to the path where the executable is installed. You need to properly deploy your applications, and you definitely don't need to copy the entirety of Qt anywhere. You also don't need to set QT_PLUGIN_PATH - it's a workaround for a simple problem.
Ideally, as part of your application's release build process you should be creating an installer, and that installer would then handle putting all the plugins into the application's installation folder.

How do I add the MinGW bin directory to my system path?

I am using Windows XP. I am trying to add a new library to Dev-C++. For that, I need to install MinGW and then I have been instructed to add the bin directory of MinGW to my system path. But, I don’t know how to do it. Please guide me (step by step) to add this to my system path.
To change the path on Windows XP, follow these instructions, and then add the directory where you install MinGW plus bin. Example: if you install MinGW in C:\ then you have to add C:\mingw\bin to your path
Just for completeness here are the steps shown on the link:
From the desktop, right-click My Computer and click Properties.
In the System Properties window, click on the Advanced tab.
In the Advanced section, click the Environment Variables button.
Finally, in the Environment Variables window, highlight the Path variable in the Systems Variable section and click the Edit button. Add or modify the path lines with the paths you wish the computer to access. Each different directory is separated with a semicolon as shown below.
C:\Program Files;C:\Winnt;C:\Winnt\System32;c:\mingw\bin