1# SPDX-License-Identifier: Apache-2.0
2
3set(GEN_DIR ${ZEPHYR_BINARY_DIR}/include/generated)
4
5zephyr_syscall_header_ifdef(CONFIG_POSIX_TIMERS posix_clock.h)
6
7if(CONFIG_POSIX_API)
8  zephyr_include_directories(${ZEPHYR_BASE}/include/zephyr/posix)
9endif()
10
11if (NOT CONFIG_TC_PROVIDES_POSIX_SIGNALS)
12  if(CONFIG_POSIX_SIGNALS)
13    set(STRSIGNAL_TABLE_H ${GEN_DIR}/posix/strsignal_table.h)
14
15    add_custom_command(
16      OUTPUT ${STRSIGNAL_TABLE_H}
17      COMMAND
18      ${PYTHON_EXECUTABLE}
19      ${ZEPHYR_BASE}/scripts/build/gen_strsignal_table.py
20      -i ${ZEPHYR_BASE}/include/zephyr/posix/signal.h
21      -o ${STRSIGNAL_TABLE_H}
22      DEPENDS ${ZEPHYR_BASE}/include/zephyr/posix/signal.h
23    )
24  endif()
25endif()
26
27if(CONFIG_POSIX_API OR CONFIG_POSIX_THREADS OR CONFIG_POSIX_TIMERS OR
28  CONFIG_POSIX_MESSAGE_PASSING OR CONFIG_POSIX_FILE_SYSTEM OR CONFIG_EVENTFD OR
29  CONFIG_POSIX_C_LIB_EXT OR CONFIG_POSIX_SINGLE_PROCESS)
30  # This is a temporary workaround so that Newlib declares the appropriate
31  # types for us. POSIX features to be formalized as part of #51211
32  zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:-D_POSIX_THREADS>)
33  zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:-D_POSIX_THREADS>)
34endif()
35
36zephyr_library()
37zephyr_library_sources_ifdef(CONFIG_EVENTFD eventfd.c)
38
39if (NOT CONFIG_TC_PROVIDES_POSIX_ASYNCHRONOUS_IO)
40  zephyr_library_sources_ifdef(CONFIG_POSIX_ASYNCHRONOUS_IO aio.c)
41endif()
42
43if (NOT CONFIG_TC_PROVIDES_POSIX_BARRIERS)
44  zephyr_library_sources_ifdef(CONFIG_POSIX_BARRIERS barrier.c)
45endif()
46
47if (NOT CONFIG_TC_PROVIDES_POSIX_C_LIB_EXT)
48  zephyr_library_sources_ifdef(CONFIG_POSIX_C_LIB_EXT
49    fnmatch.c
50    getentropy.c
51    getopt/getopt.c
52    getopt/getopt_common.c
53  )
54endif()
55
56if (NOT CONFIG_TC_PROVIDES_POSIX_DEVICE_IO)
57  zephyr_library_sources_ifdef(CONFIG_POSIX_DEVICE_IO
58    # perror should be moved to the common libc
59    perror.c
60    device_io.c
61  )
62endif()
63
64if (NOT CONFIG_TC_PROVIDES_POSIX_FD_MGMT)
65  zephyr_library_sources_ifdef(CONFIG_POSIX_FD_MGMT
66    fd_mgmt.c
67  )
68endif()
69
70if (NOT CONFIG_TC_PROVIDES_POSIX_FILE_SYSTEM)
71  zephyr_library_sources_ifdef(CONFIG_POSIX_FILE_SYSTEM fs.c)
72endif()
73
74if (NOT CONFIG_TC_PROVIDES_POSIX_FILE_SYSTEM_R)
75  zephyr_library_sources_ifdef(CONFIG_POSIX_FILE_SYSTEM_R file_system_r.c)
76endif()
77
78zephyr_library_sources_ifdef(CONFIG_POSIX_FSYNC fsync.c)
79zephyr_library_sources_ifdef(CONFIG_POSIX_MEMLOCK mlockall.c)
80zephyr_library_sources_ifdef(CONFIG_POSIX_MEMLOCK_RANGE mlock.c)
81
82if (NOT CONFIG_TC_PROVIDES_POSIX_MEMORY_PROTECTION)
83zephyr_library_sources_ifdef(CONFIG_POSIX_MEMORY_PROTECTION mprotect.c)
84endif()
85
86if (NOT CONFIG_TC_PROVIDES_POSIX_MAPPED_FILES)
87  zephyr_library_sources_ifdef(CONFIG_POSIX_MAPPED_FILES mmap.c)
88endif()
89
90zephyr_library_sources_ifdef(CONFIG_POSIX_MESSAGE_PASSING mqueue.c)
91
92if (NOT CONFIG_TC_PROVIDES_POSIX_MULTI_PROCESS)
93  zephyr_library_sources_ifdef(CONFIG_POSIX_MULTI_PROCESS
94    sleep.c
95    multi_process.c
96  )
97endif()
98
99if (NOT CONFIG_TC_PROVIDES_POSIX_NETWORKING)
100  zephyr_library_sources_ifdef(CONFIG_POSIX_NETWORKING net.c)
101endif()
102
103if (NOT CONFIG_TC_PROVIDES_POSIX_SHARED_MEMORY_OBJECTS)
104  zephyr_library_sources_ifdef(CONFIG_POSIX_SHARED_MEMORY_OBJECTS shm.c)
105endif()
106
107if (NOT CONFIG_TC_PROVIDES_POSIX_SIGNALS)
108  zephyr_library_sources_ifdef(CONFIG_POSIX_SIGNALS signal.c ${STRSIGNAL_TABLE_H})
109endif()
110
111if (NOT CONFIG_TC_PROVIDES_POSIX_SINGLE_PROCESS)
112  zephyr_library_sources_ifdef(CONFIG_POSIX_SINGLE_PROCESS
113    confstr.c
114    env.c
115    sysconf.c
116    uname.c
117  )
118endif()
119
120if (NOT CONFIG_TC_PROVIDES_POSIX_SPIN_LOCKS)
121  zephyr_library_sources_ifdef(CONFIG_POSIX_SPIN_LOCKS spinlock.c)
122endif()
123
124if (NOT CONFIG_TC_PROVIDES_POSIX_TIMERS)
125  zephyr_library_sources_ifdef(CONFIG_POSIX_TIMERS
126    clock.c
127    timer.c
128    timespec_to_timeout.c
129  )
130endif()
131
132zephyr_library_sources_ifdef(CONFIG_POSIX_PRIORITY_SCHEDULING sched.c)
133
134if (NOT CONFIG_TC_PROVIDES_POSIX_READER_WRITER_LOCKS)
135  # Note: the Option is _POSIX_READER_WRITER_LOCKS, while the Option Group is POSIX_RW_LOCKS.
136  # We have opted to use POSIX_READER_WRITER_LOCKS here to match the Option name.
137  zephyr_library_sources_ifdef(CONFIG_POSIX_READER_WRITER_LOCKS rwlock.c)
138endif()
139
140if (NOT CONFIG_TC_PROVIDES_POSIX_SEMAPHORES)
141  zephyr_library_sources_ifdef(CONFIG_POSIX_SEMAPHORES semaphore.c)
142endif()
143
144if (NOT CONFIG_TC_PROVIDES_POSIX_THREADS)
145  # Note: the Option is _POSIX_THREADS, while the Option Group is POSIX_THREADS_BASE.
146  # We have opted to use POSIX_THREADS here to match the Option name.
147  zephyr_library_sources_ifdef(CONFIG_POSIX_THREADS
148    cond.c
149    grp.c
150    key.c
151    mutex.c
152    pthread.c
153    pwd.c
154  )
155endif()
156
157zephyr_library_sources_ifdef(CONFIG_XOPEN_STREAMS stropts.c)
158
159if (NOT CONFIG_TC_PROVIDES_XSI_SYSTEM_LOGGING)
160  zephyr_library_sources_ifdef(CONFIG_XSI_SYSTEM_LOGGING syslog.c)
161endif()
162
163zephyr_library_sources_ifdef(CONFIG_GETOPT_LONG
164  getopt/getopt_long.c
165)
166zephyr_include_directories_ifdef(CONFIG_POSIX_C_LIB_EXT
167  getopt/
168)
169
170zephyr_library_include_directories(
171  ${ZEPHYR_BASE}/kernel/include
172  ${ARCH_DIR}/${ARCH}/include
173)
174
175zephyr_library_property(ALLOW_EMPTY TRUE)
176