diff options
Diffstat (limited to 'adapters/gtest/templating.go')
-rw-r--r-- | adapters/gtest/templating.go | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/adapters/gtest/templating.go b/adapters/gtest/templating.go index 41c54c1..2380db9 100644 --- a/adapters/gtest/templating.go +++ b/adapters/gtest/templating.go @@ -5,15 +5,39 @@ import ( "log" "os" "golang.flu0r1ne.net/planr" + "path" "text/template" ) type cmakeUnit struct { - ExeNm string - File string - Srcs string + ExeNm string + File string + Srcdir string + IncludeSrc bool + Srcs string + CompilerOptions string }; +func cmakeUnits(e []executable, dirs planr.DirConfig) []cmakeUnit { + + units := make([]cmakeUnit, len(e)) + for i, exe := range e { + testpath := path.Join(dirs.Tests(), exe.testpath) + srclist := srcList(dirs.Src(), exe.srcs) + + units[i] = cmakeUnit { + ExeNm: exe.exeNm, + File: testpath, + IncludeSrc: exe.includeSrc, + Srcdir: dirs.Src(), + Srcs: srclist, + CompilerOptions: compilerOptionsCmake(exe), + } + } + + return units +} + func generateCmakeScript(out string, units []cmakeUnit) { file, err := os.OpenFile(out, os.O_RDWR | os.O_CREATE, 0644) defer func () { @@ -39,6 +63,13 @@ func generateCmakeScript(out string, units []cmakeUnit) { } } +func compilerOptionsCmake(e executable) string { + if e.compilerOptions == "" { + return "" + } + + return "target_compile_options(\"" + e.exeNm + "\" PRIVATE " + e.compilerOptions + ")"; +} // TODO: Add comments func unitTemplate() *template.Template { @@ -54,6 +85,14 @@ add_executable( {{.Srcs}} ) +{{.CompilerOptions}} + +{{ if .IncludeSrc }} + +target_include_directories("{{.ExeNm}}" PRIVATE "{{.Srcdir}}") + +{{ end }} + target_link_libraries( "{{.ExeNm}}" gtest_main @@ -85,6 +124,7 @@ func writeCmakeBoilerplate(w io.Writer) { }) } +// TODO: Make CXX Version Editable func boilderTemplate() *template.Template { tmpl, err := template.New("gtest_boilerplate").Parse(` # AUTOMATICALLY GENERATED BY PLANR VERSION {{.Version}} @@ -99,6 +139,8 @@ FetchContent_Declare( URL {{.Url}} ) +set(CMAKE_CXX_STANDARD 17) + include(GoogleTest) FetchContent_MakeAvailable(googletest) `) |