Cmake set variable from command line8/19/2023 ![]() ![]() ![]() The contents of a sample from one of my projects can be seen below. I’d like my users to be able to set various variable values on the command line. The convention in CMake is to have your config in a file named CMakeLists.txt, at the root of your project. It should be simple enough to understand yet display the capabilities of tools like CMake. CMAKEBINARYDIR The path to the top level of the build tree. ![]() and so on, up to the number of command line arguments given. It then also sets CMAKEARGV1, CMAKEARGV2. So to illustrate how CMake works in a small example, I have copied a CMake config I use in my projects. When run in -P script mode, CMake sets this variable to the first command line argument. When CMake starts processing commands in a source file it sets this variable to the directory where this file is located. For example, you could use them to maintain both a Makefile on Linux and a Visual Studio project on Windows. I chose CMake as it seems the more mature of the build management tools as well as having a large adoption rate meaning a lot, if not most, 3rd party libraries have CMake configs readily available.įor anyone that hasn’t heard of or used Premake, CMake or any of the other build tools before, they are essentially tools that can be configured based on your development environment and can then either build your code, or more likely produce project files for other tools such as IDE’s. The user can also initialize or change cache variables using the cmake commandline with the -D parameter. As of recently I have been picking up C++ again, and having used Premake in the past, I thought it would be a great time to try out a new build management tool. ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |