Can one use CLion macro's in Run/Debug Configurations? - cmake

I have added a GDB Remote Debug via CLion to debug my nRF52 chip but in order to debug the gdb needs a symbol (.out) file. This symbol file name changes when the projects file name changes aswell, so I want to add a macro from CMake, such as ${PROJECT_NAME} or something. I have tried using $ProjectName$.out but it looks like CLion does not recognize this. .
Does such a feature exist?

For anyone wondering, I figured out that you cannot, however it turned out you need CLion EAP (Early Acces program, in order to debug remotely with Embedded GDB Server. One can download it here.

Related

Using CMake in Embarcadero

I am trying to get CMake to work with Embarcadero 10.2.3 (Tokyo). I see a some help and blogs. I looks fine (I haven't tried so far), but I get confused about the existing cbproj file that I have. I get the impression that I need a CMake file list (CMakeLists.txt) as well as a cbproj file, if I need to build from the IDE. So in that case, any time I need to add files or settings I need to do in both. Is this true?
Thanks.

How to setup CLion to use waf as build system

I am trying to configure my Intellij Clion IDE for working with ns-3. Since ns-3 is using waf, it is more tricky than i thought and would be really happy to hear any advice
CLion supports compilation databases for quite some while, which waf, luckily, is able to generate using the clang_compilation_database extension.
You'll need to load it within your configuration and option step; i.e. like this:
def options(ctx):
# Assuming you just copied the script into a directory called tools
ctx.load('clang_compilation_database', tooldir='tools')
# ...
def configure(ctx):
ctx.load('clang_compilation_database', tooldir='tools')
# ...
Now you can call waf clangdb; you'll be presented a file called 'compile_commands.json' in your build directory.
CLion only uses cmake for its internal project definition - so you have to have a cmake config.
It can be very simple and mirror parts of another build system you actually use, but how CLion treats files and what it does when you tell it to build something is defined by cmake and only cmake.
You could setup compilation databases as suggested by Julian or you could try my fork, if you don't mind using a not completely up-to-date fork of the upstream project. https://github.com/Gabrielcarvfer/NS3.
Visual Studio can also be used with CMake projects and WSL, but ClangCL/MSVC support is being worked on.
I plan on opening a MR to upstream the CMake support, but it is a lot of work to replace Waf completely.

Clion CMakeLists.txt not found when switching PC

I'm having issues with Clion (1.0.1) and CMakeLists.txt.
I use GitHub for my projects, and I commit them from directly within the IDE. If I then checkout the project on a different computer, the IDE looks for CMakeLists.txt in the original PC's directory.
The specific error message reported by Clion is this:
Error: CmakeLists.txt not found in C:\Users\Chris\ClionProjects\SDLTestClion
However, this is a Linux machine, so there's obviously no C drive.
Here's what I've tried:
File > Invalidate Caches/Restart
Change Project Root (from the CMake Window; the obvious solution)
File > Settings > Build, Execution, Deployment > CMake
There are no settings or variables here that indicate the directory above.
I can't find anything else, so either I'm missing something or this is bugged in version 1.0.1 and I need to sift through project files to change the path that Clion looks for the CMakeLists.txt file.
Well, I found the issue. As far as I can tell, in version 1.0.1 there is no way to remedy the problem through the IDE.
Solution:
Go to projectDir/.idea
Open misc.xml
Edit the field PROJECT_DIR to point to the directory with the project's CMakeLists.txt.
I think this is a bug and this field should probably be updated when choosing a new project root. A temporary solution may be to add misc.xml to .gitignore but I haven't tested this and don't know if this will cause other problems or if the IDE will automatically regenerate the file.

How do I change the working directory for my program

Trying out the Clion EAP on the Mac. How does one change the current working directory for a launched program? It appears to be set to the output directory of the binaries.
This can be changed via the Run -> Edit Configurations... dialog, just like Idea.
The mix of needing to make changes to CMakeLists.txt for so much of the configuration just threw me, and I've been hunting for a way to change it there, but this bit at least is consistent with the other IDEs, which is good.
Hopefully they'll improve the rest of the Project Settings in a similar fashion.
The "Working Directory" is where the executable starts. Modifying the "Working Directory" in the Configurations setting tells Clion to change to the "Working Directory" after the executable starts execution.
If you want to change where the executable starts execution you will need to add a line to the CMakesLists.txt file.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_executable(TimeServer ${SOURCE_FILES})
Position in the cmakes file is important. If you add the set command after the add_executable it will not work. It must come before.
These answers are relatively old. Not sure when the feature was added but there's a very nice UI way to set the current working directory now.
I made a YouTube tutorial for my COSC1030 (Beginning C++) students but the solution is the same for everyone:
https://youtu.be/dTtZEAfh_LM
If you know your CLion fairly well and don't need a demo, here's a short-hand version: Edit Configurations (from drop-down menu at top right of screen), enter the directory you want to use in Working Directory or select via "..." pop-up.

IntelliJ can't detect openjdk source, even though it's listed in project sources [duplicate]

How can I step through JDK source code in IntelliJ IDEA 7 and see the debug info? I can currently hit breakpoints and step through the code, but the debug info is not available. This means I can't see the value of local variables.
I only want to step through the source code of one class, if that matters.
For what it's worth, it's the javax.swing.text.html.HTMLDocument class and I do have a copy of the corresponding .java file.
If you look in [File menu ->] Settings -> Debugger -> Stepping you will see a list "Do not step into these classes", probably with "java.*" listed there. Is that the case? You can turn that off there.
Apparently the debug information is not available. According to this thread:
Sadly the JDK classes have debug information for parameters and local variable stripped off.
Years ago I filed a request that Idea should deduce the necessary information from the source code (basically converting variable names to indexes into the methods local var):
Debugger: Show variable information when no debug info
Please vote/comment.
As a workaround you can re-compile the JDK from sources, but you need to exclude some classes which do not have all needed source code attached.
Interestingly, you can download the beta version of Java 6u18, which has debug information in it (in the DEBUG bundle).
UPDATE: IntelliJ IDEA 13+ version can provide local variables information without debug info.
Java classes which are part of the JDK are compiled without debug info for the size and performance reasons. If you want debug info in these classes, you'll either need to install a development version of the JDK where the classes are built with the debug info or rebuild the parts of JDK you want to debug from source with the debug info enabled and configure the new JDK with these versions of classes in jars.
This thread provides the instructions how to rebuild JDK classes in rt.jar from the source code with debugging information.
P.S. This question is not specific to IntelliJ IDEA.
Install the JDK
OSX download: https://developer.apple.com/downloads
Windows download: http://www.oracle.com/technetwork/java/javase/downloads
Add src.jar path
Go to: Project Structure (Project Settings) > Platform Settings > SDKs > Sourcepath
Add the path to src.jar
OSX example: /Library/Java/JavaVirtualMachines/1.6.0_45-b06-451.jdk/Contents/Home
Windows example: C:\Program Files\Java\jdk1.7.0_03 (check Program (x86) for 32-bit)
Wait a long time for indexing!
Remove debugger filter
Go to: Settings > Debugger > Stepping
Uncheck the package(s) you want, e.g. javax.*
Along with the "Do not step into these classes" information, the src.jar should be configured. Right-click the project, select "Open Module Settings." Under Platform Settings, select "SDKs." Select the Java SDK version you're using. Select the Sourcepath tab, hit the "+" button, and add your src.jar from the JDK (or the separate source download for the OSX JDK). This will let you open JDK classes and step into them while debugging.
I did this on my Mac to get my Android source code but a similar approach should work for you.
File > Project Structure
Selected "SDKs" under Platform Settings.
Selected "Android SDK"
Selected "Sourcepath" tab
Pressed "+"
Browsed to location of my Java source code
you can find the source code from External Libraries --> rt.jar
setting - compiler - java Compiler - java options, you should check the option "generate debugging info", then, it will compile with debug info.