1 
  2 #  Intellij and Clion
  3 ----
  4 
  5 * [Contents](hat-00.md)
  6 * House Keeping
  7     * [Project Layout](hat-01-01-project-layout.md)
  8     * [Building Babylon](hat-01-02-building-babylon.md)
  9     * [Building HAT](hat-01-03-building-hat.md)
 10 * Programming Model
 11     * [Programming Model](hat-03-programming-model.md)
 12 * Interface Mapping
 13     * [Interface Mapping Overview](hat-04-01-interface-mapping.md)
 14     * [Cascade Interface Mapping](hat-04-02-cascade-interface-mapping.md)
 15 * Implementation Detail
 16     * [Walkthrough Of Accelerator.compute()](hat-accelerator-compute.md)
 17     * [How we minimize buffer transfers](hat-minimizing-buffer-transfers.md)
 18 
 19 ---
 20 
 21 ## Intellij and Clion
 22 
 23 We can use JetBrains' `IntelliJ` and `Clion` for dev work and
 24 decided to leave some project artifacts in the repo.
 25 
 26 Care must be taken with Intellij and Clion
 27 as these tools do not play well together,
 28 specifically we cannot have `Clion` and `Intellij`
 29 project artifacts rooted under each other or in the same dir.
 30 
 31 ### Intellij
 32 The `intellij` subdir under the root HAT directory
 33 contains the `.idea` project dir and the various `*.iml` files
 34 for each of the various `modules`
 35 (note the use of `Intellji`'s meaning of the word of module here)
 36 
 37 As you will note the `intellij` dir is somewhat self contained.  the various `*.iml`
 38 files refer to the source dirs using relative paths.
 39 
 40 I tend to add `Intellij` modules by hand.  There are gotchas ;)
 41 
 42 As with every intellij project, `.idea/modules.xml` 'points' to the iml files for each module (intellij's notion of module ;) )
 43 ```xml
 44 <!--
 45    └──hat
 46        └── intellij
 47             └── .idea
 48                  └── modules.xml
 49 -->
 50  <modules>
 51       <module fileurl="file://$PROJECT_DIR$/hat.iml"   />
 52       <module fileurl="file://$PROJECT_DIR$/backend_opencl.iml"  />
 53       <!-- yada yada -->
 54  </modules>
 55 
 56 ```
 57 
 58 The various `.iml` files then  have relative paths to their source/resource dirs roots.
 59 
 60 ```xml
 61 <module type="JAVA_MODULE" version="4">
 62   <component name="NewModuleRootManager" inherit-compiler-output="true">
 63     <exclude-output />
 64     <content url="file://$MODULE_DIR$/../../../hat/src/java">
 65       <sourceFolder url="file://$MODULE_DIR$/../../../hat/src/java" isTestSource="false" />
 66     </content>
 67     <orderEntry type="inheritedJdk" />
 68     <orderEntry type="sourceFolder" forTests="false" />
 69     <orderEntry type="module" module-name="hat" />
 70   </component>
 71 </module>
 72 
 73 ```
 74 
 75 Making run configurations available to other developers is probably `a bridge too far`
 76 
 77 But with some careful XML tooling we can make it easier to add 'run configurations'.
 78 
 79 ### How intellij stores run configurations
 80 
 81 I also tend to hand hack run configurations so will leave this here for reference
 82 
 83 ```xml
 84 <component name="RunManager" selected="Application.MandelTest">
 85     <configuration name="Mandel" type="Application"
 86                    factoryName="Application" temporary="true"
 87                    nameIsGenerated="true">
 88       <option name="MAIN_CLASS_NAME" value="mandel.Mandel" />
 89       <module name="mandel" />
 90       <option name="VM_PARAMETERS" value="
 91           --enable-preview
 92           --add-exports=java.base/java.lang.foreign.mapper=ALL-UNNAMED
 93           --patch-module=java.base=$PROJECT_DIR$/out/production/java_base_patch
 94           -Djava.lang.foreign.mapper.debug=true" />
 95       <extension name="coverage">
 96         <pattern>
 97           <option name="PATTERN" value="mandel.*" />
 98           <option name="ENABLED" value="true" />
 99         </pattern>
100       </extension>
101       <method v="2">
102         <option name="Make" enabled="true" />
103       </method>
104     </configuration>
105     <!-- more configs -->
106 </component>
107 ```
108 
109 ### Clion
110 
111 Thankfully Clion uses cmake, so we get to re-use the CMakeLists.txt in the various backends to build.
112 
113 The intent is that these cmake artifacts can be run standalone (using cmake in the appropriate dir),
114 from within Clion and can be used by maven.  So the CMakeLists.txt files have some extra variables to
115 help us use them in these three modes.
116 
117 
118 
119