I'm trying to pass an environment variable to an external project in my CMakeLists.txt without any success.
In this case, I have a dependency to mbedtls library which is downloaded and built in my cmake. In Linux this works as intended, however in a Windows environment, I need to pass a variable WINDOWS_BUILD=1 to the make environment.
I have tried to add a CONFIGURE_COMMAND to a batch file which sets this environment variable in the ExternalProject_Add(), however this does not work. If I manually go into the automatically downloaded mbedtls folder and write
$ make WINDOWS_BUILD=1
it works as intended, however I want to build everything from CMake environment. Any takes?
Related
I am trying to compile an Xcode project that uses scripts to build some external (go) code. These scripts were build with the assumption that their external dependencies are on the $PATH. However, I am so far unable to get Xcode to use a PATH environment variable that includes the additions I need.
Is there a way to do this WITHOUT having to edit the Xcode project itself or the scripts? (I really don't want to edit these as these are shared with a larger team)
I have tried to use the LaunchAgents approach suggested in for example https://support.shotgunsoftware.com/hc/en-us/articles/219042108-Setting-global-environment-variables-on-OS-X, but haven't had success with it.
Wherever the script is called in xcode, that call would have to be amended to include the desired environment variable- but you don't want to modify the project. I would suggest putting symbolic links to the external dependencies somewhere in the default $PATH, where your scripts are expecting them to be.
To give context (Unix MacOSX) I'm trying to link MKL with Eigen3. Everything works except for the fact that Clion can't run the executable that it builds, but I can manually run the Clion built exe in the terminal (./my_exe) (bash shell).
The error given is
"dyld: Library not loaded: #rpath/libiomp5.dylib"
Referenced from: /Users/MyUser/Desktop/ClionProjects/MyProject/cmake-build-debug/my_exe
Reason: image not found
I've tried setting the working directory to cmake-build-debug because that is where I am when manually running the exe through the terminal, no succes yet. I've checked the paths of the libraries and they seems fine (the ${DYLD_LIBRARY_PATH} does contain multiple paths, but one of them is the correct path, however if that was the issue why would it run fine in the terminal-shell?)
Additionally my unit tests support by BOOST won't run either.
Issue is solved! How (someone, not me) fixed it. CLion DYLD_LIBRARY_PATH was not set (all other environment variables were). When looking at the configuration of your target you can look at the list of environment variables. ->Edit configurations, click the ... next to Environment variables, you can then add one by clicking the + and you can see the current set for your target build by clicking show for me the DYLD_LIBRARY_PATH was not in this list,
so we manually added
DYLD_LIBRARY_PATH : /opt/intel/compilers_and_libraries_2018.1.126/mac/tbb/lib:/opt/intel/compilers_and_libraries_2018.1.126/mac/compiler/lib:/opt/intel/compilers_and_libraries_2018.1.126/mac/mkl/lib:/opt/local/lib:
To the executables environment variables when running the exe.
Tipically you use CC or CXX or similar variables to control and configure your build when using a configure script.
Assuming that I need a much more reliable configuration, I would like to use something with a "chroot-philosophy", meaning that I would like to configure and build my compiler in an environment that has no executables in the PATH and no other environment variables other then the ones that I'm explicitly passing.
There is a solution to sandbox this kind of builds ?
I would like to get an error from my build instead of default actions or having configure scripts picking executables from the system folders .
I'm trying to port some stuff at work over to cmake, and something that we do with our Windows installers (which currently use Inno Setup) does not appear to have a corollary in cmake/cpack. We have development libraries that get installed based on environment variables at installation time. So, the include files go to something like "%DEV_INCLUDE_DIR%/include" and the library files themselves go to something like "%DEV_LIB_DIR%/lib", and the environment variables DEV_INCLUDE_DIR and DEV_LIB_DIR are in the environment on the box when the installer is run. So, what they were on the box that the installer was generated on is irrelevant.
However, cmake seems to want all of that configured at compile time. It uses the install target to generate the package target for cpack, and you use the install commands to add stuff to be installed with the installer. And it doesn't work right if I try and put environment variables in the path. If I try
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/Include/" DESTINATION "%DEV_INCLUDE_DIR%/include")
then I end up with a %DEV_INCLUDE_DIR% folder in the CMAKE_INSTALL_PREFIX when the package is installed with the NSIS installer, which definitely isn't what I want. I want it to replace %DEV_INCLUDE_DIR% with the value of that environment variable at install time. And I can't find any way to do that. Does anyone know how to do that or if it's even possible?
Truth be told, I don't even what an install prefix in this case (everything gets installed based on the environment variables), but cmake seems to be built around the idea that there is one, and I was hoping that the install prefix would just be ignored (or worst case, create an empty directory) if every DESTINATION in the install commands was an absolute directory, but it's not treating the environment variables as either environment variables or absolute directories. And all of the ways that I can think to tell cmake to treat it as an environment variable (e.g. $ENV{DEV_INCLUDE_DIR}") would involve using the environment variable on the box that it's built on rather than the box that it's installed on. Is there any way to get cmake/cpack's install/package stuff to actually use the environment variables at installation time?
I'm using CMake 2.8.6 and the latest Intel C++ Compiler for a program which is compiled for Linux, MacOSX and Windows. For the development I'm using Eclipse with CDT on Linux and MacOSX.
Until recently I used CMake to create usual Makefiles which I ran from the console. To have a working environment, the Intel compiler comes with a shell-script called iccvars.sh which can be sourced to set all required include- and library-paths.
Now I decided to give the Eclipse-CDT build-system a chance and used the "Eclipse CDT4 - Unix Makefiles" generator of CMake to create an Eclipse project file. Everything works fine under Linux, but under OSX, Eclipse does not know about the environment variables and therefore paths like DYLD_LIBRARY_PATH are missing and the compilation stops because libraries are not found.
Update
Let me explain in more detail what I do. I'm running
cmake -G "Eclipse CDT4 - Unix Makefiles" path/to/src
from within the terminal where source iccvars.sh was executed and all environment-variables are set correctly. If I would have created a normal Makefile there and would run make, the compilation would succeed. This is because of the DYLIB_LIBRARY_PATH (in Linux LD_LIBRARY_PATH) is set correctly and I do not have to give -L/path/to/libs as option to the compiler.
But instead, I start Eclipse and import the created .project which works fine. The problem is that Eclipse do not know about my environment in the console and therefore cannot find the required libraries. One solution would be to use find_library inside CMakeLists.txt and locate every required library because then the full path should be included in the created Makefiles. Instead, I was wondering whether...
Question: Is there a way to source the iccvars.sh into my CMakeLists.txt so that the paths are available even when I'm not in my usual terminal-environment? Are there other possibilities?
Please note, that I know you can set environment variables for GUI-programs under OSX. What you have to do is to create a file environment.plist in your home under ~/.MacOSX. In this xml-file you put all your variables a GUI program should have. This works fine for other applications, but especially the Eclipse-builder seems to ignore this.