@@ -15,60 +15,46 @@ import java.nio.file.Path
1515class UcCmakeGenerator (private val targetConfig : TargetConfig , private val fileConfig : FileConfig ) {
1616 private val S = ' $' // a little trick to escape the dollar sign with $S
1717 private val platform = targetConfig.get(PlatformProperty .INSTANCE ).platform
18- private val platformName = if (platform == PlatformType .Platform .AUTO ) " POSIX" else platform.name.uppercase()
1918
20- fun generatePlatformSpecific () = with ( PrependOperator ) {
19+ fun generateCmake ( sources : List < Path >) =
2120 if (platform == PlatformType .Platform .AUTO ) {
22- """
23- |# For POSIX we directly generate an executable.
24- |# and install it to the bin directory.
25- |add_executable($S {LF_MAIN_TARGET} $S {SOURCES})
26- |install(TARGETS $S {LF_MAIN_TARGET}
27- | RUNTIME DESTINATION $S {CMAKE_INSTALL_BINDIR}
28- | OPTIONAL
29- |)
30- """ .trimMargin()
31- } else if (platform == PlatformType .Platform .ZEPHYR ) {
32- """
33- |# For Zephyr we generate a library that can be included
34- |# in a Zephyr project.
35- |zephyr_library_named($S {LF_MAIN_TARGET})
36- |zephyr_library_sources($S {SOURCES})
37- |zephyr_library_link_libraries(kernel)
38- """ .trimMargin()
39- } else if (platform == PlatformType .Platform .FLEXPRET ){
40- """
41- |add_library($S {LF_MAIN_TARGET} $S {SOURCES})
42- |target_link_libraries($S {LF_MAIN_TARGET} PUBLIC fp-sdk)
43- """ .trimMargin()
21+ generateCmakePosix(sources)
4422 } else {
45- """
46- |add_library($S {LF_MAIN_TARGET} $S {SOURCES})
47- """ .trimMargin()
48-
23+ generateCmakeEmbedded(sources)
4924 }
25+
26+ fun generateCmakeEmbedded (sources : List <Path >) = with (PrependOperator ) {
27+ """
28+ |# This file is generated by LFC. It is meant to be included in
29+ |# an existing CMake project.
30+ |
31+ |set(LF_SOURCES
32+ ${" | " .. sources.joinWithLn { " $S {CMAKE_CURRENT_LIST_DIR}/${it.toUnixString()} " }}
33+ |)
34+ |set(REACTOR_UC_PATH $S {CMAKE_CURRENT_LIST_DIR}/reactor-uc)
35+ |set(LF_INCLUDE_DIRS $S {CMAKE_CURRENT_LIST_DIR})
36+ """ .trimMargin()
5037 }
51- fun generateCmake (sources : List <Path >) = with (PrependOperator ) {
38+
39+ fun generateCmakePosix (sources : List <Path >) = with (PrependOperator ) {
5240 """
5341 |cmake_minimum_required(VERSION 3.5)
5442 |project(${fileConfig.name} VERSION 0.0.0 LANGUAGES C)
55- |set(PLATFORM $platformName CACHE STRING "Target platform")
56- |
57- |# Get the value of the environment variable
58- |if(NOT DEFINED ENV{REACTOR_UC_PATH})
59- | message(FATAL_ERROR "Environment variable REACTOR_UC_PATH is not set. Please source the env.bash in reactor-uc.")
60- |endif()
43+ |set(PLATFORM POSIX CACHE STRING "Target platform")
6144 |
6245 |set(LF_MAIN_TARGET ${fileConfig.name} )
6346 |set(SOURCES
6447 ${" | " .. sources.joinWithLn { it.toUnixString() }}
6548 |)
66- ${" |" .. generatePlatformSpecific()}
49+ |add_executable($S {LF_MAIN_TARGET} $S {SOURCES})
50+ |install(TARGETS $S {LF_MAIN_TARGET}
51+ | RUNTIME DESTINATION $S {CMAKE_INSTALL_BINDIR}
52+ | OPTIONAL
53+ |)
6754 |
6855 |add_subdirectory(reactor-uc)
69- |
70- |target_include_directories($S {LF_MAIN_TARGET} PUBLIC $S {CMAKE_CURRENT_SOURCE_DIR})
71- |target_link_libraries($S {LF_MAIN_TARGET} PUBLIC reactor-uc)
56+ |target_link_libraries($S {LF_MAIN_TARGET} PRIVATE reactor-uc)
57+ |target_include_directories($S {LF_MAIN_TARGET} PRIVATE $S {CMAKE_CURRENT_LIST_DIR})
7258 |
7359 """ .trimMargin()
7460 }
0 commit comments