Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert from Xcode to CMake

I have a C++ project that I initially developed using Xcode on my Mac and I would like to set up the very same project using CMake. The project makes use of some external libraries, including eigen and boost. Xcode has a rather long list of Build Settings, including paths to external libraries, specification of the compiler version, additional linker flags, compiler optimization level, etc... and I am wondering where all of this information goes in the CMakeLists.txt file. I've searched extensively for help on this but have found precious little. I am new to CMake and have never written make files before. If there were a utility that could convert my Xcode project into a CMake project, that would be ideal. But I would be very glad to know of a tutorial on this, or to have some specific guidance. Any help on this would be greatly appreciated.

like image 972
Aaron Schurger Avatar asked Oct 29 '22 22:10

Aaron Schurger


1 Answers

Conversion Strategy

I am pretty sure that the easiest and fastest way to move to CMake is a mixture of looking at comparable projects that link the same dependencies, and maybe copying a few relative file paths to your source files from XCode. A well-written CMakeLists.txt that uses Eigen and Boost can be very small (and platform-independent).

One reason for this is CMake has a very different way to use dependencies. For well-known libraries such as Boost, CMake includes scripts to include headers and link libraries.

Minimal CMakeLists.txt

A minimal example may look like this:

find_package(Eigen3 REQUIRED)
find_package(Boost REQUIRED COMPONENTS system)
add_executable(
  app
  src/main.cpp
)
target_include_directories(
  app
  ${Eigen3_INCLUDE_DIRS}
  ${Boost_INCLUDE_DIR}
)
target_link_libraries(
  app
  ${Boost_LIBRARIES}
)

Example Projects

For Eigen, there is no such pre-installed script that can be called by find_package. Here are two real-world example projects that link Eigen and Boost: https://github.com/ompl/ompl/blob/master/CMakeLists.txt https://github.com/roboticslibrary/rl

Here is an example for a find script for Eigen.

As a piece of advice, some CMake projects are out there are convoluted and use old syntax, newer project files tend to use small letters in commands.

like image 141
SpamBot Avatar answered Nov 02 '22 23:11

SpamBot