Native C++ third part library header files without extension

issue-resolved

(Kaloyan Penev) #1

Hi,

I am trying to include a third-party library (named “Eigen”) in a project using gradle. However, Eigen’s interface headers are organized in several level deep tree with the upper levels headers not having .h extensions. I can recursively search the tree and add all the directories, but I couldn’t figure out how to handle the extensionless headers. Here is a subset of the structure of Eigen:

Eigen/
├── Array
├── Cholesky
├── Dense

├── src
│ ├── Cholesky
│ │ ├── LDLT.h
│ │ ├── LLT.h
│ │ └── LLT_MKL.h

The top-level files e.g. Eigen/Array, Eigen/Dense etc. are what is typically used in #include statements, but are ignored by gradle. Here is a build.gradle snippet that tried to add the top-level as exportedHeaders:

model {
    components {
        eigen(NativeLibrarySpec) {
            sources.cpp {
                exportedHeaders {
                    srcDir "Eigen"
                    include "**/*"
                }
            }
        }
        stellarEvolution(NativeLibrarySpec) {
            sources.cpp {
                lib library: "alglib"
                source {
                    srcDir "StellarEvolution"
                    include "**/*.cpp"
                }
                exportedHeaders {
                    srcDir "StellarEvolution"
                }
            }
        }
    }
}

This, however, does not result in the Eigen directory added to the header search path when compiling StellarEvolution. I based my build.gradle on: gradle-3.1/samples/native-binaries/cpp, which seems to work, hence my assumption that the extension free header files are the problem.

I tried to find examples of how to do this but failed. Could someone help?


(Kaloyan Penev) #2

Nevermind. I was mis-understanding how exportedHeaders are processed. I was assuming that the headers are somehowe added to the build, along with a search path to all compilations which depend on the library. Instead, only the directory specified by exportedHeaders.srcDir is added to the search path and nothing is added to the build.


(Daniel Lacasse) #3

Hi Kaloyan,

You are correct. Only the directories are used for the source of exportedHeaders. Those directories are used as include root for the compiler.

Daniel