Hello,
I have something like this:
import ../../funim_glfw/src/glfw3_api
import ../../funim_glfw/src/mods/utils
import ../../funim_glfw/src/mods/debug
import ../../funim_glfw/src/mods/obj_parser
import ../../funim_glfw/src/mods/shapes I would like to have something like:
const GLFW_ROOT = "../funim_glfw/src/glfw"
import &"../{GLFW_ROOT}/glfw3_api" Later I would also like to set these paths in a Nim file and include that at the start. This seems to work with pragmas (.compile.), but the import seems to consume the raw string.
If not possible, any other way to do a similar thing?
TIA
import macros
macro myimport(v: static string) =
let mi = ident v
quote do:
import `mi`
myimport "tables"
a macro works, though there might be better ways ;)
Nice! Seems to be exactly what I need.
Thank you.
import ../../funim_glfw/src/[
glfw3_api,
mods/utils, mods/debug,
mods/obj_parser, shapes]Just an additional note in case someone else goes this root (irrespective of breaking parallel and incremental compilation): use an untyped parameter. This does not require the use of ident and the myimport need not use quotes.
Still think it is interesting one can do this in Nim.
Update - final solution: config.nims:
const GLFW_ROOT = "../funim_glfw/src"
switch("path", GLFW_ROOT)
switch("passC", &"-I{GLFW_ROOT}/glad/include")
switch("compile", &"{GLFW_ROOT}/glad/src/gl.c")
switch("passL", &"`pkg-config --static --libs glfw3` -L{GLFW_ROOT}/glfw/build/src/") And the code just uses:
import glfw3_api
import utils
import debug
import obj_parser
import shapes Thanks for the help. Update - final solution
Keep in mind that if you publish your code as a library, others will not be loading your config.nims.
Keep in mind that if you publish your code as a library, others will not be loading your config.nims
You can put pragmas at the start of your main file:
import std/strformat
const GLFW_ROOT = "../funim_glfw/src"
{.passc: &"-I{GLFW_ROOT}/glad/include".}
{.compile: &"{GLFW_ROOT}/glad/src/gl.c".}
{.passl: &"`pkg-config --static --libs glfw3` -L{GLFW_ROOT}/glfw/build/src/".}
or even:
import std/strformat
const GLFW_ROOT = "../funim_glfw/src"
{.passc: &"-I{GLFW_ROOT}/glad/include".}
{.compile: &"{GLFW_ROOT}/glad/src/gl.c".}
{.passl: gorge("pkg-config --static --libs glfw3") & &" -L{GLFW_ROOT}/glfw/build/src/".}
https://nim-lang.org/docs/manual.html#implementation-specific-pragmas-compile-pragma
That was my initial solution, but I wanted a single place were to set this up (specifically the GLFW_ROOT path). Right now I copy the config.nim to a new project and change it as needed.
Now that I think of it, it would be nice if compiling a library could pull in some of its configurations automatically for client use.