views:

109

answers:

4

Question: Can CMake generate build scripts that do not, in any way, use CMake? If not, how hard is it to gut a CMake generated automake script to not make any checks against CMake?

I am a big fan of CMake to the point where I am championing the idea that we transition to it in my current work environment. One thing that could ease this transition from our current build system to CMake would be if I could demonstrate that CMake can generate automake files that do not require cmake themselves.

Clearly, I would never want to do this for day to day use, but having the ability to easily create a branch of our code that can be built from source without requiring cmake would go a long way in helping me make my case.

+1  A: 

As someone who has taken a large complex piece of software and recently pulled out its existing build system, installing a new build system in its place. I can tell you that it's not easy, but I would definitely not want shell scripts as part of my build process, if they can be avoided. More and more systems will find themselves with CMake on them anyway, as more big name software packages like LLVM and KDE start using it—This is an area where it really accels, large projects.

One of the nice things about CMake is it builds things quicker. Resorting to have to fork shell instances to interpret a script really slows down the build process.

jer
+1  A: 

No, CMake cannot do this. It doesn't really make sense, either, since without any CMake-support at build-time, there would be no way to check or update the makefiles/project-files themselves when the CMakeLists.txt files have changed.

If you are moving from Visual Studio to CMake, you may want to take a look at vcproj2cmake.

JesperE
That is actually a "desired" consequence - I am interested in generating an auto tools "ready to distribute" kind of build, where make could be used to build the project without cmake dependencies of any kind - at that point, it is ok if changes are not reflected back in CMake.
Voltaire
That is a use case which CMake does not address.
JesperE
A: 

CMake generated files depend on cmake for various commands such as create / remove / etc... not just to regenerate the makefiles on a change so removing cmake is not going to work.

Oliver
A: 

What about the 'atomic solution' ?

EX- auto-generate a "QT moc" file from CMakeLists.txt, then build project that depends on the .cpp file being generated

# inside project level CMakeLists.txt 
# run shell script to create the "moc_GUICreator.cpp" auto-generated source file
if(UNIX)
execute_process(COMMAND "sh" ${CMAKE_CURRENT_SOURCE_DIR}/scripts/generate_moc.sh  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/scripts )
endif(UNIX)

Where the .sh file contains:

# generate_moc.sh
echo "generating moc file:  moc ../include/GUICreator.h  -o  ../src/moc_GUICreator.cpp "
moc ../include/GUICreator.h -o ../src/moc_GUICreator.cpp

Equivalent windows batch file, "moc_creator_win.bat":

moc "GUICreator.h" -o "moc_GUICreator.cpp"

Haven't tried this last bit in windows, but it or something very close should work, just after the if(UNIX) block in CMakeLists.txt:

if(WIN32)
execute_process(COMMAND "cmd" ${CMAKE_CURRENT_SOURCE_DIR}/scripts/moc_creator_win.bat  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/scripts )
endif(WIN32)

So, basically if you're clever you can do whatever you want from a script and use CMake variables as args to it, I'm not sure if you can ask for more...

the point is to avoid 'non-portable build types' unless you really need to hack it into a specialized compiler, or don't feel like using QT Designer to place the widgets ;-)

peter karasev
I'm not sure this is relevant to the original question.
Ilia K.
The point you can use CMake as intended, or at the opposite end of the spectrum, just wrap it around arbitrary scripts. There's nothing to stop you from parsing the cmake variables and generating whatever makefiles you desire...
peter karasev