I'm just getting started with cmake, I've read some tutorials and got the basic stuff working.
However currently my CMakesList.txt generates a Makefile that has every .cpp explicitly named. That means, whenever I add a new .cpp to my project, I need to rerun cmake, before I can make. While this is not a huge deal, it's still a bit annoying.
Since Makefiles can do something like SOURCES=*.cpp
, I thought there's probably a way to tell cmake to generate the Makefile with such a rule!?
I know I can do
cmake_minimum_required(VERSION 2.8)
file(GLOB SRC
"*.h"
"*.cpp"
)
add_executable(main ${SRC})
but with that I still have to rerun cmake.
As far as I know, the way to do it is as you have said and the downside is that you have to run cmake every time you add a file.
What I usually do to overcome this is to make a custom target that calls cmake as well. It goes like this
ADD_CUSTOM_TARGET(update
COMMAND ${CMAKE_COMMAND} ${CMAKE_SOURCE_DIR}
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target all
COMMENT "Cmake and build"
)
With this you may call make update
and it will call cmake first which captures all the files and then starts the build process.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments