trentforkert / cmake

Experimental CMake with D support
Other
16 stars 2 forks source link

Possibly redundant call to include_directories needed #10

Closed trentforkert closed 10 years ago

trentforkert commented 10 years ago

Something I've noticed as I work on writing test cases is that simple projects need a call to include_directories(${CMAKE_CURRENT_SOURCE_DIR}) to work.

I think I'd like the current source dir to implicitly be on the include path, as happens for the D compilers themselves.

mathstuf commented 10 years ago

You add sources from the top-level rather than a CMakeLists.txt right beside the sources? I think this might make sense for a language where you have to do $compiler **/*.$ext (e.g., Java, C#, or Rust), but not one with a .$ext → .o → $exe flow.

trentforkert commented 10 years ago

My structure for my (unreleased) project(s) looks like this:

project/
    CMakeLists.txt (1)
    src/
        CMakeLists.txt (2)
        pkg/
            sub/
                mod.d
                ....

With (2) compiling the sources from the pkg together into a lib/exe.

However, the reason for wanting an implicit include_directories(${CMAKE_CURRENT_SOURCE_DIR}) is for a simpler project than that:

project/
    CMakeLists.txt
    main.d
    otherModule.d

Assuming main imports otherModule, the D compiler will complain that it can't find otherModule without the change mentioned in this issue. By default, dmd and friends implicitly look in ${PWD}. However, CMake ends up calling dmd from somewhere in the build directory, meaning that dmd doesn't know where to look to find otherModule, breaking compilation.

An equivalent C project (including header for otherModule) will compile, but the D project described would not without explicitly including the current source dir. To me that felt wrong.

mathstuf commented 10 years ago

The problem is that not everyone does that. Take a look at gunroar where including the current source directory is completely unnecessary. It is however, necessary above and is done there. It looks weird for projects where CMake is shallower than the sources, but not everyone does that (and I find CMakeLists.txt being beside their sources much easier to manage than it being in some parent directory.

My problem is really with the support for this being so low level and forced onto the user. Unfortunately, I don't know how to implement it without bringing in wrappers for add_library and the like :( .

trentforkert commented 10 years ago

Okay, undid this change in 2b667f9f8776629c0bb867f11a0adc66a0174515.