Back to home page

EIC code displayed by LXR

 
 

    


Warning, /geant4/cmake/Modules/G4BuildSettings.cmake is written in an unsupported language. File is not indexed.

0001 #.rst:
0002 # G4BuildSettings.cmake
0003 # ---------------------
0004 #
0005 # Set defaults for core CMake settings for compiling and linking
0006 # Geant4 libraries and tests,
0007 #
0008 # In addition to the core compiler/linker flags (configured in the
0009 # G4MakeRules_<LANG>.cmake files) for Geant4, the build may require
0010 # further configuration. This module performs this task whicj includes:
0011 #
0012 #  1) Extra build modes for developers
0013 #  2) Additional compiler definitions to assist visualization or optimize
0014 #     performance.
0015 #  3) Additional compiler flags which may be added optionally.
0016 #  4) Whether to build shared and/or static libraries.
0017 #  5) Whether to build libraries in global or granular format.
0018 #
0019 
0020 #-----------------------------------------------------------------
0021 # License and Disclaimer
0022 #
0023 # The  Geant4 software  is  copyright of the Copyright Holders  of
0024 # the Geant4 Collaboration.  It is provided  under  the terms  and
0025 # conditions of the Geant4 Software License,  included in the file
0026 # LICENSE and available at  http://cern.ch/geant4/license .  These
0027 # include a list of copyright holders.
0028 #
0029 # Neither the authors of this software system, nor their employing
0030 # institutes,nor the agencies providing financial support for this
0031 # work  make  any representation or  warranty, express or implied,
0032 # regarding  this  software system or assume any liability for its
0033 # use.  Please see the license in the file  LICENSE  and URL above
0034 # for the full disclaimer and the limitation of liability.
0035 #
0036 # This  code  implementation is the result of  the  scientific and
0037 # technical work of the GEANT4 collaboration.
0038 # By using,  copying,  modifying or  distributing the software (or
0039 # any work based  on the software)  you  agree  to acknowledge its
0040 # use  in  resulting  scientific  publications,  and indicate your
0041 # acceptance of all terms of the Geant4 Software license.
0042 #
0043 #-----------------------------------------------------------------
0044 
0045 if(NOT __G4BUILDSETTINGS_INCLUDED)
0046   set(__G4BUILDSETTINGS_INCLUDED TRUE)
0047 else()
0048   return()
0049 endif()
0050 
0051 #-----------------------------------------------------------------------
0052 #.rst:
0053 # Included Modules
0054 # ^^^^^^^^^^^^^^^^
0055 #
0056 # This module includes the following modules:
0057 #
0058 include(CheckCXXSourceCompiles)
0059 include(IntelCompileFeatures)
0060 include(MSVCCompileFeatures)
0061 
0062 #-----------------------------------------------------------------------
0063 #.rst:
0064 # Build Modes
0065 # ^^^^^^^^^^^
0066 #
0067 # Geant4 supports the standard CMake build types/configurations of
0068 #
0069 # - ``Release``
0070 # - ``Debug``
0071 # - ``MinSizeRel``
0072 # - ``RelWithDebInfo``
0073 #
0074 # For single build type tools like `make` and `ninja`, the build
0075 # defaults to ``Release`` mode unless ``CMAKE_BUILD_TYPE`` is set.
0076 # Multi build type tools like Visual Studio and Xcode will default
0077 # to
0078 #
0079 # On non-WIN32 platforms, two types specifically for development are added:
0080 #
0081 if(NOT WIN32)
0082 
0083 #.rst:
0084 # - ``Debug_FPE``
0085 #   For debugging with full Floating Point Exception checking
0086 #
0087 set(CMAKE_CXX_FLAGS_DEBUG_FPE "${CMAKE_CXX_FLAGS_DEBUG_FPE_INIT}"
0088   CACHE STRING "Flags used by the compiler during Debug_FPE builds"
0089   )
0090 mark_as_advanced(CMAKE_CXX_FLAGS_DEBUG_FPE)
0091 
0092 #.rst:
0093 # - ``TestRelease``:
0094 #   For trial production and extended testing. It has verbose
0095 #   output, has debugging symbols, and adds definitions to allow FPE
0096 #   and physics conservation law testing where supported.
0097 #
0098 set(CMAKE_CXX_FLAGS_TESTRELEASE "${CMAKE_CXX_FLAGS_TESTRELEASE_INIT}"
0099   CACHE STRING "Flags used by the compiler during TestRelease builds"
0100   )
0101 mark_as_advanced(CMAKE_CXX_FLAGS_TESTRELEASE)
0102 
0103 #.rst:
0104 # - ``FullRelWithDebInfo``:
0105 #   For trial production and extended testing. Maximum optimization
0106 #   and debugging symbols
0107 #
0108 set(CMAKE_CXX_FLAGS_FULLRELWITHDEBINFO "${CMAKE_CXX_FLAGS_FULLRELWITHDEBINFO_INIT}"
0109   CACHE STRING "Flags used by the compiler during FullRelWithDebInfo builds"
0110   )
0111 mark_as_advanced(CMAKE_CXX_FLAGS_FULLRELWITHDEBINFO)
0112 
0113 #.rst:
0114 # Compiler flags specific to these build types are set in the cache, and
0115 # the types are added to the ``CMAKE_BUILD_TYPES`` cache string and to
0116 # ``CMAKE_CONFIGURATION_TYPES`` if appropriate to the build tool being used.
0117 #
0118 if(NOT CMAKE_CONFIGURATION_TYPES)
0119   # Single mode build tools like Make, Ninja,
0120   set(__g4buildmodes "" Release TestRelease MinSizeRel Debug Debug_FPE RelWithDebInfo FullRelWithDebInfo)
0121   if(NOT CMAKE_BUILD_TYPE)
0122     # Default to a Release build if nothing else...
0123     set(CMAKE_BUILD_TYPE Release
0124       CACHE STRING "Choose the type of build, options are: None Release TestRelease MinSizeRel Debug Debug_FPE RelWithDebInfo FullRelWithDebInfo."
0125       FORCE
0126       )
0127   else()
0128     # Force to the cache, but use existing value.
0129     set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}"
0130       CACHE STRING "Choose the type of build, options are: None Release TestRelease MinSizeRel Debug Debug_FPE RelWithDebInfo FullRelWithDebInfo."
0131       FORCE
0132       )
0133   endif()
0134   set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${__g4buildmodes})
0135 else()
0136   # Multimode tools like VS, Xcode
0137   list(APPEND CMAKE_CONFIGURATION_TYPES Debug_FPE)
0138   list(APPEND CMAKE_CONFIGURATION_TYPES TestRelease)
0139   list(APPEND CMAKE_CONFIGURATION_TYPES FullRelWithDebInfo)
0140   list(REMOVE_DUPLICATES CMAKE_CONFIGURATION_TYPES)
0141   set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}"
0142     CACHE STRING "Geant4 configurations for multimode build tools"
0143     FORCE
0144     )
0145 endif()
0146 
0147 endif() #NOT WIN32
0148 
0149 
0150 #-----------------------------------------------------------------------
0151 #.rst:
0152 # Compilation Options
0153 # ^^^^^^^^^^^^^^^^^^^
0154 #
0155 # The following options affect the compilation of the Geant4 libraries
0156 #
0157 
0158 #.rst
0159 # - ``CMAKE_CXX_STANDARD`` (Allowed values: 17, 20, 23)
0160 # - ``GEANT4_BUILD_CXXSTD`` (DEPRECATED)
0161 #
0162 #   - Choose C++ Standard to build against from supported list.
0163 #   - C++23 awareness is only available from CMake 3.20 onwards
0164 set(__g4_default_cxxstd 17 20)
0165 
0166 if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.20)
0167   list(APPEND __g4_default_cxxstd 23)
0168 endif()
0169 
0170 if(GEANT4_BUILD_CXXSTD)
0171   message(WARNING
0172     "The GEANT4_BUILD_CXXSTD argument is deprecated.\n"
0173     "Please use CMAKE_CXX_STANDARD to set the required C++ Standard. "
0174     "The value supplied will be used to set CMAKE_CXX_STANDARD, but this behaviour will "
0175     "be removed in future releases.")
0176   set(CMAKE_CXX_STANDARD ${GEANT4_BUILD_CXXSTD})
0177 endif()
0178 
0179 enum_option(CMAKE_CXX_STANDARD
0180   DOC "C++ Standard to compile against"
0181   VALUES ${__g4_default_cxxstd}
0182   CASE_INSENSITIVE
0183   )
0184 
0185 mark_as_advanced(CMAKE_CXX_STANDARD)
0186 geant4_add_feature(CMAKE_CXX_STANDARD "Compiling against C++ Standard '${CMAKE_CXX_STANDARD}'")
0187 
0188 # Setup required CXX variables: must not use vendor extensions, must require standard
0189 # Set convenience variable for compile features to use
0190 set(CMAKE_CXX_EXTENSIONS OFF)
0191 set(CMAKE_CXX_STANDARD_REQUIRED ON)
0192 set(GEANT4_TARGET_COMPILE_FEATURES cxx_std_${CMAKE_CXX_STANDARD})
0193 
0194 # Emit early fatal error if we don't have a record of the requested standard
0195 # in CMake's known features. CMake *will* check this for us as well, but doing
0196 # the check here only emits one error. We can also give a better hint on the
0197 # cause/resolution
0198 if(NOT ("${CMAKE_CXX_COMPILE_FEATURES}" MATCHES "cxx_std_${CMAKE_CXX_STANDARD}"))
0199   message(FATAL_ERROR
0200     "Geant4 requested compilation using C++ standard '${CMAKE_CXX_STANDARD}' with compiler\n"
0201     "'${CMAKE_CXX_COMPILER_ID}', version '${CMAKE_CXX_COMPILER_VERSION}'\n"
0202     "but CMake ${CMAKE_VERSION} is not aware of any support for that standard by this compiler. You may need a newer CMake and/or compiler.\n")
0203 endif()
0204 
0205 # - Check for Language/Standard Library Implementation Features
0206 #
0207 # - A very dumb wrapper round try_compile to give simple reporting
0208 function(check_cxx_feature _flag _bindir _src)
0209   try_compile(${_flag} ${_bindir} ${_src} ${ARGN})
0210   # Can be simplified after 3.17 with CHECK_PASS/FAIL
0211   set(__preamble "Checking C++ feature ${_flag} -")
0212   if(${_flag})
0213     message(STATUS "${__preamble} Success")
0214   else()
0215     message(STATUS "${__preamble} Failed")
0216   endif()
0217 endfunction()
0218 
0219 # - Filesystem may be experimental/filesystem, and in stdc++fs (GCC/libstdc++), c++fs (Clang/libc++)
0220 #   G4global will provide this as a PUBLIC dependency, if required
0221 #   - native stdlib (nothing needed)
0222 #   - GNU: stdc++fs
0223 #   - Clang: c++fs
0224 check_cxx_feature(CXXSTDLIB_FILESYSTEM_NATIVE
0225   ${PROJECT_BINARY_DIR}/cxx_filesystem/native
0226   ${PROJECT_SOURCE_DIR}/cmake/Modules/check_cxx_filesystem.cc)
0227 
0228 if(NOT CXXSTDLIB_FILESYSTEM_NATIVE)
0229   # GNU libstdc++fs
0230   check_cxx_feature(CXXSTDLIB_FILESYSTEM_STDCXXFS
0231     ${PROJECT_BINARY_DIR}/cxx_filesystem/stdc++fs
0232     ${PROJECT_SOURCE_DIR}/cmake/Modules/check_cxx_filesystem.cc
0233     LINK_LIBRARIES stdc++fs)
0234   # LLVM libc++fs
0235   check_cxx_feature(CXXSTDLIB_FILESYSTEM_CXXFS
0236     ${PROJECT_BINARY_DIR}/cxx_filesystem/c++fs
0237     ${PROJECT_SOURCE_DIR}/cmake/Modules/check_cxx_filesystem.cc
0238     LINK_LIBRARIES c++fs)
0239 endif()
0240 # Derive name of library to link to
0241 # Default is native...
0242 if(CXXSTDLIB_FILESYSTEM_NATIVE)
0243   set(GEANT4_CXX_FILESYSTEM_LIBRARY )
0244 elseif(CXXSTDLIB_FILESYSTEM_STDCXXFS)
0245   set(GEANT4_CXX_FILESYSTEM_LIBRARY "stdc++fs")
0246 elseif(CXXSTDLIB_FILESYSTEM_CXXFS)
0247   set(GEANT4_CXX_FILESYSTEM_LIBRARY "c++fs")
0248 else()
0249   message(FATAL_ERROR "No support for C++ filesystem found for compiler '${CMAKE_CXX_COMPILER_ID}', '${CMAKE_CXX_COMPILER_VERSION}'")
0250 endif()
0251 
0252 # Hold any appropriate compile flag(s) in variable for later export to
0253 # non-cmake config files
0254 set(GEANT4_CXXSTD_FLAGS "${CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION}")
0255 
0256 #.rst:
0257 # - ``GEANT4_BUILD_SANITIZER`` (Allowed values: none address thread undefined)
0258 #
0259 #   - Build libraries with instrumentation of the given sanitizer
0260 #   - Only for GNU/Clang at the moment
0261 #   - VS 2019 16.9 supports asan: https://devblogs.microsoft.com/cppblog/address-sanitizer-for-msvc-now-generally-available/)
0262 if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|.*Clang")
0263   enum_option(GEANT4_BUILD_SANITIZER
0264     DOC "Build libraries with sanitizer instrumentation"
0265     VALUES none address thread undefined
0266     CASE_INSENSITIVE)
0267 
0268   mark_as_advanced(GEANT4_BUILD_SANITIZER)
0269 
0270   if(NOT (GEANT4_BUILD_SANITIZER STREQUAL "none"))
0271     # Add flags - longer term, make compile/link options
0272     # frame pointer flag to get more meaningful stack traces
0273     # May need others for better/reliable output
0274     set(__geant4_sanitizer_flags "-fno-omit-frame-pointer -fsanitize=${GEANT4_BUILD_SANITIZER}")
0275     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${__geant4_sanitizer_flags}")
0276     # Xcode does not forward CXX_FLAGS to the linker, and sanitizer link flags need propagating to final
0277     # link steps
0278     if(CMAKE_GENERATOR MATCHES Xcode)
0279       set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${__geant4_sanitizer_flags}")
0280       set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${__geant4_sanitizer_flags}")
0281     endif()
0282 
0283     geant4_add_feature(GEANT4_BUILD_SANITIZER "Compiling/linking with sanitizer '${GEANT4_BUILD_SANITIZER}'")
0284   endif()
0285 endif()
0286 
0287 #.rst:
0288 # - ``GEANT4_BUILD_XCODE_WARNINGS``
0289 #   - Build libraries on macOS command line with extended warnings from Xcode
0290 if(APPLE AND 
0291   (NOT CMAKE_GENERATOR STREQUAL "Xcode") AND
0292   (CMAKE_CXX_COMPILER_ID MATCHES ".*Clang"))
0293 
0294   set(__geant4_appleclang_additional "-Wshorten-64-to-32")
0295   
0296   option(GEANT4_BUILD_XCODE_WARNINGS "Enable additional warnings used by Xcode when building with Command Line Tools")
0297   geant4_add_feature(GEANT4_BUILD_XCODE_WARNINGS "Compiling Geant4 with additional warnings '${__geant4_appleclang_additional}'")
0298   mark_as_advanced(GEANT4_BUILD_XCODE_WARNINGS)
0299 
0300 
0301   if(GEANT4_BUILD_XCODE_WARNINGS)
0302     string(APPEND CMAKE_CXX_FLAGS " ${__geant4_appleclang_additional}")
0303   endif()
0304 endif()
0305 
0306 #.rst:
0307 # - ``GEANT4_BUILD_ENABLE_ASSERTIONS``
0308 #   - Build libraries with assertions enabled even in release build types (Release, RelWithDebInfo, MinSizeRel)
0309 #
0310 option(GEANT4_BUILD_ENABLE_ASSERTIONS "Enable assertions regardless of build mode" OFF)
0311 geant4_add_feature(GEANT4_BUILD_ENABLE_ASSERTIONS "Compiling Geant4 with assertions enabled in all build types")
0312 mark_as_advanced(GEANT4_BUILD_ENABLE_ASSERTIONS)
0313 
0314 # "Dumb" strip of NDEBUG definition from build type flags
0315 if(GEANT4_BUILD_ENABLE_ASSERTIONS)
0316   foreach(__build_type Release MinSizeRel RelWithDebInfo)
0317     string(TOUPPER ${__build_type} __build_type_uc)
0318     foreach(__lang C CXX)
0319       set(FLAGSET_TO_MODIFY "CMAKE_${__lang}_FLAGS_${__build_type_uc}")
0320       string(REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" " " new_flags "${${FLAGSET_TO_MODIFY}}")
0321       set(${FLAGSET_TO_MODIFY} "${new_flags}")
0322     endforeach()
0323   endforeach()
0324 endif()
0325 
0326 # Copy .clang-tidy file to build dir
0327 # - clang-tidy/run-clang-tidy state that by default:
0328 #
0329 #   "clang-tidy will attempt to find a file named .clang-tidy for each source file in its parent directories."
0330 #
0331 #   Whilst this does appear to be the case, `run-clang-tidy` will report enabled checks
0332 #   as the default set, or that of any .clang-tidy found in parent directories of the build dir
0333 #   To avoid confusion, copy .clang-tidy into build directory so that run-clang-tidy
0334 #   should report correctly
0335 #
0336 if(EXISTS "${PROJECT_SOURCE_DIR}/.clang-tidy")
0337   configure_file("${PROJECT_SOURCE_DIR}/.clang-tidy" "${PROJECT_BINARY_DIR}/.clang-tidy" COPYONLY)
0338 endif()
0339 
0340 #-----------------------------------------------------------------------
0341 # Multithreading
0342 #-----------------------------------------------------------------------
0343 #.rst:
0344 # - ``GEANT4_BUILD_MULTITHREADED`` (Default: ``OFF``)
0345 #
0346 #   If set to ``ON``, compile Geant4 with support for multithreading.
0347 #   On Win32, this option requires use of static libraries only
0348 #
0349 option(GEANT4_BUILD_MULTITHREADED "Enable multithreading in Geant4" ON)
0350 geant4_add_feature(GEANT4_BUILD_MULTITHREADED "Build multithread enabled libraries")
0351 
0352 #.rst:
0353 # - ``GEANT4_BUILD_TLS_MODEL`` (Default: ``initial-exec``)
0354 #
0355 #   If ``GEANT4_BUILD_MULTITHREADED`` is ``ON`` and a GNU/Clang/Intel
0356 #   compiler is being used, then this option may be used to choose the
0357 #   Thread Local Storage model. A default of ``initial-exec`` is used
0358 #   to provide optimal performance for applications directly linking
0359 #   to the Geant4 libraries. The dummy ``auto`` model may be selected
0360 #   to leave model selection to the compiler, with no additional flag(s)
0361 #   passed to the compiler.
0362 #
0363 if(GEANT4_BUILD_MULTITHREADED)
0364   # - Need Thread Local Storage support (POSIX)
0365   if(UNIX)
0366     check_cxx_source_compiles("__thread int i; int main(){return 0;}" HAVE_TLS)
0367     if(NOT HAVE_TLS)
0368       message(FATAL_ERROR "Configured compiler ${CMAKE_CXX_COMPILER} does not support thread local storage")
0369     endif()
0370   endif()
0371 
0372   # - Allow advanced users to select the thread local storage model,
0373   # if the compiler supports it, defaulting to that recommended by Geant4
0374   if(TLSMODEL_IS_AVAILABLE)
0375     enum_option(GEANT4_BUILD_TLS_MODEL
0376       DOC "Build libraries with Thread Local Storage model"
0377       VALUES ${TLSMODEL_IS_AVAILABLE}
0378       CASE_INSENSITIVE
0379     )
0380     mark_as_advanced(GEANT4_BUILD_TLS_MODEL)
0381 
0382     if(GEANT4_BUILD_TLS_MODEL STREQUAL "auto")
0383       geant4_add_feature(GEANT4_BUILD_TLS_MODEL "Building without explicit TLS model")
0384     else()
0385       geant4_add_feature(GEANT4_BUILD_TLS_MODEL "Building with TLS model '${GEANT4_BUILD_TLS_MODEL}'")
0386     endif()
0387 
0388     set(GEANT4_MULTITHREADED_CXX_FLAGS "${GEANT4_MULTITHREADED_CXX_FLAGS} ${${GEANT4_BUILD_TLS_MODEL}_TLSMODEL_FLAGS}")
0389   endif()
0390 
0391   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GEANT4_MULTITHREADED_CXX_FLAGS}")
0392 endif()
0393 
0394 #-----------------------------------------------------------------------
0395 # Link-time optimization
0396 #-----------------------------------------------------------------------
0397 # If LTO is enabled via CMAKE_INTERPROCEDURAL_OPTIMIZATION, then add
0398 # additional flags to force identify/check ODR violations for GCC only (at present)
0399 # Note that these are _nominally_ enabled by default in GCC with flto, so
0400 # they are added explicitly for the sake of clarity. Also, some are only valid for 
0401 # older GCC versions, but they do not break things.
0402 # TODO: Review with experiments what recommended options are here.
0403 if(CMAKE_INTERPROCEDURAL_OPTIMIZATION AND (CMAKE_CXX_COMPILER_ID STREQUAL "GNU"))
0404   string(APPEND CMAKE_CXX_FLAGS " -Wodr -fipa-icf -flto-odr-type-merging") 
0405 endif()
0406 
0407 #-----------------------------------------------------------------------
0408 # Physics
0409 #-----------------------------------------------------------------------
0410 #.rst:
0411 # - ``GEANT4_BUILD_PHP_AS_HP`` (Default: OFF)
0412 #
0413 #   - Build ParticleHP as HP.
0414 #
0415 set(_default_build_php_as_hp OFF)
0416 option(GEANT4_BUILD_PHP_AS_HP "Build ParticleHP as HP" ${_default_build_php_as_hp})
0417 mark_as_advanced(GEANT4_BUILD_PHP_AS_HP)
0418 geant4_add_feature(GEANT4_BUILD_PHP_AS_HP "Building ParticleHP as HP")
0419 
0420 #-----------------------------------------------------------------------
0421 # Miscellaneous
0422 #-----------------------------------------------------------------------
0423 #.rst:
0424 # - ``GEANT4_BUILD_STORE_TRAJECTORY`` (Default: ON)
0425 #
0426 #   - Switching off can improve performance. Needs to be on
0427 #     for visualization to work fully. Mark as advanced because most users
0428 #     should not need to worry about it.
0429 #
0430 option(GEANT4_BUILD_STORE_TRAJECTORY
0431   "Store trajectories in event processing. Switch off for improved performance but note that visualization of trajectories will not be possible"
0432   ON)
0433 mark_as_advanced(GEANT4_BUILD_STORE_TRAJECTORY)
0434 
0435 #.rst:
0436 # - ``GEANT4_BUILD_VERBOSE_CODE`` (Default: ON)
0437 #
0438 #   - Switching off can improve performance, but at the cost
0439 #     of fewer informational or warning messages.
0440 #     Mark as advanced because most users should not need to worry about it.
0441 #
0442 option(GEANT4_BUILD_VERBOSE_CODE
0443   "Enable verbose output from Geant4 code. Switch off for better performance at the cost of fewer informational messages or warnings"
0444   ON)
0445 mark_as_advanced(GEANT4_BUILD_VERBOSE_CODE)
0446 
0447 #.rst:
0448 # - ``GEANT4_BUILD_BUILTIN_BACKTRACE`` (Unix only, Default: OFF)
0449 #
0450 #   - Setting to ``ON`` will build in automatic signal handling for ``G4RunManager``
0451 #     through ``G4Backtrace``. Applications requiring/implenting their own signal
0452 #     handling should not enable this option.
0453 #
0454 if(UNIX)
0455   option(GEANT4_BUILD_BUILTIN_BACKTRACE
0456     "Enable automatic G4Backtrace signal handling in G4RunManager. Switch off for applications implementing their own signal handling"
0457     OFF)
0458   mark_as_advanced(GEANT4_BUILD_BUILTIN_BACKTRACE)
0459 endif()
0460 
0461 #.rst:
0462 # - ``GEANT4_BUILD_MSVC_MP`` (Windows only, Default: OFF)
0463 #
0464 #    - Provide optional file level parallelization with MSVC compiler.
0465 #
0466 
0467 # NB: This will only work if the build tool performs compilations
0468 # with multiple sources, e.g. "cl.exe a.cc b.cc c.cc"
0469 if(MSVC)
0470   option(GEANT4_BUILD_MSVC_MP "Use /MP option with MSVC for file level parallel builds" OFF)
0471   mark_as_advanced(GEANT4_BUILD_MSVC_MP)
0472 
0473   if(GEANT4_BUILD_MSVC_MP)
0474     set(CMAKE_CXX_FLAGS "/MP ${CMAKE_CXX_FLAGS}")
0475   endif()
0476 endif()
0477 
0478 
0479 #-----------------------------------------------------------------------
0480 #.rst:
0481 # Library Mode and Link Options
0482 # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
0483 #
0484 # - ``BUILD_SHARED_LIBS`` (Default: ``ON``)
0485 #
0486 #   - Build shared libraries (`.so` on Unix, `.dylib` on macOS, `.dll/.lib` on Windows)
0487 #
0488 # - ``BUILD_STATIC_LIBS`` (Default: ``OFF``)
0489 #
0490 #   - Build static libraries (`.a` on Unices, `.lib` on Windows)
0491 #
0492 # Both options are adavanced and may be selected together to build
0493 # both types. If neither is selected, an error is emitted.
0494 #
0495 option(BUILD_SHARED_LIBS "Build Geant4 shared libraries" ON)
0496 option(BUILD_STATIC_LIBS "Build Geant4 static libraries" OFF)
0497 mark_as_advanced(BUILD_SHARED_LIBS BUILD_STATIC_LIBS)
0498 
0499 # Because both could be switched off accidently, FATAL_ERROR if neither
0500 # option has been selected.
0501 if(NOT BUILD_STATIC_LIBS AND NOT BUILD_SHARED_LIBS)
0502   message(FATAL_ERROR "Neither static nor shared libraries will be built")
0503 endif()
0504 
0505 # Always build global libraries - always FATAL_ERROR if old
0506 # granular library switch is set, e.g. from command line
0507 if(GEANT4_BUILD_GRANULAR_LIBS)
0508   message(FATAL_ERROR " Granular libraries are no longer supported!")
0509 endif()
0510 
0511 #------------------------------------------------------------------------
0512 #.rst:
0513 # Build Output Directories
0514 # ------------------------
0515 #
0516 # Because of the highly nested structure of Geant4, built libraries and
0517 # programs will be distributed throughout the build tree. To simplify
0518 # use and testing of the build, CMake is setup to output these products
0519 # to a directory hierarchy based on the configured install locations.
0520 
0521 # - Match output layout, so must have variables from GNUInstallDirs...
0522 if((NOT DEFINED CMAKE_INSTALL_BINDIR) OR (NOT DEFINED CMAKE_INSTALL_LIBDIR))
0523   message(FATAL_ERROR "Cannot configure build output dirs as install directories have not yet been defined")
0524 endif()
0525 
0526 #.rst
0527 # In all cases, build products are stored in a directory tree rooted
0528 # in a directory named ``BuildProducts`` under the ``PROJECT_BINARY_DIRECTORY``.
0529 #
0530 set(BASE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/BuildProducts")
0531 
0532 #.rst:
0533 # For single mode build generators (make, ninja), the following
0534 #  hierarchy is used:
0535 #
0536 #  .. code-block:: console
0537 #
0538 #    +- <PROJECT_BINARY_DIR>/
0539 #       +- BuildProducts/
0540 #          +- <CMAKE_INSTALL_BINDIR>/
0541 #             +- ... "runtime" targets ...
0542 #          +- <CMAKE_INSTALL_LIBDIR>/
0543 #             +- ... "library" and "archive" targets ...
0544 #
0545 
0546 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${BASE_OUTPUT_DIRECTORY}/${CMAKE_INSTALL_BINDIR}")
0547 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${BASE_OUTPUT_DIRECTORY}/${CMAKE_INSTALL_LIBDIR}")
0548 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${BASE_OUTPUT_DIRECTORY}/${CMAKE_INSTALL_LIBDIR}")
0549 
0550 #.rst:
0551 #  For multimode build generators (Xcode, Visual Studio), each mode
0552 #  is separated using the hierarchy
0553 #
0554 #  .. code-block:: console
0555 #
0556 #    +- <PROJECT_BINARY_DIR>
0557 #       +- BuildProducts/
0558 #          +- <CONFIG>/
0559 #             +- <CMAKE_INSTALL_BINDIR>/
0560 #                +- ... "runtime" targets ...
0561 #             +- <CMAKE_INSTALL_LIBDIR>/
0562 #                +- ... "library" and "archive" targets ...
0563 #          +- ...
0564 #
0565 #  where ``<CONFIG>`` is repeated for each build configuration listed in
0566 #  :cmake:variable:`CMAKE_CONFIGURATION_TYPES <cmake:variable:CMAKE_CONFIGURATION_TYPES>`, e.g. Release, Debug, RelWithDebInfo etc.
0567 
0568 foreach(_conftype ${CMAKE_CONFIGURATION_TYPES})
0569   string(TOUPPER ${_conftype} _conftype_uppercase)
0570   set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${_conftype_uppercase}
0571     "${BASE_OUTPUT_DIRECTORY}/${_conftype}/${CMAKE_INSTALL_BINDIR}"
0572     )
0573   set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${_conftype_uppercase}
0574     "${BASE_OUTPUT_DIRECTORY}/${_conftype}/${CMAKE_INSTALL_LIBDIR}"
0575     )
0576   set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${_conftype_uppercase}
0577     "${BASE_OUTPUT_DIRECTORY}/${_conftype}/${CMAKE_INSTALL_LIBDIR}"
0578     )
0579 endforeach()