Skip to content

Instantly share code, notes, and snippets.

@vietlq
Last active April 13, 2017 20:08
Show Gist options
  • Save vietlq/f3c33a710d26dee096dc81556c6ddbd9 to your computer and use it in GitHub Desktop.
Save vietlq/f3c33a710d26dee096dc81556c6ddbd9 to your computer and use it in GitHub Desktop.
Code2Pro: How to Generate Eclipse CDT Project Files Using CMake

Code2Pro: How to Generate Eclipse CDT Project Files Using CMake

Scope

Tested with CMake & Eclipse on Ubuntu 16.

Steps

  1. Create a folder for Eclipse
  2. Run CMake with -G "Eclipse CDT4 - Unix Makefiles" in the Eclipse folder & out of the source code folder
  3. Open Eclipse, import the project via "General", select generated Eclipse project folder
  4. Code & run

To keep things simple, I provided a Makefile and you can copy it to the same folder with CMakeLists.txt and then run:

make eclipse

# To delete the generated eclipse folder:
make eclean

NOTE: Eclipse CDT4 needs special CMake flag so it could index C++11 headers with proper C-processor defines. Make sure you pass -DCMAKE_CXX_COMPILER_ARG1=-std=c++11 to CMake.

References

.PHONY: all init build clean bclean rebuild fresh eclipse
PROJECT_DIR=$(shell pwd)
BASENAME=$(shell basename `pwd`)
BUILD_DIR=${HOME}/projects/_build/build-${BASENAME}
ECLIPSE_ROOT=${HOME}/eclipse/workspaces
ECLIPSE_PROJ=${ECLIPSE_ROOT}/cproject-${BASENAME}
all: init build run
rebuild: clean build
fresh: bclean all
init:
mkdir -p ${BUILD_DIR}
cd ${BUILD_DIR} && cmake -G Ninja ${PROJECT_DIR}
ln -f -s ${BUILD_DIR} .build_ninja
build:
cd ${BUILD_DIR} && ninja
run:
$(info Running: ${BUILD_DIR}/${BASENAME})
${BUILD_DIR}/${BASENAME}
clean:
cd ${BUILD_DIR} && ninja clean
bclean:
rm -rf ${BUILD_DIR} .build_ninja
eclipse:
mkdir -p ${ECLIPSE_PROJ}
cd ${ECLIPSE_PROJ} && cmake -G "Eclipse CDT4 - Unix Makefiles" -DCMAKE_CXX_COMPILER_ARG1=-std=c++11 ${PROJECT_DIR}
ln -f -s ${ECLIPSE_PROJ} .build_eclipse
eclean:
rm -rf ${ECLIPSE_PROJ} .build_eclipse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment