Skip to content
This repository has been archived by the owner on Mar 4, 2021. It is now read-only.

Commit

Permalink
Implement check_{function,symbol}_exists
Browse files Browse the repository at this point in the history
Required by and used in measurement-kit/libndt#108
  • Loading branch information
bassosimone committed Aug 2, 2019
1 parent d8f7540 commit f27aa8d
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmake/cmake.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ func sortedTestInfo(m map[string]pkginfo.TestInfo) []string {
func Generate(pkginfo *pkginfo.PkgInfo) {
cmake := cmakefile.Open(pkginfo.Name)
defer cmake.Close()
for _, funcheck := range pkginfo.FunctionChecks {
cmake.CheckFunctionExists(funcheck.Name, funcheck.Define)
}
for _, symcheck := range pkginfo.SymbolChecks {
cmake.CheckSymbolExists(symcheck.Name, symcheck.Header, symcheck.Define)
}
for _, depname := range pkginfo.Dependencies {
handler, ok := deps.All[depname]
if !ok {
Expand Down
27 changes: 27 additions & 0 deletions cmake/cmakefile/cmakefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ func Open(name string) *CMakeFile {
cmake.WriteLine(` set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/usr/local/lib")`)
cmake.WriteLine(` set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -L/usr/local/lib")`)
cmake.WriteLine(`endif()`)
cmake.writeEmptyLine()
cmake.WriteLine(`include(CheckFunctionExists)`)
cmake.WriteLine(`include(CheckSymbolExists)`)
return cmake
}

Expand Down Expand Up @@ -154,6 +157,30 @@ func (cmake *CMakeFile) untar(filename, destdir string) {
cmake.unzip(filename, destdir)
}

// CheckFunctionExists checks whether |name| is a function and
// defines the |define| preprocessor macro in such case.
func (cmake *CMakeFile) CheckFunctionExists(name, define string) {
cmake.WriteLine(fmt.Sprintf("check_function_exists(%s %s)", name, define))
cmake.WriteLine(fmt.Sprintf("if(${%s})", define))
cmake.WithIndent(" ", func() {
cmake.WriteLine(fmt.Sprintf("add_definitions(-D%s)", define))
})
cmake.WriteLine("endif()")
}

// CheckSymbolExists checks whether |name| is a symbol in |header| and
// defines the |define| preprocessor macro in such case.
func (cmake *CMakeFile) CheckSymbolExists(name, header, define string) {
cmake.WriteLine(fmt.Sprintf(
"check_symbol_exists(%s %s %s)", name, header, define,
))
cmake.WriteLine(fmt.Sprintf("if(${%s})", define))
cmake.WithIndent(" ", func() {
cmake.WriteLine(fmt.Sprintf("add_definitions(-D%s)", define))
})
cmake.WriteLine("endif()")
}

// AddRequiredDefinition adds |definition| to the macro definitions
func (cmake *CMakeFile) AddRequiredDefinition(definition string) {
cmake.WriteLine(fmt.Sprintf(
Expand Down
27 changes: 27 additions & 0 deletions pkginfo/pkginfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,38 @@ type TestInfo struct {
Command string
}

// FunctionCheck adds a check for a specific function
type FunctionCheck struct {
// Name is the function name
Name string

// Define is the define to add to the build if function exists
Define string
}

// SymbolCheck adds a check for a specific symbol
type SymbolCheck struct {
// Name is the symbol name
Name string

// Header is the header to include for checking for the symbol
Header string

// Define is the define to add to the build if symbol exists
Define string
}

// PkgInfo contains information on a package
type PkgInfo struct {
// Name is the name of the package
Name string

// FunctionChecks contains all the checks for functions
FunctionChecks []FunctionCheck `yaml:"function_checks"`

// SymbolChecks contains all the checks for symbols
SymbolChecks []SymbolCheck `yaml:"symbol_checks"`

// Docker is the docker container to use for running tests
Docker string

Expand Down

0 comments on commit f27aa8d

Please sign in to comment.