To those in a similar situation, I did the following to share my code between Mac and Linux.
As I said, CLion uses CMake. I thought there would be a lot going on under the hood but it turns out all you need to compile your source files is the CMakeLists file, and an installation of CMake itself.
CLion generates the CMakeLists file, but it can be written from scratch and it only needs around 5 lines to begin compiling. In it, you declare the source files you wish to include in compilation, and a few other things, like minimum CMake version and the version of C++ your project uses.
There's a good explanation of what goes into the CMakeLists file here.
My Linux machine runs Ubuntu, and the version of CMake I was using was 2.8.something - quite early compared to 3.6 on my Mac. So firstly this meant I had to change cmake_minimum_required(VERSION 3.6)
to 2.8
.
Then I tried running cmake .
in the directory containing the source files, which threw up a load of compile errors to the terminal. Most of which concerned things like template classes and curly brace initialisation - features of more recent versions of C++.
This was because CMake's set(CMAKE_CXX_STANDARD 11)
syntax, which sets the project's C++ version, wasn't around in CMake 2.8. Replacing this line with set (CMAKE_CXX_FLAGS "-std=c++11")
fixed this issue.
Another cmake .
worked just fine, which then spat out a load of files into the source directory. I'm not entirely sure what all of them do, but they all surround a generated 'Makefile'. Running make
in the same directory compiles all of the source files and outputs an executable, which worked perfectly.
The ncurses
library seems pretty baked-in to Unix-like/based systems, so I was able to use and compile this library by simply #include
ing it in my code. 3rd party libraries might require a bit more work!