List of hacks to make CLion usable

Hi

This is life hacks I am using for CLion. I hope one day CLion will support all of them naturally. Maybe somebody will find them useful.



1. Disable build types, cause they are completely useless.

set(CMAKE_CONFIGURATION_TYPES "Debug" CACHE STRING "" FORCE)



2. Automatically link CLion private build dir to build dir inside project:

if (CMAKE_CURRENT_BINARY_DIR MATCHES clion)
    EXEC_PROGRAM(rm ARGS -rf ${CMAKE_SOURCE_DIR}/build)
    EXEC_PROGRAM(ln ARGS -s ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/build)
endif(CMAKE_CURRENT_BINARY_DIR MATCHES clion)



3. Fix build script to go to build dir by absolute path.

cd `readlink -f ./build` && make -j




4. Put binaries and libraries output in different folders:

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/lib")




5. Automatically create new CLion internal dir inside project. The clion.sh file content:

#!/bin/bash

cd $(dirname $0)
mkdir -p .clion
cd .clion

IDEA_BIN_DIR=/usr/local/clion
IDEA_MAIN_DIR=$(pwd)
IDEA_PROPERTIES=$IDEA_MAIN_DIR/idea.properties

cp $IDEA_BIN_DIR/idea.properties $IDEA_PROPERTIES

echo "idea.config.path=$IDEA_MAIN_DIR/config" >> $IDEA_PROPERTIES
echo "idea.system.path=$IDEA_MAIN_DIR/system" >> $IDEA_PROPERTIES
echo "idea.plugins.path=$IDEA_MAIN_DIR/config/plugins" >> $IDEA_PROPERTIES
echo "idea.log.path=$IDEA_MAIN_DIR/system/log" >> $IDEA_PROPERTIES

export CL_PROPERTIES=$IDEA_PROPERTIES

$IDEA_BIN_DIR/clion.sh



6. Call 'make install' from CLion

ADD_CUSTOM_TARGET(run_install COMMAND ${CMAKE_MAKE_PROGRAM} install)



7. Call 'make test' from CLion

  No workaround found so far. THe problem is that CLion somehow perevents creation of 'tests' target.

3 comments
Comment actions Permalink

update:
  added #6 and #7

0
Comment actions Permalink

On #7: Does CLion really prevent you from making any target with "test" in the name? Does

    ADD_CUSTOM_TARGET(run_test COMMAND ${CMAKE_MAKE_PROGRAM} test)

not work? Does it not work because of the target name? How about you name it "check" instead of "test"?

 

0
Comment actions Permalink

The problem with #7 is not that CLion prevents 'test' as the name of a target.  Any version of CMake after 2.8.12 has some restrictions on the names that can be used for targets.  See CMake Policy CMP0037 for more details.

0

Please sign in to leave a comment.