33 cmake_policy (SET CMP0091 NEW )
44endif ()
55
6- project (LibreSSL C ASM )
6+ project (LibreSSL LANGUAGES C ASM )
77
88include (CheckFunctionExists )
99include (CheckSymbolExists )
@@ -200,37 +200,42 @@ else()
200200 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall" )
201201endif ()
202202
203+ # XXX - needs _GNU_SOURCE on linux
203204check_function_exists (asprintf HAVE_ASPRINTF )
204205if (HAVE_ASPRINTF)
205206 add_definitions (-DHAVE_ASPRINTF )
206207endif ()
207208
208- check_function_exists (getopt HAVE_GETOPT )
209+ check_symbol_exists (getopt "unistd.h" HAVE_GETOPT )
209210if (HAVE_GETOPT)
210211 add_definitions (-DHAVE_GETOPT )
211212endif ()
212213
213- check_function_exists (reallocarray HAVE_REALLOCARRAY )
214+ check_symbol_exists (reallocarray "stdlib.h" HAVE_REALLOCARRAY )
214215if (HAVE_REALLOCARRAY)
215216 add_definitions (-DHAVE_REALLOCARRAY )
216217endif ()
217218
219+ # XXX strcasecmp() is in strings.h which isn't available everywhere
218220check_function_exists (strcasecmp HAVE_STRCASECMP )
219221if (HAVE_STRCASECMP)
220222 add_definitions (-DHAVE_STRCASECMP )
221223endif ()
222224
223- check_function_exists (strlcat HAVE_STRLCAT )
224- if (HAVE_STRLCAT)
225- add_definitions (-DHAVE_STRLCAT )
226- endif ()
225+ # Emscripten's strlcat and strlcpy triggers ASAN errors
226+ if (NOT EMSCRIPTEN)
227+ check_symbol_exists (strlcat "string.h" HAVE_STRLCAT )
228+ if (HAVE_STRLCAT)
229+ add_definitions (-DHAVE_STRLCAT )
230+ endif ()
227231
228- check_function_exists (strlcpy HAVE_STRLCPY )
229- if (HAVE_STRLCPY)
230- add_definitions (-DHAVE_STRLCPY )
232+ check_symbol_exists (strlcpy "string.h" HAVE_STRLCPY )
233+ if (HAVE_STRLCPY)
234+ add_definitions (-DHAVE_STRLCPY )
235+ endif ()
231236endif ()
232237
233- check_function_exists (strndup HAVE_STRNDUP )
238+ check_symbol_exists (strndup "string.h" HAVE_STRNDUP )
234239if (HAVE_STRNDUP)
235240 add_definitions (-DHAVE_STRNDUP )
236241endif ()
@@ -239,67 +244,64 @@ if(WIN32)
239244 set (HAVE_STRNLEN true )
240245 add_definitions (-DHAVE_STRNLEN )
241246else ()
242- check_function_exists (strnlen HAVE_STRNLEN )
247+ check_symbol_exists (strnlen "string.h" HAVE_STRNLEN )
243248 if (HAVE_STRNLEN)
244249 add_definitions (-DHAVE_STRNLEN )
245250 endif ()
246251endif ()
247252
248- check_function_exists (strsep HAVE_STRSEP )
253+ check_symbol_exists (strsep "string.h" HAVE_STRSEP )
249254if (HAVE_STRSEP)
250255 add_definitions (-DHAVE_STRSEP )
251256endif ()
252257
253- check_function_exists (strtonum HAVE_STRTONUM )
258+ check_symbol_exists (strtonum "stdlib.h" HAVE_STRTONUM )
254259if (HAVE_STRTONUM)
255260 add_definitions (-DHAVE_STRTONUM )
256261endif ()
257262
258- check_function_exists (timegm HAVE_TIMEGM )
259- if (HAVE_TIMEGM)
260- add_definitions (-DHAVE_TIMEGM )
261- endif ()
262-
263- check_function_exists (arc4random_buf HAVE_ARC4RANDOM_BUF )
263+ check_symbol_exists (arc4random_buf "stdlib.h" HAVE_ARC4RANDOM_BUF )
264264if (HAVE_ARC4RANDOM_BUF)
265265 add_definitions (-DHAVE_ARC4RANDOM_BUF )
266266endif ()
267267
268- check_function_exists (arc4random_uniform HAVE_ARC4RANDOM_UNIFORM )
268+ check_symbol_exists (arc4random_uniform "stdlib.h" HAVE_ARC4RANDOM_UNIFORM )
269269if (HAVE_ARC4RANDOM_UNIFORM)
270270 add_definitions (-DHAVE_ARC4RANDOM_UNIFORM )
271271endif ()
272272
273- check_function_exists (explicit_bzero HAVE_EXPLICIT_BZERO )
273+ check_symbol_exists (explicit_bzero "string.h" HAVE_EXPLICIT_BZERO )
274274if (HAVE_EXPLICIT_BZERO)
275275 add_definitions (-DHAVE_EXPLICIT_BZERO )
276276endif ()
277277
278- check_function_exists (getauxval HAVE_GETAUXVAL )
278+ check_symbol_exists (getauxval "sys/auxv.h" HAVE_GETAUXVAL )
279279if (HAVE_GETAUXVAL)
280280 add_definitions (-DHAVE_GETAUXVAL )
281281endif ()
282282
283+ # XXX macos fails to find getentropy with check_symbol_exists()
283284check_function_exists (getentropy HAVE_GETENTROPY )
284285if (HAVE_GETENTROPY)
285286 add_definitions (-DHAVE_GETENTROPY )
286287endif ()
287288
288- check_symbol_exists (getpagesize unistd.h HAVE_GETPAGESIZE )
289+ check_symbol_exists (getpagesize " unistd.h" HAVE_GETPAGESIZE )
289290if (HAVE_GETPAGESIZE)
290291 add_definitions (-DHAVE_GETPAGESIZE )
291292endif ()
292293
293- check_function_exists (getprogname HAVE_GETPROGNAME )
294+ check_symbol_exists (getprogname "stdlib.h" HAVE_GETPROGNAME )
294295if (HAVE_GETPROGNAME)
295296 add_definitions (-DHAVE_GETPROGNAME )
296297endif ()
297298
298- check_function_exists (syslog_r HAVE_SYSLOG_R )
299+ check_symbol_exists (syslog_r "syslog.h;stdarg.h" HAVE_SYSLOG_R )
299300if (HAVE_SYSLOG_R)
300301 add_definitions (-DHAVE_SYSLOG_R )
301302endif ()
302303
304+ # XXX - needs _GNU_SOURCE on linux
303305check_function_exists (syslog HAVE_SYSLOG )
304306if (HAVE_SYSLOG)
305307 add_definitions (-DHAVE_SYSLOG )
@@ -310,16 +312,17 @@ if(HAVE_TIMESPECSUB)
310312 add_definitions (-DHAVE_TIMESPECSUB )
311313endif ()
312314
313- check_function_exists (timingsafe_bcmp HAVE_TIMINGSAFE_BCMP )
315+ check_symbol_exists (timingsafe_bcmp "string.h" HAVE_TIMINGSAFE_BCMP )
314316if (HAVE_TIMINGSAFE_BCMP)
315317 add_definitions (-DHAVE_TIMINGSAFE_BCMP )
316318endif ()
317319
318- check_function_exists (timingsafe_memcmp HAVE_TIMINGSAFE_MEMCMP )
320+ check_symbol_exists (timingsafe_memcmp "string.h" HAVE_TIMINGSAFE_MEMCMP )
319321if (HAVE_TIMINGSAFE_MEMCMP)
320322 add_definitions (-DHAVE_TIMINGSAFE_MEMCMP )
321323endif ()
322324
325+ # XXX - needs _GNU_SOURCE on linux
323326check_function_exists (memmem HAVE_MEMMEM )
324327if (HAVE_MEMMEM)
325328 add_definitions (-DHAVE_MEMMEM )
@@ -375,7 +378,7 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "mips")
375378elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "powerpc" )
376379 set (HOST_POWERPC true )
377380elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64" )
378- set (HOST_PPC64 true )
381+ set (HOST_POWERPC64 true )
379382elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "riscv64" )
380383 set (HOST_RISCV64 true )
381384elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "sparc64" )
@@ -386,21 +389,20 @@ endif()
386389
387390if (ENABLE_ASM)
388391 if (CMAKE_C_COMPILER_ABI STREQUAL "ELF" )
389- if (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64|amd64)" )
392+ if (HOST_X86_64 )
390393 set (HOST_ASM_ELF_X86_64 true )
391- elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "arm" AND
392- NOT CMAKE_SYSTEM_PROCESSOR MATCHES "arm64" )
394+ elseif (HOST_ARM)
393395 set (HOST_ASM_ELF_ARMV4 true )
394- elseif (CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND CMAKE_SYSTEM_PROCESSOR MATCHES "i386" )
396+ elseif (CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND HOST_I386 )
395397 set (HOST_ASM_ELF_X86_64 true )
396398 endif ()
397399 add_definitions (-DHAVE_GNU_STACK )
398- elseif (APPLE AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64" )
400+ elseif (APPLE AND HOST_X86_64 )
399401 set (HOST_ASM_MACOSX_X86_64 true )
400402 elseif (MSVC AND (CMAKE_GENERATOR MATCHES "Win64" OR CMAKE_GENERATOR_PLATFORM STREQUAL "x64" ))
401403 set (HOST_ASM_MASM_X86_64 true )
402404 ENABLE_LANGUAGE (ASM_MASM )
403- elseif (MINGW AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64" )
405+ elseif (MINGW AND HOST_X86_64 )
404406 set (HOST_ASM_MINGW64_X86_64 true )
405407 endif ()
406408endif ()
@@ -509,15 +511,13 @@ if(ENABLE_LIBRESSL_INSTALL)
509511 "${CMAKE_CURRENT_BINARY_DIR} /LibreSSLConfigVersion.cmake"
510512 DESTINATION "${LIBRESSL_INSTALL_CMAKEDIR} "
511513 )
512- endif ()
513514
514- if (ENABLE_LIBRESSL_INSTALL)
515515 if (NOT MSVC )
516516 # Create pkgconfig files.
517517 set (prefix ${CMAKE_INSTALL_PREFIX} )
518518 set (exec_prefix \${prefix} )
519519 set (libdir \${exec_prefix} /${CMAKE_INSTALL_LIBDIR} )
520- set (includedir \${prefix} /include )
520+ set (includedir \${prefix} /${CMAKE_INSTALL_INCLUDEDIR} )
521521 if (PLATFORM_LIBS)
522522 string (REGEX REPLACE ";" " -l" PLATFORM_LDADD ";${PLATFORM_LIBS} " )
523523 endif ()
@@ -530,19 +530,17 @@ if(ENABLE_LIBRESSL_INSTALL)
530530 install (DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} /pkgconfig
531531 DESTINATION ${CMAKE_INSTALL_LIBDIR} )
532532 endif ()
533- endif (ENABLE_LIBRESSL_INSTALL )
534533
535- if (ENABLE_LIBRESSL_INSTALL)
536534 install (FILES cert.pem openssl.cnf x509v3.cnf DESTINATION ${CONF_DIR} )
537535 install (DIRECTORY DESTINATION ${CONF_DIR} /certs)
538- endif (ENABLE_LIBRESSL_INSTALL )
539536
540- if (NOT TARGET uninstall)
541- configure_file (
542- "${CMAKE_CURRENT_SOURCE_DIR} /cmake_uninstall.cmake.in"
543- "${CMAKE_CURRENT_BINARY_DIR} /cmake_uninstall.cmake"
544- IMMEDIATE @ONLY )
537+ if (NOT TARGET uninstall)
538+ configure_file (
539+ "${CMAKE_CURRENT_SOURCE_DIR} /cmake_uninstall.cmake.in"
540+ "${CMAKE_CURRENT_BINARY_DIR} /cmake_uninstall.cmake"
541+ IMMEDIATE @ONLY )
545542
546- add_custom_target (uninstall
547- COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR} /cmake_uninstall.cmake )
543+ add_custom_target (uninstall
544+ COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR} /cmake_uninstall.cmake )
545+ endif ()
548546endif ()
0 commit comments