1 # get CODENAME to perform per codename actions
3 set(ONE_UBUNTU_CODENAME "focal")
4 find_program(LSB_RELEASE_EXEC lsb_release)
6 # output should be one of 'bionic', 'focal', 'jammy'
7 # others are not tested
8 execute_process(COMMAND "${LSB_RELEASE_EXEC}" --short --codename
9 OUTPUT_VARIABLE ONE_UBUNTU_CODENAME
10 OUTPUT_STRIP_TRAILING_WHITESPACE)
12 message(STATUS "WARNING: lsb_release not found")
15 if(${ONE_UBUNTU_CODENAME} STREQUAL "jammy")
16 set(ONE_UBUNTU_CODENAME_JAMMY TRUE)
19 # TODO Validate the argument of "requires"
20 function(get_project_build_order VAR)
21 # This file will describe the dependencies among projects
22 set(DEPS_FILE "${CMAKE_CURRENT_BINARY_DIR}/compiler.deps")
25 file(REMOVE "${DEPS_FILE}")
27 # Let's create .deps file
28 list_subdirectories(PROJECT_DIRS)
30 foreach(PROJECT_DIR IN ITEMS ${PROJECT_DIRS})
31 set(SUCC "${PROJECT_DIR}")
32 set(REQUIRES_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_DIR}/requires.cmake")
35 file(APPEND "${DEPS_FILE}" "${PRED} ${SUCC} ")
38 file(APPEND "${DEPS_FILE}" "${SUCC} ${SUCC} ")
39 if(EXISTS "${REQUIRES_FILE}")
40 include(${REQUIRES_FILE})
41 endif(EXISTS "${REQUIRES_FILE}")
42 endforeach(PROJECT_DIR)
44 # NOTE "tsort" is a part of the POSIX.1 standard.
46 # Reference: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/tsort.html
47 execute_process(COMMAND tsort "${DEPS_FILE}"
49 OUTPUT_STRIP_TRAILING_WHITESPACE)
51 # Remove newline characters
52 # TODO Check which one (UNIX_COMMAND or WINDOWS_COMMAND) is correct
53 separate_arguments(ORDER UNIX_COMMAND ${ORDER})
55 set(${VAR} "${ORDER}" PARENT_SCOPE)
56 endfunction(get_project_build_order)
58 function(add_compiler_directory DIR)
59 string(TOUPPER ${DIR} PREFIX)
61 option(BUILD_COMPILER_${PREFIX} "Build compiler/${dir}" ON)
62 set(BUILD_WHITELIST "" CACHE STRING "Set modules to be built")
64 if(NOT BUILD_WHITELIST STREQUAL "")
66 set(CURRENT_DIR ${DIR})
67 foreach(ACCEPTED_DIR IN ITEMS ${BUILD_WHITELIST})
68 if(ACCEPTED_DIR STREQUAL CURRENT_DIR)
71 endforeach(ACCEPTED_DIR)
73 set(ENABLE ${BUILD_COMPILER_${PREFIX}})
76 # This line prevents some errors in this CMakeLists.txt
77 if(NOT DEFINED ENABLE)
78 message(FATAL_ERROR "Undefined ENABLE! Please check CMakeLists.txt")
82 message(STATUS "Configure ${PREFIX}")
83 add_subdirectory(${DIR})
84 message(STATUS "Configure ${PREFIX} - Done")
86 endfunction(add_compiler_directory)
88 function(add_compiler_directories)
89 get_project_build_order(PROJECT_DIRS)
91 foreach(PROJECT_DIR IN ITEMS ${PROJECT_DIRS})
92 add_compiler_directory(${PROJECT_DIR})
93 endforeach(PROJECT_DIR)
94 endfunction(add_compiler_directories)
96 add_compiler_directories()