@@ -24,23 +24,7 @@ enable_language(CXX)
24
24
25
25
include (GNUInstallDirs)
26
26
27
- # CMake versions before 3.14 do not have default destination values. Executable
28
- # and library targets that use a default destination should include this
29
- # variable.
30
- if (CMAKE_VERSION VERSION_LESS "3.14" )
31
- set (INSTALL_DESTINATION_DEFAULT
32
- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
33
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
34
- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
35
- endif ()
36
-
37
- # Wrap the CMake install function so we can disable it.
38
27
set (INSTALL_ENABLED 1)
39
- function (install_if_enabled)
40
- if (INSTALL_ENABLED)
41
- install (${ARGV} )
42
- endif ()
43
- endfunction ()
44
28
45
29
if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT CMAKE_CROSSCOMPILING )
46
30
find_package (PkgConfig QUIET )
@@ -490,29 +474,146 @@ target_include_directories(
490
474
# themselves as dependencies next to the target definition.
491
475
add_custom_target (all_tests)
492
476
493
- add_subdirectory (crypto)
494
477
add_subdirectory (ssl/test )
495
478
add_subdirectory (util/fipstools)
496
479
add_subdirectory (util/fipstools/acvp/modulewrapper)
497
480
481
+ if (OPENSSL_ASM)
482
+ set (CRYPTO_SOURCES_ASM_USED ${CRYPTO_SOURCES_ASM} )
483
+ set (BCM_SOURCES_ASM_USED ${BCM_SOURCES_ASM} )
484
+ set (TEST_SUPPORT_SOURCES_ASM_USED ${TEST_SUPPORT_SOURCES_ASM} )
485
+ elseif (OPENSSL_NASM)
486
+ set (CRYPTO_SOURCES_ASM_USED ${CRYPTO_SOURCES_NASM} )
487
+ set (BCM_SOURCES_ASM_USED ${BCM_SOURCES_NASM} )
488
+ set (TEST_SUPPORT_SOURCES_ASM_USED ${TEST_SUPPORT_SOURCES_NASM} )
489
+ endif ()
490
+
491
+ if (FIPS_DELOCATE AND FIPS_SHARED)
492
+ message (FATAL_ERROR "Can't set both delocate and shared mode for FIPS build" )
493
+ endif ()
494
+
495
+ if (FIPS_DELOCATE)
496
+ add_library (bcm_c_generated_asm STATIC ${BCM_SOURCES} )
497
+ add_dependencies (bcm_c_generated_asm boringssl_prefix_symbols)
498
+ target_include_directories (bcm_c_generated_asm PRIVATE ${PROJECT_SOURCE_DIR} /include )
499
+ set_target_properties (bcm_c_generated_asm PROPERTIES COMPILE_OPTIONS "-S" )
500
+ set_target_properties (bcm_c_generated_asm PROPERTIES POSITION_INDEPENDENT_CODE ON )
501
+
502
+ set (TARGET_FLAG "" )
503
+ if (CMAKE_ASM_COMPILER_TARGET)
504
+ set (TARGET_FLAG "--target=${CMAKE_ASM_COMPILER_TARGET} " )
505
+ endif ()
506
+
507
+ go_executable(delocate boringssl.googlesource.com/boringssl/util/fipstools/delocate)
508
+ add_custom_command (
509
+ OUTPUT bcm-delocated.S
510
+ COMMAND ${CMAKE_CURRENT_BINARY_DIR} /delocate
511
+ -a $<TARGET_FILE:bcm_c_generated_asm>
512
+ -o ${CMAKE_CURRENT_BINARY_DIR} /bcm-delocated.S
513
+ -cc ${CMAKE_ASM_COMPILER}
514
+ -cc-flags "${TARGET_FLAG} ${CMAKE_ASM_FLAGS} "
515
+ ${BCM_SOURCES_ASM_USED}
516
+ ${CRYPTO_HEADERS}
517
+ DEPENDS bcm_c_generated_asm
518
+ delocate
519
+ ${BCM_SOURCES_ASM_USED}
520
+ ${CRYPTO_HEADERS}
521
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
522
+ )
523
+
524
+ add_library (bcm_hashunset STATIC bcm-delocated.S)
525
+ set_target_properties (bcm_hashunset PROPERTIES POSITION_INDEPENDENT_CODE ON )
526
+ set_target_properties (bcm_hashunset PROPERTIES LINKER_LANGUAGE C)
527
+
528
+ go_executable(inject_hash
529
+ boringssl.googlesource.com/boringssl/util/fipstools/inject_hash)
530
+ add_custom_command (
531
+ OUTPUT bcm.o
532
+ COMMAND ./inject_hash -o bcm.o -in-archive $<TARGET_FILE:bcm_hashunset>
533
+ DEPENDS bcm_hashunset inject_hash
534
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
535
+ )
536
+ set (CRYPTO_FIPS_OBJECTS bcm.o)
537
+ elseif (FIPS_SHARED)
538
+ if (NOT BUILD_SHARED_LIBS )
539
+ message (FATAL_ERROR "FIPS_SHARED set but not BUILD_SHARED_LIBS" )
540
+ endif ()
541
+
542
+ add_library (bcm_library STATIC ${BCM_SOURCES} ${BCM_SOURCES_ASM_USED} )
543
+ add_dependencies (bcm_library boringssl_prefix_symbols)
544
+ target_include_directories (bcm_library PRIVATE ${PROJECT_SOURCE_DIR} /include )
545
+
546
+ add_custom_command (
547
+ OUTPUT bcm.o
548
+ COMMAND ${CMAKE_LINKER} -r -T ${CMAKE_CURRENT_SOURCE_DIR} /crypto/fipsmodule/fips_shared.lds -o bcm.o --whole-archive $<TARGET_FILE:bcm_library>
549
+ DEPENDS bcm_library crypto/fipsmodule/fips_shared.lds
550
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
551
+ )
552
+ set (CRYPTO_FIPS_OBJECTS bcm.o)
553
+ else ()
554
+ add_library (fipsmodule OBJECT ${BCM_SOURCES} ${BCM_SOURCES_ASM_USED} )
555
+ add_dependencies (fipsmodule boringssl_prefix_symbols)
556
+ target_include_directories (fipsmodule PRIVATE ${PROJECT_SOURCE_DIR} /include )
557
+ set (CRYPTO_FIPS_OBJECTS $<TARGET_OBJECTS:fipsmodule>)
558
+ endif ()
559
+
560
+ add_library (crypto ${CRYPTO_SOURCES} ${CRYPTO_FIPS_OBJECTS} ${CRYPTO_SOURCES_ASM_USED} )
561
+ target_include_directories (crypto PUBLIC
562
+ $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR} /include >
563
+ $<INSTALL_INTERFACE:include >
564
+ )
565
+ set_property (TARGET crypto PROPERTY EXPORT_NAME Crypto)
566
+
567
+ if (FIPS_SHARED)
568
+ # Rewrite libcrypto.so to inject the correct module hash value. This assumes
569
+ # UNIX-style library naming, but we only support FIPS mode on Linux anyway.
570
+ add_custom_command (
571
+ TARGET crypto POST_BUILD
572
+ COMMAND ${GO_EXECUTABLE} run
573
+ ${CMAKE_CURRENT_SOURCE_DIR} /util/fipstools/inject_hash/inject_hash.go
574
+ -o libcrypto.so -in-object libcrypto.so
575
+ # The DEPENDS argument to a POST_BUILD rule appears to be ignored. Thus
576
+ # go_executable isn't used (as it doesn't get built), but we list this
577
+ # dependency anyway in case it starts working in some CMake version.
578
+ DEPENDS util/fipstools/inject_hash/inject_hash.go
579
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
580
+ )
581
+ endif ()
582
+
583
+ add_dependencies (crypto boringssl_prefix_symbols)
584
+ if (WIN32 )
585
+ target_link_libraries (crypto ws2_32)
586
+ endif ()
587
+
588
+ # CMAKE_SYSTEM_NAME is "Generic" for embedded OSes:
589
+ # https://cmake.org/cmake/help/book/mastering-cmake/chapter/Cross%20Compiling%20With%20CMake.html#toolchain-files
590
+ #
591
+ # For now we assume embedded OSes do not have threads. Additionally, the Threads
592
+ # package does not work with Android, but Android does not require any extra
593
+ # parameters to link pthreads.
594
+ if (NOT CMAKE_SYSTEM_NAME MATCHES "^(Generic|Android)$" )
595
+ find_package (Threads REQUIRED)
596
+ target_link_libraries (crypto Threads::Threads)
597
+ endif ()
598
+
599
+ # Every target depends on crypto, so we add libcxx as a dependency here to
600
+ # simplify injecting it everywhere.
601
+ if (USE_CUSTOM_LIBCXX)
602
+ target_link_libraries (crypto libcxx)
603
+ endif ()
604
+
498
605
add_library (ssl ${SSL_SOURCES} )
499
606
# Although libssl also provides headers that require an include directory, the
500
607
# flag is already specified by libcrypto, so we omit target_include_directories
501
608
# here.
502
- install_if_enabled(TARGETS ssl EXPORT OpenSSLTargets ${INSTALL_DESTINATION_DEFAULT} )
503
609
set_property (TARGET ssl PROPERTY EXPORT_NAME SSL)
504
610
target_link_libraries (ssl crypto)
505
611
506
612
add_library (decrepit ${DECREPIT_SOURCES} )
507
613
target_link_libraries (decrepit crypto ssl)
508
614
509
- add_library (test_support_lib STATIC ${TEST_SUPPORT_SOURCES} )
510
- if (OPENSSL_ASM)
511
- target_sources (test_support_lib PRIVATE ${TEST_SUPPORT_SOURCES_ASM} )
512
- endif ()
513
- if (OPENSSL_NASM)
514
- target_sources (test_support_lib PRIVATE ${TEST_SUPPORT_SOURCES_NASM} )
515
- endif ()
615
+ add_library (test_support_lib STATIC
616
+ ${TEST_SUPPORT_SOURCES} ${TEST_SUPPORT_SOURCES_ASM_USED} )
516
617
if (LIBUNWIND_FOUND)
517
618
target_compile_options (test_support_lib PRIVATE ${LIBUNWIND_CFLAGS_OTHER} )
518
619
target_include_directories (test_support_lib PRIVATE ${LIBUNWIND_INCLUDE_DIRS} )
@@ -562,13 +663,12 @@ set_target_properties(
562
663
COMPILE_FLAGS "${PKI_CXX_FLAGS} " )
563
664
564
665
add_executable (bssl ${BSSL_SOURCES} )
565
- install_if_enabled(TARGETS bssl DESTINATION ${INSTALL_DESTINATION_DEFAULT} )
566
666
target_link_libraries (bssl ssl crypto)
567
667
568
668
# Historically, targets were built in subdirectories. For compatibility with
569
669
# existing tools, we, for now, copy the targets into the subdirectories. This
570
670
# will be removed sometime in 2024.
571
- copy_post_build(crypto crypto_test urandom_test)
671
+ copy_post_build(crypto crypto crypto_test urandom_test)
572
672
copy_post_build(ssl ssl ssl_test)
573
673
copy_post_build(decrepit decrepit decrepit_test)
574
674
copy_post_build(tool bssl)
@@ -643,11 +743,24 @@ add_custom_target(
643
743
DEPENDS all_tests bssl_shim handshaker fips_specific_tests_if_any
644
744
USES_TERMINAL )
645
745
646
- install_if_enabled(DIRECTORY include / DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
746
+ if (INSTALL_ENABLED)
747
+ # CMake versions before 3.14 do not have default destination values. Executable
748
+ # and library targets that use a default destination should include this
749
+ # variable.
750
+ if (CMAKE_VERSION VERSION_LESS "3.14" )
751
+ set (INSTALL_DESTINATION_DEFAULT
752
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
753
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
754
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
755
+ endif ()
647
756
648
- install_if_enabled(EXPORT OpenSSLTargets
649
- FILE OpenSSLTargets.cmake
650
- NAMESPACE OpenSSL::
651
- DESTINATION lib/cmake/OpenSSL
652
- )
653
- install_if_enabled(FILES cmake/OpenSSLConfig.cmake DESTINATION lib/cmake/OpenSSL)
757
+ install (TARGETS crypto ssl
758
+ EXPORT OpenSSLTargets ${INSTALL_DESTINATION_DEFAULT} )
759
+ install (TARGETS bssl DESTINATION ${INSTALL_DESTINATION_DEFAULT} )
760
+ install (DIRECTORY include / DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
761
+ install (EXPORT OpenSSLTargets
762
+ FILE OpenSSLTargets.cmake
763
+ NAMESPACE OpenSSL::
764
+ DESTINATION lib/cmake/OpenSSL)
765
+ install (FILES cmake/OpenSSLConfig.cmake DESTINATION lib/cmake/OpenSSL)
766
+ endif ()
0 commit comments