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(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fsanitize=${GEANT4_BUILD_SANITIZER}")
0275
0276 geant4_add_feature(GEANT4_BUILD_SANITIZER "Compiling/linking with sanitizer '${GEANT4_BUILD_SANITIZER}'")
0277 endif()
0278 endif()
0279
0280 #.rst:
0281 # - ``GEANT4_BUILD_ENABLE_ASSERTIONS``
0282 # - Build libraries with assertions enabled even in release build types (Release, RelWithDebInfo, MinSizeRel)
0283 #
0284 option(GEANT4_BUILD_ENABLE_ASSERTIONS "Enable assertions regardless of build mode" OFF)
0285 geant4_add_feature(GEANT4_BUILD_ENABLE_ASSERTIONS "Compiling Geant4 with assertions enabled in all build types")
0286 mark_as_advanced(GEANT4_BUILD_ENABLE_ASSERTIONS)
0287
0288 # "Dumb" strip of NDEBUG definition from build type flags
0289 if(GEANT4_BUILD_ENABLE_ASSERTIONS)
0290 foreach(__build_type Release MinSizeRel RelWithDebInfo)
0291 string(TOUPPER ${__build_type} __build_type_uc)
0292 foreach(__lang C CXX)
0293 set(FLAGSET_TO_MODIFY "CMAKE_${__lang}_FLAGS_${__build_type_uc}")
0294 string(REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" " " new_flags "${${FLAGSET_TO_MODIFY}}")
0295 set(${FLAGSET_TO_MODIFY} "${new_flags}")
0296 endforeach()
0297 endforeach()
0298 endif()
0299
0300 # Copy .clang-tidy file to build dir
0301 # - clang-tidy/run-clang-tidy state that by default:
0302 #
0303 # "clang-tidy will attempt to find a file named .clang-tidy for each source file in its parent directories."
0304 #
0305 # Whilst this does appear to be the case, `run-clang-tidy` will report enabled checks
0306 # as the default set, or that of any .clang-tidy found in parent directories of the build dir
0307 # To avoid confusion, copy .clang-tidy into build directory so that run-clang-tidy
0308 # should report correctly
0309 #
0310 if(EXISTS "${PROJECT_SOURCE_DIR}/.clang-tidy")
0311 configure_file("${PROJECT_SOURCE_DIR}/.clang-tidy" "${PROJECT_BINARY_DIR}/.clang-tidy" COPYONLY)
0312 endif()
0313
0314 #-----------------------------------------------------------------------
0315 # Multithreading
0316 #-----------------------------------------------------------------------
0317 #.rst:
0318 # - ``GEANT4_BUILD_MULTITHREADED`` (Default: ``OFF``)
0319 #
0320 # If set to ``ON``, compile Geant4 with support for multithreading.
0321 # On Win32, this option requires use of static libraries only
0322 #
0323 option(GEANT4_BUILD_MULTITHREADED "Enable multithreading in Geant4" ON)
0324 geant4_add_feature(GEANT4_BUILD_MULTITHREADED "Build multithread enabled libraries")
0325
0326 #.rst:
0327 # - ``GEANT4_BUILD_TLS_MODEL`` (Default: ``initial-exec``)
0328 #
0329 # If ``GEANT4_BUILD_MULTITHREADED`` is ``ON`` and a GNU/Clang/Intel
0330 # compiler is being used, then this option may be used to choose the
0331 # Thread Local Storage model. A default of ``initial-exec`` is used
0332 # to provide optimal performance for applications directly linking
0333 # to the Geant4 libraries. The dummy ``auto`` model may be selected
0334 # to leave model selection to the compiler, with no additional flag(s)
0335 # passed to the compiler.
0336 #
0337 if(GEANT4_BUILD_MULTITHREADED)
0338 # - Need Thread Local Storage support (POSIX)
0339 if(UNIX)
0340 check_cxx_source_compiles("__thread int i; int main(){return 0;}" HAVE_TLS)
0341 if(NOT HAVE_TLS)
0342 message(FATAL_ERROR "Configured compiler ${CMAKE_CXX_COMPILER} does not support thread local storage")
0343 endif()
0344 endif()
0345
0346 # - Allow advanced users to select the thread local storage model,
0347 # if the compiler supports it, defaulting to that recommended by Geant4
0348 if(TLSMODEL_IS_AVAILABLE)
0349 enum_option(GEANT4_BUILD_TLS_MODEL
0350 DOC "Build libraries with Thread Local Storage model"
0351 VALUES ${TLSMODEL_IS_AVAILABLE}
0352 CASE_INSENSITIVE
0353 )
0354 mark_as_advanced(GEANT4_BUILD_TLS_MODEL)
0355
0356 if(GEANT4_BUILD_TLS_MODEL STREQUAL "auto")
0357 geant4_add_feature(GEANT4_BUILD_TLS_MODEL "Building without explicit TLS model")
0358 else()
0359 geant4_add_feature(GEANT4_BUILD_TLS_MODEL "Building with TLS model '${GEANT4_BUILD_TLS_MODEL}'")
0360 endif()
0361
0362 set(GEANT4_MULTITHREADED_CXX_FLAGS "${GEANT4_MULTITHREADED_CXX_FLAGS} ${${GEANT4_BUILD_TLS_MODEL}_TLSMODEL_FLAGS}")
0363 endif()
0364
0365 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GEANT4_MULTITHREADED_CXX_FLAGS}")
0366 endif()
0367
0368 #-----------------------------------------------------------------------
0369 # Link-time optimization
0370 #-----------------------------------------------------------------------
0371 # If LTO is enabled via CMAKE_INTERPROCEDURAL_OPTIMIZATION, then add
0372 # additional flags to force identify/check ODR violations for GCC only (at present)
0373 # Note that these are _nominally_ enabled by default in GCC with flto, so
0374 # they are added explicitly for the sake of clarity. Also, some are only valid for
0375 # older GCC versions, but they do not break things.
0376 # TODO: Review with experiments what recommended options are here.
0377 if(CMAKE_INTERPROCEDURAL_OPTIMIZATION AND (CMAKE_CXX_COMPILER_ID STREQUAL "GNU"))
0378 string(APPEND CMAKE_CXX_FLAGS " -Wodr -fipa-icf -flto-odr-type-merging")
0379 endif()
0380
0381 #-----------------------------------------------------------------------
0382 # Physics
0383 #-----------------------------------------------------------------------
0384 #.rst:
0385 # - ``GEANT4_BUILD_PHP_AS_HP`` (Default: OFF)
0386 #
0387 # - Build ParticleHP as HP.
0388 #
0389 set(_default_build_php_as_hp OFF)
0390 option(GEANT4_BUILD_PHP_AS_HP "Build ParticleHP as HP" ${_default_build_php_as_hp})
0391 mark_as_advanced(GEANT4_BUILD_PHP_AS_HP)
0392 geant4_add_feature(GEANT4_BUILD_PHP_AS_HP "Building ParticleHP as HP")
0393
0394 #-----------------------------------------------------------------------
0395 # Miscellaneous
0396 #-----------------------------------------------------------------------
0397 #.rst:
0398 # - ``GEANT4_BUILD_STORE_TRAJECTORY`` (Default: ON)
0399 #
0400 # - Switching off can improve performance. Needs to be on
0401 # for visualization to work fully. Mark as advanced because most users
0402 # should not need to worry about it.
0403 #
0404 option(GEANT4_BUILD_STORE_TRAJECTORY
0405 "Store trajectories in event processing. Switch off for improved performance but note that visualization of trajectories will not be possible"
0406 ON)
0407 mark_as_advanced(GEANT4_BUILD_STORE_TRAJECTORY)
0408
0409 #.rst:
0410 # - ``GEANT4_BUILD_VERBOSE_CODE`` (Default: ON)
0411 #
0412 # - Switching off can improve performance, but at the cost
0413 # of fewer informational or warning messages.
0414 # Mark as advanced because most users should not need to worry about it.
0415 #
0416 option(GEANT4_BUILD_VERBOSE_CODE
0417 "Enable verbose output from Geant4 code. Switch off for better performance at the cost of fewer informational messages or warnings"
0418 ON)
0419 mark_as_advanced(GEANT4_BUILD_VERBOSE_CODE)
0420
0421 #.rst:
0422 # - ``GEANT4_BUILD_BUILTIN_BACKTRACE`` (Unix only, Default: OFF)
0423 #
0424 # - Setting to ``ON`` will build in automatic signal handling for ``G4RunManager``
0425 # through ``G4Backtrace``. Applications requiring/implenting their own signal
0426 # handling should not enable this option.
0427 #
0428 if(UNIX)
0429 option(GEANT4_BUILD_BUILTIN_BACKTRACE
0430 "Enable automatic G4Backtrace signal handling in G4RunManager. Switch off for applications implementing their own signal handling"
0431 OFF)
0432 mark_as_advanced(GEANT4_BUILD_BUILTIN_BACKTRACE)
0433 endif()
0434
0435 #.rst:
0436 # - ``GEANT4_BUILD_MSVC_MP`` (Windows only, Default: OFF)
0437 #
0438 # - Provide optional file level parallelization with MSVC compiler.
0439 #
0440
0441 # NB: This will only work if the build tool performs compilations
0442 # with multiple sources, e.g. "cl.exe a.cc b.cc c.cc"
0443 if(MSVC)
0444 option(GEANT4_BUILD_MSVC_MP "Use /MP option with MSVC for file level parallel builds" OFF)
0445 mark_as_advanced(GEANT4_BUILD_MSVC_MP)
0446
0447 if(GEANT4_BUILD_MSVC_MP)
0448 set(CMAKE_CXX_FLAGS "/MP ${CMAKE_CXX_FLAGS}")
0449 endif()
0450 endif()
0451
0452
0453 #-----------------------------------------------------------------------
0454 #.rst:
0455 # Library Mode and Link Options
0456 # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
0457 #
0458 # - ``BUILD_SHARED_LIBS`` (Default: ``ON``)
0459 #
0460 # - Build shared libraries (`.so` on Unix, `.dylib` on macOS, `.dll/.lib` on Windows)
0461 #
0462 # - ``BUILD_STATIC_LIBS`` (Default: ``OFF``)
0463 #
0464 # - Build static libraries (`.a` on Unices, `.lib` on Windows)
0465 #
0466 # Both options are adavanced and may be selected together to build
0467 # both types. If neither is selected, an error is emitted.
0468 #
0469 option(BUILD_SHARED_LIBS "Build Geant4 shared libraries" ON)
0470 option(BUILD_STATIC_LIBS "Build Geant4 static libraries" OFF)
0471 mark_as_advanced(BUILD_SHARED_LIBS BUILD_STATIC_LIBS)
0472
0473 # Because both could be switched off accidently, FATAL_ERROR if neither
0474 # option has been selected.
0475 if(NOT BUILD_STATIC_LIBS AND NOT BUILD_SHARED_LIBS)
0476 message(FATAL_ERROR "Neither static nor shared libraries will be built")
0477 endif()
0478
0479 # Always build global libraries - always FATAL_ERROR if old
0480 # granular library switch is set, e.g. from command line
0481 if(GEANT4_BUILD_GRANULAR_LIBS)
0482 message(FATAL_ERROR " Granular libraries are no longer supported!")
0483 endif()
0484
0485 #------------------------------------------------------------------------
0486 #.rst:
0487 # Build Output Directories
0488 # ------------------------
0489 #
0490 # Because of the highly nested structure of Geant4, built libraries and
0491 # programs will be distributed throughout the build tree. To simplify
0492 # use and testing of the build, CMake is setup to output these products
0493 # to a directory hierarchy based on the configured install locations.
0494
0495 # - Match output layout, so must have variables from GNUInstallDirs...
0496 if((NOT DEFINED CMAKE_INSTALL_BINDIR) OR (NOT DEFINED CMAKE_INSTALL_LIBDIR))
0497 message(FATAL_ERROR "Cannot configure build output dirs as install directories have not yet been defined")
0498 endif()
0499
0500 #.rst
0501 # In all cases, build products are stored in a directory tree rooted
0502 # in a directory named ``BuildProducts`` under the ``PROJECT_BINARY_DIRECTORY``.
0503 #
0504 set(BASE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/BuildProducts")
0505
0506 #.rst:
0507 # For single mode build generators (make, ninja), the following
0508 # hierarchy is used:
0509 #
0510 # .. code-block:: console
0511 #
0512 # +- <PROJECT_BINARY_DIR>/
0513 # +- BuildProducts/
0514 # +- <CMAKE_INSTALL_BINDIR>/
0515 # +- ... "runtime" targets ...
0516 # +- <CMAKE_INSTALL_LIBDIR>/
0517 # +- ... "library" and "archive" targets ...
0518 #
0519
0520 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${BASE_OUTPUT_DIRECTORY}/${CMAKE_INSTALL_BINDIR}")
0521 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${BASE_OUTPUT_DIRECTORY}/${CMAKE_INSTALL_LIBDIR}")
0522 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${BASE_OUTPUT_DIRECTORY}/${CMAKE_INSTALL_LIBDIR}")
0523
0524 #.rst:
0525 # For multimode build generators (Xcode, Visual Studio), each mode
0526 # is separated using the hierarchy
0527 #
0528 # .. code-block:: console
0529 #
0530 # +- <PROJECT_BINARY_DIR>
0531 # +- BuildProducts/
0532 # +- <CONFIG>/
0533 # +- <CMAKE_INSTALL_BINDIR>/
0534 # +- ... "runtime" targets ...
0535 # +- <CMAKE_INSTALL_LIBDIR>/
0536 # +- ... "library" and "archive" targets ...
0537 # +- ...
0538 #
0539 # where ``<CONFIG>`` is repeated for each build configuration listed in
0540 # :cmake:variable:`CMAKE_CONFIGURATION_TYPES <cmake:variable:CMAKE_CONFIGURATION_TYPES>`, e.g. Release, Debug, RelWithDebInfo etc.
0541
0542 foreach(_conftype ${CMAKE_CONFIGURATION_TYPES})
0543 string(TOUPPER ${_conftype} _conftype_uppercase)
0544 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${_conftype_uppercase}
0545 "${BASE_OUTPUT_DIRECTORY}/${_conftype}/${CMAKE_INSTALL_BINDIR}"
0546 )
0547 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${_conftype_uppercase}
0548 "${BASE_OUTPUT_DIRECTORY}/${_conftype}/${CMAKE_INSTALL_LIBDIR}"
0549 )
0550 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${_conftype_uppercase}
0551 "${BASE_OUTPUT_DIRECTORY}/${_conftype}/${CMAKE_INSTALL_LIBDIR}"
0552 )
0553 endforeach()