I have an existing project (wvdial
) that has a working makefile. I'm trying to integrate it into our main build process which uses CMake. Can anyone advise on how to do this? I made an attempt below based on some of the other projects we build but the makefile is never called. All I want to do is call the makefile for wvdial and include the binary in the .deb
package we build.
cmake_minimum_required(VERSION 2.6) SET(COMPONENT_NAME roots-vendor-wvdial) SET(DEBIAN_PACKAGE_VERSION 1.6.1) SET(WVDIAL_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) SET(WVDIAL_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) SET(WVDIAL_INSTALLED ${CMAKE_CURRENT_BINARY_DIR}) ADD_CUSTOM_TARGET( wvdial ALL DEPENDS ${WVDIAL_INSTALLED} ) IF (${ROOTS_TARGET_ARCHITECTURE} STREQUAL "armhf") SET(TARGET_FLAG "--host=arm-linux-gnueabihf") ENDIF() ADD_CUSTOM_COMMAND( WORKING_DIRECTORY ${WVDIAL_BINARY_DIR} OUTPUT ${WVDIAL_INSTALLED} COMMAND env CXXFLAGS=${ROOTS_COMPILER_FLAGS} ./configure ${TARGET_FLAG} ${ROOTS_HOST_OPTION} COMMAND make COMMENT "Building wvdial" VERBATIM ) INSTALL( FILES ${CMAKE_CURRENT_BINARY_DIR}/wvdial DESTINATION usr/local/bin COMPONENT ${COMPONENT_NAME} PERMISSIONS OWNER_EXECUTE OWNER_READ OWNER_WRITE GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ ) DEFINE_DEBIAN_PACKAGE( NAME ${COMPONENT_NAME} CONTROL_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/debian/control CHANGELOG_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/debian/changelog )
CMake will create makefiles inside many of the folders inside a build directory and you can run make or make -j8 in any of these directories and it will do the right thing. You can even run make in your src tree, but since there is no Makefile in your source tree, only CMakeLists.
So, what is the real difference? CMake is much more high-level. It's tailored to compile C++, for which you write much less build code, but can be also used for general purpose build. make has some built-in C/C++ rules as well, but they are useless at best.
CMake generates a Unix makefile by default when run from the command line in a Unix-like environment. Of course, you can generate makefiles explicitly using the -G option. When generating a makefile, you should also define the CMAKE_BUILD_TYPE variable.
In converting an autoconf based project to CMake, start with the configure.in and Makefile.in files. The Makefile.in file can be converted to CMake syntax as explained in the preceding section on converting UNIX Makefiles. Once this has been done, convert the configure.in file into CMake syntax.
Take a look at the ExternalProject
module.
This will add a dummy target to your CMake project that is responsible for building the dependency. The command is quite complex and supports a lot of stuff that you probably won't need in your case. Kitware (the company behind CMake) did a nice post called Building External Projects with CMake 2.8 a while back explaining the basic use of that command.
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