diff options
author | flu0r1ne <flu0r1ne@flu0r1ne.net> | 2021-09-06 02:12:52 -0500 |
---|---|---|
committer | flu0r1ne <flu0r1ne@flu0r1ne.net> | 2021-09-06 02:12:52 -0500 |
commit | fd4ff9192a004ade9174a58dd51abb31277fc1a7 (patch) | |
tree | 0b19b37c8a0ad66986dba2ed63b1066a7318ab72 /adapters/gtest/templating.go | |
parent | 087c51bed9da75f5585d176a7b14396cd70f2638 (diff) | |
parent | 788ae3e0266bdb12bdff6c260dda2e3bcbdfc79c (diff) | |
download | deb-planr-fd4ff9192a004ade9174a58dd51abb31277fc1a7.tar.xz deb-planr-fd4ff9192a004ade9174a58dd51abb31277fc1a7.zip |
Merge branch 'upstream' into ppa
Update to v0.1.1
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) `) |