Skip to content

Instantly share code, notes, and snippets.

@nd

nd/clion.md

Created Feb 24, 2019
Embed
What would you like to do?

In his streams Per updates the ion compiler while writing ion. To have a similar workflow in Clion:

Open the ion directory as a project - this will create CMakeLists.txt.

Change CMakeLists.txt with the following content

cmake_minimum_required(VERSION 3.13)
project(ion C)
 
set(CMAKE_C_STANDARD 11)
 
include_directories(.)
 
add_executable(ion main.c)

This allows to build and run the ion compiler.

To enable breakpoints in the ion files, add the *.ion pattern to C/C++ file types (Settings > Editor > File Types).

Let's say we want to debug the test1 package. Add the executable to CMakeLists.txt:

add_executable(test1 test1/out.c)

Create a new run configuration called 'test1' (Run > Edit configurations...> + > Application) and select test1 in its Target and Executable fields.

Create a run configuration 'compile test1' with Target and Executable ion, program arguments -o <path/to/test1/out.c> test1 and environment variables:

IONPATH=path/to/bitwise/ion
IONHOME=path/to/bitwise/ion

Add the 'compile test1' configuration to the 'Before launch' list of 'test1' after the 'Build'.

Now you can debug 'test1' configuration and it stops in ion breakpoints.

For some reason sometimes debugger doesn't show all local variables. You can evaluate them by name and add to watches.

@nd

This comment has been minimized.

Copy link
Owner Author

@nd nd commented Feb 24, 2019

Probably a better way without messing with run configuration dependencies is to write in CMakeLists.txt:

add_custom_command(
        OUTPUT  ${CMAKE_CURRENT_BINARY_DIR}/test1.c
        COMMAND IONHOME=${CMAKE_CURRENT_SOURCE_DIR} IONPATH=${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/ion -o ${CMAKE_CURRENT_BINARY_DIR}/test1.c test1
        DEPENDS test1/test1.ion
)
 
add_executable(test1 ${CMAKE_CURRENT_BINARY_DIR}/test1.c)

and create a single run configuration with Target and Executable 'test1'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment