To use an IDE, either pass -G"name of IDE" if CMake can produce that IDE's files (like Xcode, Visual Studio), or open the CMakeLists.txt file from your IDE if that IDE has built in support for CMake (CLion, QtCreator, many others). For older methods to do this folder layout, see However, the documentation does not say which directory to set it in, or why it is a DIRECTORY property. I tried it in the 3.6 RC and it works fine if I set the property in the top-level directory, so thanks for that. Note: If you need to support CMake < 3.8, I would recommend just protecting the above command, and only supporting nice folder layout on CMake 3.8+. a DIRECTORY property VSSTARTUPPROJECT which sets the start up project in Visual Studio. The prefix tells you where it puts it into the IDE structure, and the FILES option takes a list of files.ĬMake will strip the TREE path from the FILE_LIST path, it will add PREFIX, and that will be the IDE folder structure. In CMake 3.8+, you can do so very easily with a new version of the source_group command: source_group(TREE "$/ (because the command interprets paths relative to the build directory). However, if your on-disk layout is well designed, you might just want to mimic that. This way you have complete control over the folder structure. If you are using CMake 3.X your first choice for adding a preprocessor macro should be targetcompiledefinitions. You can explicitly list files with FILES, or use a REGULAR_EXPRESSION. The traditional way is source_group( "Source Files\\New Directory" REGULAR_EXPRESSION ".*\\.cp?") Open the CMakeLists.txt file in the project root directory. There are two ways, both using the source_group command. To set this linker option in a Visual Studio CMake project Because a CMake project doesn't have the usual Property Pages support, the linker option can be set by modifying the CMakeLists.txt file. You can also control how the folders inside targets appear. You can control how files show up in each folder with regular expressions or explicit listings in source_group: Folders for files Then, you can add targets to folders after you create them: set_property(TARGET MyFile PROPERTY FOLDER "Scripts") You have to manually enable the USE_FOLDERS global property to allow CMake to organize your files by folders: set_property(GLOBAL PROPERTY USE_FOLDERS ON) There are just a few extra things that can help IDEs perform even better. If you go by the prerequisite that MainProject is always first, you could simplify this a little: cmake_minimum_required(VERSION 2.In general, IDEs are already supported by a standard CMake project. Sure enough, if you would do this from scratch I would - as has suggested - use your own versions of those commands to allow global customizations. The problem is that every time I change the target, I have to reselect the startup project. Im a CMake newbie, but Ive gotten a project to debug targeting local machine, WSL and RPi. Set_property(GLOBAL APPEND PROPERTY GlobalTargetList $) I am trying to develop cross platform cpp code using Visual Studio 2022 Release Candidate and CMake. In your case - going by the assumption that you don't want to modify all 250 sub-project's CMakeLists.txt files - overwriting add_executable(), add_library() and add_custom_target() would do the trick: cmake_minimum_required(VERSION 2.8) as a global property).Įdit: It is now implemented: Global BUILDSYSTEM_TARGETS property was released with CMake 3.7 It works, but is there anything more elegant for this problem?Īt the moment (as per CMake version 3.5.x), there is - as far as I know - no global target list provided by CMake itself (e.g. Now this is not an elegant solution at all, as add_dependencies in MainProject has a LOT of dependencies in it. Basically, in order to make Visual Studio to check for dependencies for all 250 projects or so, I have to add all the other projects in the main project as dependencies. Obviously this is a very simplified example, but hopefully the idea is there. My CMakeLists.txt files look like this.Īdd_dependencies (MainProject ProjectA ProjectB. So basically, Visual Studio should check for all 250 projects for changes when MainProject is compiled (and run). It's important that all projects are up to date when the main project is run. In my project, I have about 250 projects with one main project that uses most of the projects.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |