Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get CMake to use existing Makefile?

Tags:

makefile

cmake

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     ) 
like image 905
SeanLabs Avatar asked Aug 21 '13 00:08

SeanLabs


People also ask

Can CMake run Makefile?

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.

Can I use CMake instead of make?

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.

How does CMake generate Makefile?

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.

How do I convert to CMake?

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.


1 Answers

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.

like image 196
ComicSansMS Avatar answered Sep 25 '22 07:09

ComicSansMS