I'm building a cmake based build system for our product. The problem is that Visual Studio project, generated by cmake, doesn't display header files in solution browser.
What I need to add in CMakeList.txt to list header files? The preferred solution is where no need to list each particular header file.
Solution Here is a solution I came with:
file(GLOB_RECURSE INCS "*.h") add_library(myLib ${SRCS} ${INCS})
Thanks
Visual Studio looks for headers in this order: In the current source directory. In the Additional Include Directories in the project properties (Project -> [project name] Properties, under C/C++ | General). In the Visual Studio C++ Include directories under Tools → Options → Projects and Solutions → VC++ Directories.
To include headers in CMake targets, use the command target_include_directories(...) . Depending on the purpose of the included directories, you will need to define the scope specifier – either PUBLIC , PRIVATE or INTERFACE .
Place your caret on the first line of any C# or Visual Basic file. Press Ctrl+. to trigger the Quick Actions and Refactorings menu. Select Add file header. To apply the file header to an entire project or solution, select Project or Solution under the Fix all occurrences in: option.
Just add the header files along with the source files:
PROJECT (Test) ADD_EXECUTABLE(Test test.cpp test.h)
Or using variables:
PROJECT (Test) SET(SOURCE test.cpp ) SET(HEADERS test.h ) ADD_EXECUTABLE(Test ${SOURCE} ${HEADERS})
The basic trick to this is to add the header files to one of the targets (either executable or library). This is particularly irritating because cmake already knows all the header file dependencies and should take care of this for us. You can organize it further using the source_group command:
source_group("My Headers" FILES ${MY_HDRS})
Note that you have to do the same thing in Xcode too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With