diff --git a/.cmake-format.py b/.cmake-format.py new file mode 100644 index 000000000..3df985a27 --- /dev/null +++ b/.cmake-format.py @@ -0,0 +1,241 @@ +# ---------------------------------- +# Options affecting listfile parsing +# ---------------------------------- +with section("parse"): + + # Specify structure for custom cmake functions + additional_commands = { 'foo': { 'flags': ['BAR', 'BAZ'], + 'kwargs': {'DEPENDS': '*', 'HEADERS': '*', 'SOURCES': '*'}}} + + # Override configurations per-command where available + override_spec = {} + + # Specify variable tags. + vartags = [] + + # Specify property tags. + proptags = [] + +# ----------------------------- +# Options affecting formatting. +# ----------------------------- +with section("format"): + + # Disable formatting entirely, making cmake-format a no-op + disable = False + + # How wide to allow formatted cmake files + line_width = 80 + + # How many spaces to tab for indent + tab_size = 2 + + # If true, lines are indented using tab characters (utf-8 0x09) instead of + # space characters (utf-8 0x20). In cases where the layout would + # require a fractional tab character, the behavior of the fractional + # indentation is governed by + use_tabchars = False + + # If is True, then the value of this variable indicates how + # fractional indentions are handled during whitespace replacement. If set to + # 'use-space', fractional indentation is left as spaces (utf-8 0x20). If set + # to `round-up` fractional indentation is replaced with a single tab character + # (utf-8 0x09) effectively shifting the column to the next tabstop + fractional_tab_policy = 'use-space' + + # If an argument group contains more than this many sub-groups (parg or kwarg + # groups) then force it to a vertical layout. + max_subgroups_hwrap = 2 + + # If a positional argument group contains more than this many arguments, then + # force it to a vertical layout. + max_pargs_hwrap = 6 + + # If a cmdline positional group consumes more than this many lines without + # nesting, then invalidate the layout (and nest) + max_rows_cmdline = 2 + + # If true, separate flow control names from their parentheses with a space + separate_ctrl_name_with_space = False + + # If true, separate function names from parentheses with a space + separate_fn_name_with_space = False + + # If a statement is wrapped to more than one line, than dangle the closing + # parenthesis on its own line. + dangle_parens = False + + # If the trailing parenthesis must be 'dangled' on its on line, then align it + # to this reference: `prefix`: the start of the statement, `prefix-indent`: + # the start of the statement, plus one indentation level, `child`: align to + # the column of the arguments + dangle_align = 'prefix' + + # If the statement spelling length (including space and parenthesis) is + # smaller than this amount, then force reject nested layouts. + min_prefix_chars = 4 + + # If the statement spelling length (including space and parenthesis) is larger + # than the tab width by more than this amount, then force reject un-nested + # layouts. + max_prefix_chars = 10 + + # If a candidate layout is wrapped horizontally but it exceeds this many + # lines, then reject the layout. + max_lines_hwrap = 2 + + # What style line endings to use in the output. + line_ending = 'unix' + + # Format command names consistently as 'lower' or 'upper' case + command_case = 'canonical' + + # Format keywords consistently as 'lower' or 'upper' case + keyword_case = 'unchanged' + + # A list of command names which should always be wrapped + always_wrap = [] + + # If true, the argument lists which are known to be sortable will be sorted + # lexicographicall + enable_sort = True + + # If true, the parsers may infer whether or not an argument list is sortable + # (without annotation). + autosort = False + + # By default, if cmake-format cannot successfully fit everything into the + # desired linewidth it will apply the last, most agressive attempt that it + # made. If this flag is True, however, cmake-format will print error, exit + # with non-zero status code, and write-out nothing + require_valid_layout = False + + # A dictionary mapping layout nodes to a list of wrap decisions. See the + # documentation for more information. + layout_passes = {} + +# ------------------------------------------------ +# Options affecting comment reflow and formatting. +# ------------------------------------------------ +with section("markup"): + + # What character to use for bulleted lists + bullet_char = '*' + + # What character to use as punctuation after numerals in an enumerated list + enum_char = '.' + + # If comment markup is enabled, don't reflow the first comment block in each + # listfile. Use this to preserve formatting of your copyright/license + # statements. + first_comment_is_literal = False + + # If comment markup is enabled, don't reflow any comment block which matches + # this (regex) pattern. Default is `None` (disabled). + literal_comment_pattern = None + + # Regular expression to match preformat fences in comments default= + # ``r'^\s*([`~]{3}[`~]*)(.*)$'`` + fence_pattern = '^\\s*([`~]{3}[`~]*)(.*)$' + + # Regular expression to match rulers in comments default= + # ``r'^\s*[^\w\s]{3}.*[^\w\s]{3}$'`` + ruler_pattern = '^\\s*[^\\w\\s]{3}.*[^\\w\\s]{3}$' + + # If a comment line matches starts with this pattern then it is explicitly a + # trailing comment for the preceeding argument. Default is '#<' + explicit_trailing_pattern = '#<' + + # If a comment line starts with at least this many consecutive hash + # characters, then don't lstrip() them off. This allows for lazy hash rulers + # where the first hash char is not separated by space + hashruler_min_length = 10 + + # If true, then insert a space between the first hash char and remaining hash + # chars in a hash ruler, and normalize its length to fill the column + canonicalize_hashrulers = True + + # enable comment markup parsing and reflow + enable_markup = True + +# ---------------------------- +# Options affecting the linter +# ---------------------------- +with section("lint"): + + # a list of lint codes to disable + disabled_codes = [] + + # regular expression pattern describing valid function names + function_pattern = '[0-9a-z_]+' + + # regular expression pattern describing valid macro names + macro_pattern = '[0-9A-Z_]+' + + # regular expression pattern describing valid names for variables with global + # (cache) scope + global_var_pattern = '[A-Z][0-9A-Z_]+' + + # regular expression pattern describing valid names for variables with global + # scope (but internal semantic) + internal_var_pattern = '_[A-Z][0-9A-Z_]+' + + # regular expression pattern describing valid names for variables with local + # scope + local_var_pattern = '[a-z][a-z0-9_]+' + + # regular expression pattern describing valid names for privatedirectory + # variables + private_var_pattern = '_[0-9a-z_]+' + + # regular expression pattern describing valid names for public directory + # variables + public_var_pattern = '[A-Z][0-9A-Z_]+' + + # regular expression pattern describing valid names for function/macro + # arguments and loop variables. + argument_var_pattern = '[a-z][a-z0-9_]+' + + # regular expression pattern describing valid names for keywords used in + # functions or macros + keyword_pattern = '[A-Z][0-9A-Z_]+' + + # In the heuristic for C0201, how many conditionals to match within a loop in + # before considering the loop a parser. + max_conditionals_custom_parser = 2 + + # Require at least this many newlines between statements + min_statement_spacing = 1 + + # Require no more than this many newlines between statements + max_statement_spacing = 2 + max_returns = 6 + max_branches = 12 + max_arguments = 5 + max_localvars = 15 + max_statements = 50 + +# ------------------------------- +# Options affecting file encoding +# ------------------------------- +with section("encode"): + + # If true, emit the unicode byte-order mark (BOM) at the start of the file + emit_byteorder_mark = False + + # Specify the encoding of the input file. Defaults to utf-8 + input_encoding = 'utf-8' + + # Specify the encoding of the output file. Defaults to utf-8. Note that cmake + # only claims to support utf-8 so be careful when using anything else + output_encoding = 'utf-8' + +# ------------------------------------- +# Miscellaneous configurations options. +# ------------------------------------- +with section("misc"): + + # A dictionary containing any per-command configuration overrides. Currently + # only `command_case` is supported. + per_command = {} + diff --git a/.github/workflows/cmake-format-linter.yml b/.github/workflows/cmake-format-linter.yml new file mode 100644 index 000000000..4d7f66945 --- /dev/null +++ b/.github/workflows/cmake-format-linter.yml @@ -0,0 +1,26 @@ +name: Run cmake-format linter + +on: + pull_request: + branches: [ master, develop ] + + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Format CMake files + id: cmake-format + uses: PuneetMatharu/cmake-format-lint-action@v1.0.1 + with: + args: --config-files .cmake-format.py --in-place + + - name: Commit changes + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_user_name: cmake-format-bot + commit_message: 'Automated commit of cmake-format changes.' \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index e799e8ea0..0fefc8afe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,5 @@ -# SPDX-FileCopyrightText: 2021 Philipp Basler, Margarete Mühlleitner and Jonas Müller +# SPDX-FileCopyrightText: 2021 Philipp Basler, Margarete Mühlleitner and Jonas +# Müller # # SPDX-License-Identifier: GPL-3.0-or-later @@ -7,18 +8,20 @@ project( BSMPT VERSION 2.4.0 LANGUAGES C CXX - DESCRIPTION "BSMPT - Beyond the Standard Model Phase Transitions : A C++ package for the computation of the EWPT in BSM models") + DESCRIPTION + "BSMPT - Beyond the Standard Model Phase Transitions : A C++ package for the computation of the EWPT in BSM models" +) # -------------------------------- options -------------------------------- option(UseLibCMAES "Use libcmaes to minimize the potential" ON) option(UseNLopt "Use NLopt to minimize the potential" ON) -option(MakeAdditionalTesting "Build the executables used for further testing" OFF) +option(MakeAdditionalTesting "Build the executables used for further testing" + OFF) option(BSMPTCompileBaryo "Compile Baryogenesis" ON) option(UseConan "Use conan to get dependencies" OFF) option(EnableCoverage "Enable code coverage" OFF) - set(BSMPT_IS_TOPLEVEL NO) if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) set(BSMPT_IS_TOPLEVEL YES) @@ -47,141 +50,101 @@ if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release") endif(NOT CMAKE_BUILD_TYPE) - - set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin") - - include(LTO) - - if(UseConan) - list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR}) - include(conan) - set(ConanPkgList eigen/3.4.0 - gsl/2.7 - boost/1.78.0) - - if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) - set(ConanPkgList ${ConanPkgList} benchmark/1.6.1) - endif() - if(UseNLopt) - set(ConanPkgList ${ConanPkgList} nlopt/2.7.1) - endif(UseNLopt) - conan_cmake_configure(REQUIRES ${ConanPkgList} - GENERATORS cmake_find_package) - - - conan_cmake_autodetect(settings) - - conan_cmake_install(PATH_OR_REFERENCE . - BUILD missing - REMOTE conancenter - SETTINGS ${settings}) - + include(ConanDependencies) endif(UseConan) - find_package(PkgConfig) find_package(Eigen3 3.3.0 REQUIRED) find_package(Boost 1.66) find_package(GSL 2.1 REQUIRED) - - find_package(Threads REQUIRED) if(NOT BOOST_FOUND) set(BSMPTCompileBaryo OFF) endif() - -set(CodeCoverageExcludesFromOtherPkgs - "${EIGEN3_ROOT_DIR}/*" - "${GSL_ROOT_DIR}/*") +set(CodeCoverageExcludesFromOtherPkgs "${EIGEN3_ROOT_DIR}/*" + "${GSL_ROOT_DIR}/*") if(Boost_FOUND) if(NOT "${Boost_DIR}" STREQUAL "") - set(CodeCoverageExcludesFromOtherPkgs - ${CodeCoverageExcludesFromOtherPkgs} - "${Boost_DIR}/*" - ) + set(CodeCoverageExcludesFromOtherPkgs ${CodeCoverageExcludesFromOtherPkgs} + "${Boost_DIR}/*") endif() if(NOT "${Boost_ROOT_DIR}" STREQUAL "") - set(CodeCoverageExcludesFromOtherPkgs - ${CodeCoverageExcludesFromOtherPkgs} - "${Boost_ROOT_DIR}/*" - ) + set(CodeCoverageExcludesFromOtherPkgs ${CodeCoverageExcludesFromOtherPkgs} + "${Boost_ROOT_DIR}/*") endif() endif() set(EXPORT_CMAES FALSE) include(FetchContent) if(UseLibCMAES AND NOT WIN32) - include(CMAES) + include(CMAES) endif(UseLibCMAES AND NOT WIN32) if(UseNLopt) - find_package(NLopt QUIET) + find_package(NLopt QUIET) if(NLopt_FOUND) if(NOT "${NLopt_ROOT_DIR}" STREQUAL "") - set(CodeCoverageExcludesFromOtherPkgs - ${CodeCoverageExcludesFromOtherPkgs} - "${NLopt_ROOT_DIR}/*" - ) + set(CodeCoverageExcludesFromOtherPkgs ${CodeCoverageExcludesFromOtherPkgs} + "${NLopt_ROOT_DIR}/*") endif() if(NOT "${NLopt_DIR}" STREQUAL "") - set(CodeCoverageExcludesFromOtherPkgs - ${CodeCoverageExcludesFromOtherPkgs} - "${NLopt_DIR}/*" - ) + set(CodeCoverageExcludesFromOtherPkgs ${CodeCoverageExcludesFromOtherPkgs} + "${NLopt_DIR}/*") endif() endif() endif(UseNLopt) if(NOT libcmaes_FOUND AND NOT NLopt_FOUND) - message( FATAL_ERROR "You need at least libcmaes or NLopt." ) + message(FATAL_ERROR "You need at least libcmaes or NLopt.") endif() configure_file(include/BSMPT/config.h.in include/BSMPT/config.h) -# -------------------- Coverage -------------------------------------------------- +# -------------------- Coverage +# -------------------------------------------------- if(EnableCoverage) include(CodeCoverage) append_coverage_compiler_flags() -# set(LCOV_ARGS "--no-external") + # set(LCOV_ARGS "--no-external") set(COVERAGE_EXCLUDES - "/usr/include/*" - "/usr/lib/*" - ${CodeCoverageExcludesFromOtherPkgs} - "${PROJECT_SOURCE_DIR}/tests/*" - "tests/*" - "${PROJECT_SOURCE_DIR}/src/prog/*" - "${PROJECT_SOURCE_DIR}/src/utility/*" - "${PROJECT_SOURCE_DIR}/include/BSMPT/utility/Logger.h" - "${PROJECT_SOURCE_DIR}/src/Kfactors/Kfactors.cpp" - "${PROJECT_SOURCE_DIR}/src/models/ClassPotentialOrigin_deprecated.cpp" - "${PROJECT_SOURCE_DIR}/src/models/ClassTemplate.cpp" - "${PROJECT_SOURCE_DIR}/src/WallThickness/WallThickness1D.cpp" - ) - SETUP_TARGET_FOR_COVERAGE_LCOV( - NAME coverage # New target name - EXECUTABLE ctest -j ${n_cores} # Executable in PROJECT_BINARY_DIR - BASE_DIRECTORY "${PROJECT_SOURCE_DIR}" - ) + "/usr/include/*" + "/usr/lib/*" + ${CodeCoverageExcludesFromOtherPkgs} + "${PROJECT_SOURCE_DIR}/tests/*" + "tests/*" + "${PROJECT_SOURCE_DIR}/src/prog/*" + "${PROJECT_SOURCE_DIR}/src/utility/*" + "${PROJECT_SOURCE_DIR}/include/BSMPT/utility/Logger.h" + "${PROJECT_SOURCE_DIR}/src/Kfactors/Kfactors.cpp" + "${PROJECT_SOURCE_DIR}/src/models/ClassPotentialOrigin_deprecated.cpp" + "${PROJECT_SOURCE_DIR}/src/models/ClassTemplate.cpp" + "${PROJECT_SOURCE_DIR}/src/WallThickness/WallThickness1D.cpp") + setup_target_for_coverage_lcov( + NAME + coverage # New target name + EXECUTABLE + ctest + -j + ${n_cores} # Executable in PROJECT_BINARY_DIR + BASE_DIRECTORY + "${PROJECT_SOURCE_DIR}") endif(EnableCoverage) - find_lto(CXX) - add_subdirectory(src) - # -------------------------- export as cmake package -------------------------- if(PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) include(CMakePackageConfigHelpers) @@ -190,49 +153,30 @@ if(PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) VERSION ${PACKAGE_VERSION} COMPATIBILITY AnyNewerVersion) - set(ExportList - Models - Minimizer - ThermalFunctions - Utility - ) - + set(ExportList Models Minimizer ThermalFunctions Utility) if(BSMPTCompileBaryo) - set(ExportList - ${ExportList} - Baryo - LibWallThickness - Kfactors - ) + set(ExportList ${ExportList} Baryo LibWallThickness Kfactors) endif(BSMPTCompileBaryo) - export( TARGETS ${ExportList} NAMESPACE BSMPT:: - FILE BSMPTTargets.cmake - ) + FILE BSMPTTargets.cmake) if(EXPORT_CMAES) export( TARGETS cmaes NAMESPACE libcmaes:: - APPEND FILE BSMPTTargets.cmake - ) + APPEND + FILE BSMPTTargets.cmake) endif(EXPORT_CMAES) - - - configure_file(tools/cmake/BSMPTConfig.cmake.in BSMPTConfig.cmake @ONLY) - export(PACKAGE BSMPT) endif() - - # ------------------------ Doxygen -------------------------------------------- if(BSMPT_IS_TOPLEVEL) find_package(Doxygen) @@ -241,9 +185,8 @@ if(BSMPT_IS_TOPLEVEL) set(DOXYGEN_USE_MATHJAX YES) set(DOXYGEN_STRIP_FROM_INC_PATH "${CMAKE_CURRENT_SOURCE_DIR}/include") set(DOXYGEN_EXCLUDE - ${CMAKE_CURRENT_SOURCE_DIR}/src/Kfactors/Kfunctions_grid_Part1.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/Kfactors/Kfunctions_grid_Part2.cpp - ) + ${CMAKE_CURRENT_SOURCE_DIR}/src/Kfactors/Kfunctions_grid_Part1.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/Kfactors/Kfunctions_grid_Part2.cpp) set(DOXYGEN_PROJECT_BRIEF ${CMAKE_PROJECT_DESCRIPTION}) set(DOXYGEN_EXTRACT_PRIVATE YES) set(DOXYGEN_GENERATE_TREEVIEW YES) @@ -252,26 +195,26 @@ if(BSMPT_IS_TOPLEVEL) set(DOXYGEN_WARN_IF_DOC_ERROR YES) set(DOXYGEN_USE_MDFILE_AS_MAINPAGE README.md) - doxygen_add_docs(doc + doxygen_add_docs( + doc "${CMAKE_CURRENT_SOURCE_DIR}/include/" "${CMAKE_CURRENT_SOURCE_DIR}/src/" "${CMAKE_CURRENT_SOURCE_DIR}/README.md" "${CMAKE_CURRENT_SOURCE_DIR}/Changelog.md") - else () - message("Doxygen need to be installed to generate the doxygen documentation") + else() + message( + "Doxygen need to be installed to generate the doxygen documentation") endif() endif(BSMPT_IS_TOPLEVEL) - -# -------------------- Testing --------------------------------------------------- +# -------------------- Testing +# --------------------------------------------------- if(BSMPT_IS_TOPLEVEL) - include(CTest) + include(CTest) endif() if(BSMPT_IS_TOPLEVEL AND BUILD_TESTING) - add_subdirectory(tests) + add_subdirectory(tests) endif() - - diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8d3731f2a..341a5a64b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,5 @@ -# SPDX-FileCopyrightText: 2021 Philipp Basler, Margarete Mühlleitner and Jonas Müller +# SPDX-FileCopyrightText: 2021 Philipp Basler, Margarete Mühlleitner and Jonas +# Müller # # SPDX-License-Identifier: GPL-3.0-or-later @@ -11,14 +12,11 @@ if(BSMPTCompileBaryo) endif(BSMPTCompileBaryo) add_subdirectory(ThermalFunctions) - -#==============================Utility================================== +# ==============================Utility================================== add_subdirectory(utility) - - -#==============================EXE====================================== +# ==============================EXE====================================== add_executable(BSMPT prog/BSMPT.cpp) target_link_libraries(BSMPT Minimizer Models Utility) @@ -44,37 +42,32 @@ add_executable(Test prog/Test.cpp) target_link_libraries(Test Minimizer Models Utility) target_compile_features(Test PUBLIC cxx_std_14) - - if(BSMPTCompileBaryo) -add_executable(CalculateEWBG prog/CalculateEWBG.cpp) -target_link_libraries(CalculateEWBG Minimizer Models Baryo Utility) -target_compile_features(CalculateEWBG PUBLIC cxx_std_14) + add_executable(CalculateEWBG prog/CalculateEWBG.cpp) + target_link_libraries(CalculateEWBG Minimizer Models Baryo Utility) + target_compile_features(CalculateEWBG PUBLIC cxx_std_14) else(BSMPTCompileBaryo) message("CalculateEWBG will not compile as Boost is missing") endif(BSMPTCompileBaryo) if(BSMPTCompileBaryo) -add_executable(PlotEWBG_vw prog/PlotEWBG_vw.cpp) -target_link_libraries(PlotEWBG_vw Minimizer Models Baryo Utility) -target_compile_features(PlotEWBG_vw PUBLIC cxx_std_14) + add_executable(PlotEWBG_vw prog/PlotEWBG_vw.cpp) + target_link_libraries(PlotEWBG_vw Minimizer Models Baryo Utility) + target_compile_features(PlotEWBG_vw PUBLIC cxx_std_14) else(BSMPTCompileBaryo) message("PlotEWBG_vw will not compile as Boost is missing") endif(BSMPTCompileBaryo) if(BSMPTCompileBaryo) -add_executable(PlotEWBG_nL prog/PlotEWBG_nL.cpp) -target_link_libraries(PlotEWBG_nL Minimizer Models Baryo Utility) -target_compile_features(PlotEWBG_nL PUBLIC cxx_std_14) + add_executable(PlotEWBG_nL prog/PlotEWBG_nL.cpp) + target_link_libraries(PlotEWBG_nL Minimizer Models Baryo Utility) + target_compile_features(PlotEWBG_nL PUBLIC cxx_std_14) else(BSMPTCompileBaryo) message("PlotEWBG_nL will not compile as Boost is missing") endif(BSMPTCompileBaryo) - - - - -#======================= Additional testing ==================================== +# ======================= Additional testing +# ==================================== if(MakeAdditionalTesting) @@ -94,6 +87,4 @@ if(MakeAdditionalTesting) message("Kfactor_grid will not compile as Boost is missing") endif(BSMPTCompileBaryo) - endif(MakeAdditionalTesting) - diff --git a/src/Kfactors/CMakeLists.txt b/src/Kfactors/CMakeLists.txt index 924cd0380..580216366 100644 --- a/src/Kfactors/CMakeLists.txt +++ b/src/Kfactors/CMakeLists.txt @@ -1,25 +1,21 @@ -# SPDX-FileCopyrightText: 2021 Philipp Basler, Margarete Mühlleitner and Jonas Müller +# SPDX-FileCopyrightText: 2021 Philipp Basler, Margarete Mühlleitner and Jonas +# Müller # # SPDX-License-Identifier: GPL-3.0-or-later set(header_path "${BSMPT_SOURCE_DIR}/include/BSMPT/Kfactors") set(header - ${header_path}/Kfactors.h - ${header_path}/KfactorsinterpolatedGSL.h - ${header_path}/Kfactors_grid/KtildeInterpolation.h - ${header_path}/Kfactors_grid/Kfunctions_grid.h -) + ${header_path}/Kfactors.h ${header_path}/KfactorsinterpolatedGSL.h + ${header_path}/Kfactors_grid/KtildeInterpolation.h + ${header_path}/Kfactors_grid/Kfunctions_grid.h) -set(src - Kfunctions_grid_Part1.cpp - Kfunctions_grid_Part2.cpp - Kfactors.cpp - KfactorsinterpolatedGSL.cpp -) +set(src Kfunctions_grid_Part1.cpp Kfunctions_grid_Part2.cpp Kfactors.cpp + KfactorsinterpolatedGSL.cpp) add_library(Kfactors ${header} ${src}) -target_link_libraries(Kfactors PUBLIC Eigen3::Eigen GSL::gsl Boost::boost Minimizer Utility) +target_link_libraries(Kfactors PUBLIC Eigen3::Eigen GSL::gsl Boost::boost + Minimizer Utility) target_compile_options(Kfactors PUBLIC ${OpenMP_CXX_FLAGS}) target_include_directories(Kfactors PUBLIC ${BSMPT_SOURCE_DIR}/include) target_compile_features(Kfactors PUBLIC cxx_std_14) diff --git a/src/ThermalFunctions/CMakeLists.txt b/src/ThermalFunctions/CMakeLists.txt index f1bd6779f..476759e53 100644 --- a/src/ThermalFunctions/CMakeLists.txt +++ b/src/ThermalFunctions/CMakeLists.txt @@ -1,21 +1,16 @@ -# SPDX-FileCopyrightText: 2021 Philipp Basler, Margarete Mühlleitner and Jonas Müller +# SPDX-FileCopyrightText: 2021 Philipp Basler, Margarete Mühlleitner and Jonas +# Müller # # SPDX-License-Identifier: GPL-3.0-or-later set(header_path "${BSMPT_SOURCE_DIR}/include/BSMPT/ThermalFunctions") set(header - ${header_path}/ThermalFunctions.h - ${header_path}/NegativeBosonSpline.h - ${header_path}/thermalcoefficientcalculator.h -) -set(src - ThermalFunctions.cpp - thermalcoefficientcalculator.cpp -) + ${header_path}/ThermalFunctions.h ${header_path}/NegativeBosonSpline.h + ${header_path}/thermalcoefficientcalculator.h) +set(src ThermalFunctions.cpp thermalcoefficientcalculator.cpp) add_library(ThermalFunctions ${header} ${src}) target_link_libraries(ThermalFunctions PUBLIC GSL::gsl) target_include_directories(ThermalFunctions PUBLIC ${BSMPT_SOURCE_DIR}/include) target_compile_features(ThermalFunctions PUBLIC cxx_std_14) - diff --git a/src/WallThickness/CMakeLists.txt b/src/WallThickness/CMakeLists.txt index 5428b3224..ac200a607 100644 --- a/src/WallThickness/CMakeLists.txt +++ b/src/WallThickness/CMakeLists.txt @@ -1,19 +1,16 @@ -# SPDX-FileCopyrightText: 2021 Philipp Basler, Margarete Mühlleitner and Jonas Müller +# SPDX-FileCopyrightText: 2021 Philipp Basler, Margarete Mühlleitner and Jonas +# Müller # # SPDX-License-Identifier: GPL-3.0-or-later set(header_path "${BSMPT_SOURCE_DIR}/include/BSMPT/WallThickness") -set(header - ${header_path}/WallThicknessLib.h - ${header_path}/WallThicknessCommon.h -) -set(src - WallThicknessLib.cpp - WallThickness1D.cpp -) +set(header ${header_path}/WallThicknessLib.h + ${header_path}/WallThicknessCommon.h) +set(src WallThicknessLib.cpp WallThickness1D.cpp) add_library(LibWallThickness ${header} ${src}) -target_link_libraries(LibWallThickness PUBLIC Eigen3::Eigen GSL::gsl Minimizer Utility Boost::boost Threads::Threads) +target_link_libraries( + LibWallThickness PUBLIC Eigen3::Eigen GSL::gsl Minimizer Utility Boost::boost + Threads::Threads) target_include_directories(LibWallThickness PUBLIC ${BSMPT_SOURCE_DIR}/include) target_compile_features(LibWallThickness PUBLIC cxx_std_14) - diff --git a/src/baryo_calculation/CMakeLists.txt b/src/baryo_calculation/CMakeLists.txt index 5b7825cf2..dbe6705d6 100644 --- a/src/baryo_calculation/CMakeLists.txt +++ b/src/baryo_calculation/CMakeLists.txt @@ -1,30 +1,37 @@ -# SPDX-FileCopyrightText: 2021 Philipp Basler, Margarete Mühlleitner and Jonas Müller +# SPDX-FileCopyrightText: 2021 Philipp Basler, Margarete Mühlleitner and Jonas +# Müller # # SPDX-License-Identifier: GPL-3.0-or-later set(header_path "${BSMPT_SOURCE_DIR}/include/BSMPT/baryo_calculation") set(header - ${header_path}/transport_equations.h - ${header_path}/Fluid_Type/gen_calc.h - ${header_path}/Fluid_Type/gen_func_fluid.h - ${header_path}/Fluid_Type/top_source.h - ${header_path}/Fluid_Type/bot_source.h - ${header_path}/Fluid_Type/tau_source.h - ${header_path}/CalculateEtaInterface.h -) + ${header_path}/transport_equations.h + ${header_path}/Fluid_Type/gen_calc.h + ${header_path}/Fluid_Type/gen_func_fluid.h + ${header_path}/Fluid_Type/top_source.h + ${header_path}/Fluid_Type/bot_source.h + ${header_path}/Fluid_Type/tau_source.h + ${header_path}/CalculateEtaInterface.h) set(src - transport_equations.cpp - Fluid_Type/gen_calc.cpp - Fluid_Type/gen_func_fluid.cpp - Fluid_Type/top_source.cpp - Fluid_Type/bot_source.cpp - Fluid_Type/tau_source.cpp - CalculateEtaInterface.cpp -) + transport_equations.cpp + Fluid_Type/gen_calc.cpp + Fluid_Type/gen_func_fluid.cpp + Fluid_Type/top_source.cpp + Fluid_Type/bot_source.cpp + Fluid_Type/tau_source.cpp + CalculateEtaInterface.cpp) add_library(Baryo ${header} ${src}) -target_link_libraries(Baryo PUBLIC Eigen3::Eigen GSL::gsl Minimizer Kfactors LibWallThickness Utility Boost::boost) -#target_compile_options(Baryo PUBLIC ${OpenMP_CXX_FLAGS}) +target_link_libraries( + Baryo + PUBLIC Eigen3::Eigen + GSL::gsl + Minimizer + Kfactors + LibWallThickness + Utility + Boost::boost) +# target_compile_options(Baryo PUBLIC ${OpenMP_CXX_FLAGS}) target_include_directories(Baryo PUBLIC ${BSMPT_SOURCE_DIR}/include) target_compile_features(Baryo PUBLIC cxx_std_14) diff --git a/src/minimizer/CMakeLists.txt b/src/minimizer/CMakeLists.txt index de4500c38..29f57d9ce 100644 --- a/src/minimizer/CMakeLists.txt +++ b/src/minimizer/CMakeLists.txt @@ -1,53 +1,32 @@ -# SPDX-FileCopyrightText: 2021 Philipp Basler, Margarete Mühlleitner and Jonas Müller +# SPDX-FileCopyrightText: 2021 Philipp Basler, Margarete Mühlleitner and Jonas +# Müller # # SPDX-License-Identifier: GPL-3.0-or-later set(header_path "${BSMPT_SOURCE_DIR}/include/BSMPT/minimizer") -set(header - ${header_path}/Minimizer.h - ${header_path}/MinimizePlane.h - ${header_path}/MinimizeGSL.h -) - -set(src - MinimizeGSL.cpp - Minimizer.cpp - MinimizePlane.cpp -) +set(header ${header_path}/Minimizer.h ${header_path}/MinimizePlane.h + ${header_path}/MinimizeGSL.h) +set(src MinimizeGSL.cpp Minimizer.cpp MinimizePlane.cpp) if(libcmaes_FOUND) - set(header - ${header} - ${header_path}/LibCMAES/MinimizeLibCMAES.h - ) - set(src - ${src} - LibCMAES/MinimizeLibCMAES.cpp - ) + set(header ${header} ${header_path}/LibCMAES/MinimizeLibCMAES.h) + set(src ${src} LibCMAES/MinimizeLibCMAES.cpp) endif() if(NLopt_FOUND) - set(header - ${header} - ${header_path}/LibNLOPT/MinimizeNLOPT.h - ) - set(src - ${src} - LibNLOPT/MinimizeNLOPT.cpp - ) + set(header ${header} ${header_path}/LibNLOPT/MinimizeNLOPT.h) + set(src ${src} LibNLOPT/MinimizeNLOPT.cpp) endif() - - add_library(Minimizer ${header} ${src}) -target_link_libraries(Minimizer PUBLIC Eigen3::Eigen GSL::gsl Threads::Threads Utility Models) +target_link_libraries(Minimizer PUBLIC Eigen3::Eigen GSL::gsl Threads::Threads + Utility Models) if(libcmaes_FOUND) target_link_libraries(Minimizer PRIVATE libcmaes::cmaes OpenMP::OpenMP_CXX) endif() - if(NLopt_FOUND) if(TARGET NLopt::nlopt) target_link_libraries(Minimizer PUBLIC NLopt::nlopt) @@ -57,7 +36,6 @@ if(NLopt_FOUND) endif() target_include_directories(Minimizer PUBLIC ${BSMPT_SOURCE_DIR}/include - ${BSMPT_BINARY_DIR}/include) + ${BSMPT_BINARY_DIR}/include) target_include_directories(Minimizer PUBLIC ${BSMPT_SOURCE_DIR}/include) target_compile_features(Minimizer PUBLIC cxx_std_14) - diff --git a/src/models/CMakeLists.txt b/src/models/CMakeLists.txt index eb7b1f40f..7a31d4f35 100644 --- a/src/models/CMakeLists.txt +++ b/src/models/CMakeLists.txt @@ -1,48 +1,40 @@ -# SPDX-FileCopyrightText: 2021 Philipp Basler, Margarete Mühlleitner and Jonas Müller +# SPDX-FileCopyrightText: 2021 Philipp Basler, Margarete Mühlleitner and Jonas +# Müller # # SPDX-License-Identifier: GPL-3.0-or-later set(header_path "${BSMPT_SOURCE_DIR}/include/BSMPT/models") set(header - - ${header_path}/SMparam.h - - ${header_path}/ModelTestfunctions.h - ${header_path}/IncludeAllModels.h - ${header_path}/ClassPotentialOrigin.h - ${header_path}/ClassPotentialC2HDM.h - ${header_path}/ClassPotentialR2HDM.h - ${header_path}/ClassPotentialRN2HDM.h - ${header_path}/ClassPotentialCxSM.h - ${header_path}/ClassPotentialCPintheDark.h - - # Here you can add your new model - ${header_path}/ClassTemplate.h -) + ${header_path}/SMparam.h + ${header_path}/ModelTestfunctions.h + ${header_path}/IncludeAllModels.h + ${header_path}/ClassPotentialOrigin.h + ${header_path}/ClassPotentialC2HDM.h + ${header_path}/ClassPotentialR2HDM.h + ${header_path}/ClassPotentialRN2HDM.h + ${header_path}/ClassPotentialCxSM.h + ${header_path}/ClassPotentialCPintheDark.h + # Here you can add your new model + ${header_path}/ClassTemplate.h) set(src - - ModelTestfunctions.cpp - - IncludeAllModels.cpp - ClassPotentialOrigin.cpp - ClassPotentialOrigin_deprecated.cpp - - ClassPotentialC2HDM.cpp - ClassPotentialR2HDM.cpp - ClassPotentialRN2HDM.cpp - ClassPotentialCxSM.cpp - ClassPotentialCPintheDark.cpp - - # Here you can add your new model - ClassTemplate.cpp -) + ModelTestfunctions.cpp + IncludeAllModels.cpp + ClassPotentialOrigin.cpp + ClassPotentialOrigin_deprecated.cpp + ClassPotentialC2HDM.cpp + ClassPotentialR2HDM.cpp + ClassPotentialRN2HDM.cpp + ClassPotentialCxSM.cpp + ClassPotentialCPintheDark.cpp + # Here you can add your new model + ClassTemplate.cpp) add_library(Models ${header} ${src}) -target_link_libraries( Models PUBLIC GSL::gsl Eigen3::Eigen Minimizer ThermalFunctions Utility) +target_link_libraries(Models PUBLIC GSL::gsl Eigen3::Eigen Minimizer + ThermalFunctions Utility) target_include_directories(Models PUBLIC ${BSMPT_SOURCE_DIR}/include) target_compile_features(Models PUBLIC cxx_std_14) -# Include code-coverage settings: -#target_link_libraries(Models PUBLIC coverage_config) - +# Include code-coverage settings: target_link_libraries(Models PUBLIC +# coverage_config) diff --git a/src/utility/CMakeLists.txt b/src/utility/CMakeLists.txt index a0a2dc17b..fbf1905ed 100644 --- a/src/utility/CMakeLists.txt +++ b/src/utility/CMakeLists.txt @@ -1,14 +1,10 @@ set(header_path "${BSMPT_SOURCE_DIR}/include/BSMPT/utility") -set(header - ${header_path}/utility.h - ${header_path}/Logger.h) -set(src - utility.cpp - Logger.cpp) +set(header ${header_path}/utility.h ${header_path}/Logger.h) +set(src utility.cpp Logger.cpp) add_library(Utility ${header} ${src}) -target_include_directories(Utility PUBLIC ${BSMPT_SOURCE_DIR}/include ${BSMPT_BINARY_DIR}/include) +target_include_directories(Utility PUBLIC ${BSMPT_SOURCE_DIR}/include + ${BSMPT_BINARY_DIR}/include) if(Boost_FOUND) target_link_libraries(Utility PUBLIC Boost::boost) endif() target_compile_features(Utility PUBLIC cxx_std_14) - diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 488463135..74929b461 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,4 +1,5 @@ -# SPDX-FileCopyrightText: 2021 Philipp Basler, Margarete Mühlleitner and Jonas Müller +# SPDX-FileCopyrightText: 2021 Philipp Basler, Margarete Mühlleitner and Jonas +# Müller # # SPDX-License-Identifier: GPL-3.0-or-later @@ -8,13 +9,13 @@ if(NOT Catch2_FOUND) include(FetchContent) FetchContent_Declare( Catch2 - GIT_SHALLOW TRUE + GIT_SHALLOW TRUE GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG v3.1.0) + GIT_TAG v3.1.0) FetchContent_MakeAvailable(Catch2) set(CodeCoverageExcludesFromOtherPkgs - "${CodeCoverageExcludesFromOtherPkgs} ${Catch2_SOURCE_DIR}/*") + "${CodeCoverageExcludesFromOtherPkgs} ${Catch2_SOURCE_DIR}/*") endif() @@ -22,16 +23,12 @@ list(APPEND CMAKE_MODULE_PATH ${Catch2_SOURCE_DIR}/extras) if(Catch2_FOUND) if(NOT "${Catch2_DIR}" STREQUAL "") - set(CodeCoverageExcludesFromOtherPkgs - ${CodeCoverageExcludesFromOtherPkgs} - "${Catch2_DIR}/*" - ) + set(CodeCoverageExcludesFromOtherPkgs ${CodeCoverageExcludesFromOtherPkgs} + "${Catch2_DIR}/*") endif() if(NOT "${Catch2_ROOT_DIR}" STREQUAL "") - set(CodeCoverageExcludesFromOtherPkgs - ${CodeCoverageExcludesFromOtherPkgs} - "${Catch2_ROOT_DIR}/*" - ) + set(CodeCoverageExcludesFromOtherPkgs ${CodeCoverageExcludesFromOtherPkgs} + "${Catch2_ROOT_DIR}/*") endif() endif() @@ -39,7 +36,3 @@ add_subdirectory(catcheventlistener) add_subdirectory(GenerateTestCompares) add_subdirectory(unittests) add_subdirectory(benchmarks) - - - - diff --git a/tests/GenerateTestCompares/CMakeLists.txt b/tests/GenerateTestCompares/CMakeLists.txt index f0204d08c..77b548e02 100644 --- a/tests/GenerateTestCompares/CMakeLists.txt +++ b/tests/GenerateTestCompares/CMakeLists.txt @@ -1,28 +1,13 @@ -# SPDX-FileCopyrightText: 2021 Philipp Basler, Margarete Mühlleitner and Jonas Müller +# SPDX-FileCopyrightText: 2021 Philipp Basler, Margarete Mühlleitner and Jonas +# Müller # # SPDX-License-Identifier: GPL-3.0-or-later +set(header C2HDM.h R2HDM.h RN2HDM.h CPINTHEDARK.h CXSM.h) -set(header - C2HDM.h - R2HDM.h - RN2HDM.h - CPINTHEDARK.h - CXSM.h - ) - -set(src - C2HDM.cpp - R2HDM.cpp - RN2HDM.cpp - CPINTHEDARK.cpp - CXSM.cpp - ) +set(src C2HDM.cpp R2HDM.cpp RN2HDM.cpp CPINTHEDARK.cpp CXSM.cpp) add_library(TestCompares ${header} ${src}) target_compile_features(TestCompares PUBLIC cxx_std_14) -target_link_libraries(TestCompares PRIVATE Minimizer ) +target_link_libraries(TestCompares PRIVATE Minimizer) target_include_directories(TestCompares PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) - - - diff --git a/tests/benchmarks/CMakeLists.txt b/tests/benchmarks/CMakeLists.txt index 68edf9fae..16c8d1e36 100644 --- a/tests/benchmarks/CMakeLists.txt +++ b/tests/benchmarks/CMakeLists.txt @@ -1,30 +1,29 @@ -# SPDX-FileCopyrightText: 2021 Philipp Basler, Margarete Mühlleitner and Jonas Müller +# SPDX-FileCopyrightText: 2021 Philipp Basler, Margarete Mühlleitner and Jonas +# Müller # # SPDX-License-Identifier: GPL-3.0-or-later - find_package(benchmark QUIET) if(benchmark_FOUND) -set(TESTDIR ${CMAKE_CURRENT_SOURCE_DIR}) + set(TESTDIR ${CMAKE_CURRENT_SOURCE_DIR}) -set(SOURCE_FILES - benchmark-ewpt-c2hdm.cpp) + set(SOURCE_FILES benchmark-ewpt-c2hdm.cpp) -if(BSMPTCompileBaryo) - set(SOURCE_FILES - ${SOURCE_FILES} - benchmark-ewbg-c2hdm.cpp) -endif() -add_executable(benchmarks ${SOURCE_FILES}) -target_link_libraries(benchmarks Minimizer Models Utility TestCompares ThermalFunctions) -target_link_libraries(benchmarks benchmark::benchmark) -target_compile_features(benchmarks PUBLIC cxx_std_14) + if(BSMPTCompileBaryo) + set(SOURCE_FILES ${SOURCE_FILES} benchmark-ewbg-c2hdm.cpp) + endif() + add_executable(benchmarks ${SOURCE_FILES}) + target_link_libraries(benchmarks Minimizer Models Utility TestCompares + ThermalFunctions) + target_link_libraries(benchmarks benchmark::benchmark) + target_compile_features(benchmarks PUBLIC cxx_std_14) -if(BSMPTCompileBaryo) - target_link_libraries(benchmarks Baryo) -endif(BSMPTCompileBaryo) + if(BSMPTCompileBaryo) + target_link_libraries(benchmarks Baryo) + endif(BSMPTCompileBaryo) else() - message(WARNING "Did not find google benchmark. Benchmarks will not be compiled.") + message( + WARNING "Did not find google benchmark. Benchmarks will not be compiled.") endif() diff --git a/tests/catcheventlistener/CMakeLists.txt b/tests/catcheventlistener/CMakeLists.txt index 1304fdbb9..8ece00a20 100644 --- a/tests/catcheventlistener/CMakeLists.txt +++ b/tests/catcheventlistener/CMakeLists.txt @@ -1,4 +1,5 @@ add_library(CatchEventListener catcheventlistener.cpp) target_link_libraries(CatchEventListener PRIVATE Utility Catch2::Catch2WithMain) -target_include_directories(CatchEventListener INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) +target_include_directories(CatchEventListener + INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) target_compile_features(CatchEventListener PUBLIC cxx_std_14) diff --git a/tests/unittests/CMakeLists.txt b/tests/unittests/CMakeLists.txt index 170873593..825d67767 100644 --- a/tests/unittests/CMakeLists.txt +++ b/tests/unittests/CMakeLists.txt @@ -1,15 +1,21 @@ -# SPDX-FileCopyrightText: 2021 Philipp Basler, Margarete Mühlleitner and Jonas Müller +# SPDX-FileCopyrightText: 2021 Philipp Basler, Margarete Mühlleitner and Jonas +# Müller # # SPDX-License-Identifier: GPL-3.0-or-later - set(TESTDIR ${CMAKE_CURRENT_SOURCE_DIR}) - file(GLOB SOURCE_FILES "Test-*.cpp" CONFIURE_DEPENDS) add_executable(GenericTests ${SOURCE_FILES}) -target_link_libraries(GenericTests PRIVATE - Catch2::Catch2WithMain CatchEventListener Minimizer Models Utility TestCompares ThermalFunctions) +target_link_libraries( + GenericTests + PRIVATE Catch2::Catch2WithMain + CatchEventListener + Minimizer + Models + Utility + TestCompares + ThermalFunctions) target_compile_features(GenericTests PUBLIC cxx_std_14) include(Catch) @@ -18,6 +24,3 @@ catch_discover_tests(GenericTests) if(BSMPTCompileBaryo) add_subdirectory(baryotests) endif(BSMPTCompileBaryo) - - - diff --git a/tests/unittests/baryotests/CMakeLists.txt b/tests/unittests/baryotests/CMakeLists.txt index 3d752c969..7379bbbac 100644 --- a/tests/unittests/baryotests/CMakeLists.txt +++ b/tests/unittests/baryotests/CMakeLists.txt @@ -1,11 +1,20 @@ -# SPDX-FileCopyrightText: 2021 Philipp Basler, Margarete Mühlleitner and Jonas Müller +# SPDX-FileCopyrightText: 2021 Philipp Basler, Margarete Mühlleitner and Jonas +# Müller # # SPDX-License-Identifier: GPL-3.0-or-later file(GLOB SOURCE_FILES "Test-*.cpp" CONFIURE_DEPENDS) add_executable(BaryoTests ${SOURCE_FILES}) -target_link_libraries(BaryoTests PRIVATE - Catch2::Catch2WithMain CatchEventListener Minimizer Models Utility TestCompares ThermalFunctions Baryo) +target_link_libraries( + BaryoTests + PRIVATE Catch2::Catch2WithMain + CatchEventListener + Minimizer + Models + Utility + TestCompares + ThermalFunctions + Baryo) target_compile_features(BaryoTests PUBLIC cxx_std_17) include(Catch) diff --git a/tools/cmake/CMAES.cmake b/tools/cmake/CMAES.cmake index 3d77e1560..2567a98fa 100644 --- a/tools/cmake/CMAES.cmake +++ b/tools/cmake/CMAES.cmake @@ -1,36 +1,32 @@ find_package(OpenMP REQUIRED) find_package(libcmaes 0.10 QUIET) - if(NOT libcmaes_FOUND) - set(BSMPT_CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - set(BSMPT_CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") - set(BSMPT_CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") - set(EXPORT_CMAES TRUE) - FetchContent_Declare( - libcmaes - GIT_REPOSITORY https://github.com/CMA-ES/libcmaes.git - GIT_TAG v0.10) - FetchContent_GetProperties(libcmaes) - if(NOT libcmaes_POPULATED) - option(LIBCMAES_BUILD_TESTS OFF) - option(LIBCMAES_BUILD_PYTHON OFF) - option(LIBCMAES_BUILD_EXAMPLES OFF) - FetchContent_Populate(libcmaes) - add_subdirectory(${libcmaes_SOURCE_DIR} ${libcmaes_BINARY_DIR}) - include (GenerateExportHeader) - generate_export_header (cmaes EXPORT_FILE_NAME ${libcmaes_SOURCE_DIR}/include/libcmaes/cmaes_export.h) - message(STATUS ${libcmaes_SOURCE_DIR}) - set(CodeCoverageExcludesFromOtherPkgs - ${CodeCoverageExcludesFromOtherPkgs} - "${libcmaes_SOURCE_DIR}/*" - ) - endif() - - - - set(libcmaes_FOUND TRUE) - else() - set(CodeCoverageExcludesFromOtherPkgs - ${CodeCoverageExcludesFromOtherPkgs} - "${libcmaes_ROOT_DIR}/*" - ) +if(NOT libcmaes_FOUND) + set(BSMPT_CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + set(BSMPT_CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") + set(BSMPT_CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") + set(EXPORT_CMAES TRUE) + FetchContent_Declare( + libcmaes + GIT_REPOSITORY https://github.com/CMA-ES/libcmaes.git + GIT_TAG v0.10) + FetchContent_GetProperties(libcmaes) + if(NOT libcmaes_POPULATED) + option(LIBCMAES_BUILD_TESTS OFF) + option(LIBCMAES_BUILD_PYTHON OFF) + option(LIBCMAES_BUILD_EXAMPLES OFF) + FetchContent_Populate(libcmaes) + add_subdirectory(${libcmaes_SOURCE_DIR} ${libcmaes_BINARY_DIR}) + include(GenerateExportHeader) + generate_export_header( + cmaes EXPORT_FILE_NAME + ${libcmaes_SOURCE_DIR}/include/libcmaes/cmaes_export.h) + message(STATUS ${libcmaes_SOURCE_DIR}) + set(CodeCoverageExcludesFromOtherPkgs ${CodeCoverageExcludesFromOtherPkgs} + "${libcmaes_SOURCE_DIR}/*") endif() + + set(libcmaes_FOUND TRUE) +else() + set(CodeCoverageExcludesFromOtherPkgs ${CodeCoverageExcludesFromOtherPkgs} + "${libcmaes_ROOT_DIR}/*") +endif() diff --git a/tools/cmake/CodeCoverage.cmake b/tools/cmake/CodeCoverage.cmake index aef3d9436..84cb99bba 100644 --- a/tools/cmake/CodeCoverage.cmake +++ b/tools/cmake/CodeCoverage.cmake @@ -1,134 +1,113 @@ -# Copyright (c) 2012 - 2017, Lars Bilke -# All rights reserved. +# Copyright (c) 2012 - 2017, Lars Bilke All rights reserved. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors -# may be used to endorse or promote products derived from this software without -# specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# list of conditions and the following disclaimer. +# +# 1. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 1. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # CHANGES: # -# 2012-01-31, Lars Bilke -# - Enable Code Coverage +# 2012-01-31, Lars Bilke - Enable Code Coverage # -# 2013-09-17, Joakim Söderberg -# - Added support for Clang. -# - Some additional usage instructions. +# 2013-09-17, Joakim Söderberg - Added support for Clang. - Some additional +# usage instructions. # -# 2016-02-03, Lars Bilke -# - Refactored functions to use named parameters +# 2016-02-03, Lars Bilke - Refactored functions to use named parameters # -# 2017-06-02, Lars Bilke -# - Merged with modified version from github.com/ufz/ogs +# 2017-06-02, Lars Bilke - Merged with modified version from github.com/ufz/ogs # -# 2019-05-06, Anatolii Kurotych -# - Remove unnecessary --coverage flag +# 2019-05-06, Anatolii Kurotych - Remove unnecessary --coverage flag # -# 2019-12-13, FeRD (Frank Dana) -# - Deprecate COVERAGE_LCOVR_EXCLUDES and COVERAGE_GCOVR_EXCLUDES lists in favor -# of tool-agnostic COVERAGE_EXCLUDES variable, or EXCLUDE setup arguments. -# - CMake 3.4+: All excludes can be specified relative to BASE_DIRECTORY -# - All setup functions: accept BASE_DIRECTORY, EXCLUDE list -# - Set lcov basedir with -b argument -# - Add automatic --demangle-cpp in lcovr, if 'c++filt' is available (can be -# overridden with NO_DEMANGLE option in setup_target_for_coverage_lcovr().) -# - Delete output dir, .info file on 'make clean' -# - Remove Python detection, since version mismatches will break gcovr -# - Minor cleanup (lowercase function names, update examples...) +# 2019-12-13, FeRD (Frank Dana) - Deprecate COVERAGE_LCOVR_EXCLUDES and +# COVERAGE_GCOVR_EXCLUDES lists in favor of tool-agnostic COVERAGE_EXCLUDES +# variable, or EXCLUDE setup arguments. - CMake 3.4+: All excludes can be +# specified relative to BASE_DIRECTORY - All setup functions: accept +# BASE_DIRECTORY, EXCLUDE list - Set lcov basedir with -b argument - Add +# automatic --demangle-cpp in lcovr, if 'c++filt' is available (can be +# overridden with NO_DEMANGLE option in setup_target_for_coverage_lcovr().) - +# Delete output dir, .info file on 'make clean' - Remove Python detection, since +# version mismatches will break gcovr - Minor cleanup (lowercase function names, +# update examples...) # -# 2019-12-19, FeRD (Frank Dana) -# - Rename Lcov outputs, make filtered file canonical, fix cleanup for targets +# 2019-12-19, FeRD (Frank Dana) - Rename Lcov outputs, make filtered file +# canonical, fix cleanup for targets # -# 2020-01-19, Bob Apthorpe -# - Added gfortran support +# 2020-01-19, Bob Apthorpe - Added gfortran support # -# 2020-02-17, FeRD (Frank Dana) -# - Make all add_custom_target()s VERBATIM to auto-escape wildcard characters -# in EXCLUDEs, and remove manual escaping from gcovr targets +# 2020-02-17, FeRD (Frank Dana) - Make all add_custom_target()s VERBATIM to +# auto-escape wildcard characters in EXCLUDEs, and remove manual escaping from +# gcovr targets # -# 2021-01-19, Robin Mueller -# - Add CODE_COVERAGE_VERBOSE option which will allow to print out commands which are run -# - Added the option for users to set the GCOVR_ADDITIONAL_ARGS variable to supply additional -# flags to the gcovr command +# 2021-01-19, Robin Mueller - Add CODE_COVERAGE_VERBOSE option which will allow +# to print out commands which are run - Added the option for users to set the +# GCOVR_ADDITIONAL_ARGS variable to supply additional flags to the gcovr command # -# 2020-05-04, Mihchael Davis -# - Add -fprofile-abs-path to make gcno files contain absolute paths -# - Fix BASE_DIRECTORY not working when defined -# - Change BYPRODUCT from folder to index.html to stop ninja from complaining about double defines +# 2020-05-04, Mihchael Davis - Add -fprofile-abs-path to make gcno files contain +# absolute paths - Fix BASE_DIRECTORY not working when defined - Change +# BYPRODUCT from folder to index.html to stop ninja from complaining about +# double defines # -# 2021-05-10, Martin Stump -# - Check if the generator is multi-config before warning about non-Debug builds +# 2021-05-10, Martin Stump - Check if the generator is multi-config before +# warning about non-Debug builds # -# 2022-02-22, Marko Wehle -# - Change gcovr output from -o for --xml and --html output respectively. -# This will allow for Multiple Output Formats at the same time by making use of GCOVR_ADDITIONAL_ARGS, e.g. GCOVR_ADDITIONAL_ARGS "--txt". +# 2022-02-22, Marko Wehle - Change gcovr output from -o for --xml +# and --html output respectively. This will allow for +# Multiple Output Formats at the same time by making use of +# GCOVR_ADDITIONAL_ARGS, e.g. GCOVR_ADDITIONAL_ARGS "--txt". # # USAGE: # # 1. Copy this file into your cmake modules path. # -# 2. Add the following line to your CMakeLists.txt (best inside an if-condition -# using a CMake option() to enable it just optionally): -# include(CodeCoverage) +# 1. Add the following line to your CMakeLists.txt (best inside an if-condition +# using a CMake option() to enable it just optionally): include(CodeCoverage) # -# 3. Append necessary compiler flags for all supported source files: -# append_coverage_compiler_flags() -# Or for specific target: -# append_coverage_compiler_flags_to_target(YOUR_TARGET_NAME) +# 1. Append necessary compiler flags for all supported source files: +# append_coverage_compiler_flags() Or for specific target: +# append_coverage_compiler_flags_to_target(YOUR_TARGET_NAME) # # 3.a (OPTIONAL) Set appropriate optimization flags, e.g. -O0, -O1 or -Og # -# 4. If you need to exclude additional directories from the report, specify them -# using full paths in the COVERAGE_EXCLUDES variable before calling -# setup_target_for_coverage_*(). -# Example: -# set(COVERAGE_EXCLUDES -# '${PROJECT_SOURCE_DIR}/src/dir1/*' -# '/path/to/my/src/dir2/*') -# Or, use the EXCLUDE argument to setup_target_for_coverage_*(). -# Example: -# setup_target_for_coverage_lcov( -# NAME coverage -# EXECUTABLE testrunner -# EXCLUDE "${PROJECT_SOURCE_DIR}/src/dir1/*" "/path/to/my/src/dir2/*") +# 1. If you need to exclude additional directories from the report, specify them +# using full paths in the COVERAGE_EXCLUDES variable before calling +# setup_target_for_coverage_*(). Example: set(COVERAGE_EXCLUDES +# '${PROJECT_SOURCE_DIR}/src/dir1/*' +# '/path/to/my/src/dir2/*') Or, use the EXCLUDE argument to +# setup_target_for_coverage_*(). Example: setup_target_for_coverage_lcov( NAME +# coverage EXECUTABLE testrunner EXCLUDE "${PROJECT_SOURCE_DIR}/src/dir1/*" +# "/path/to/my/src/dir2/*") # # 4.a NOTE: With CMake 3.4+, COVERAGE_EXCLUDES or EXCLUDE can also be set -# relative to the BASE_DIRECTORY (default: PROJECT_SOURCE_DIR) -# Example: -# set(COVERAGE_EXCLUDES "dir1/*") -# setup_target_for_coverage_gcovr_html( -# NAME coverage -# EXECUTABLE testrunner -# BASE_DIRECTORY "${PROJECT_SOURCE_DIR}/src" -# EXCLUDE "dir2/*") +# relative to the BASE_DIRECTORY (default: PROJECT_SOURCE_DIR) Example: +# set(COVERAGE_EXCLUDES "dir1/*") setup_target_for_coverage_gcovr_html( NAME +# coverage EXECUTABLE testrunner BASE_DIRECTORY "${PROJECT_SOURCE_DIR}/src" +# EXCLUDE "dir2/*") # -# 5. Use the functions described below to create a custom make target which -# runs your test executable and produces a code coverage report. +# 1. Use the functions described below to create a custom make target which runs +# your test executable and produces a code coverage report. # -# 6. Build a Debug build: -# cmake -DCMAKE_BUILD_TYPE=Debug .. -# make -# make my_coverage_target +# 1. Build a Debug build: cmake -DCMAKE_BUILD_TYPE=Debug .. make make +# my_coverage_target # include(CMakeParseArguments) @@ -136,584 +115,653 @@ include(CMakeParseArguments) option(CODE_COVERAGE_VERBOSE "Verbose information" FALSE) # Check prereqs -find_program( GCOV_PATH gcov ) -find_program( LCOV_PATH NAMES lcov lcov.bat lcov.exe lcov.perl) -find_program( FASTCOV_PATH NAMES fastcov fastcov.py ) -find_program( GENHTML_PATH NAMES genhtml genhtml.perl genhtml.bat ) -find_program( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/scripts/test) -find_program( CPPFILT_PATH NAMES c++filt ) +find_program(GCOV_PATH gcov) +find_program(LCOV_PATH NAMES lcov lcov.bat lcov.exe lcov.perl) +find_program(FASTCOV_PATH NAMES fastcov fastcov.py) +find_program(GENHTML_PATH NAMES genhtml genhtml.perl genhtml.bat) +find_program(GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/scripts/test) +find_program(CPPFILT_PATH NAMES c++filt) if(NOT GCOV_PATH) - message(FATAL_ERROR "gcov not found! Aborting...") + message(FATAL_ERROR "gcov not found! Aborting...") endif() # NOT GCOV_PATH get_property(LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES) list(GET LANGUAGES 0 LANG) if("${CMAKE_${LANG}_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang") - if("${CMAKE_${LANG}_COMPILER_VERSION}" VERSION_LESS 3) - message(FATAL_ERROR "Clang version must be 3.0.0 or greater! Aborting...") - endif() + if("${CMAKE_${LANG}_COMPILER_VERSION}" VERSION_LESS 3) + message(FATAL_ERROR "Clang version must be 3.0.0 or greater! Aborting...") + endif() elseif(NOT CMAKE_COMPILER_IS_GNUCXX) - if("${CMAKE_Fortran_COMPILER_ID}" MATCHES "[Ff]lang") - # Do nothing; exit conditional without error if true - elseif("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU") - # Do nothing; exit conditional without error if true - else() - message(FATAL_ERROR "Compiler is not GNU gcc! Aborting...") - endif() + if("${CMAKE_Fortran_COMPILER_ID}" MATCHES "[Ff]lang") + # Do nothing; exit conditional without error if true + elseif("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU") + # Do nothing; exit conditional without error if true + else() + message(FATAL_ERROR "Compiler is not GNU gcc! Aborting...") + endif() endif() -set(COVERAGE_COMPILER_FLAGS "-g -fprofile-arcs -ftest-coverage" +set(COVERAGE_COMPILER_FLAGS + "-g -fprofile-arcs -ftest-coverage" CACHE INTERNAL "") if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)") - include(CheckCXXCompilerFlag) - check_cxx_compiler_flag(-fprofile-abs-path HAVE_fprofile_abs_path) - if(HAVE_fprofile_abs_path) - set(COVERAGE_COMPILER_FLAGS "${COVERAGE_COMPILER_FLAGS} -fprofile-abs-path") - endif() + include(CheckCXXCompilerFlag) + check_cxx_compiler_flag(-fprofile-abs-path HAVE_fprofile_abs_path) + if(HAVE_fprofile_abs_path) + set(COVERAGE_COMPILER_FLAGS "${COVERAGE_COMPILER_FLAGS} -fprofile-abs-path") + endif() endif() set(CMAKE_Fortran_FLAGS_COVERAGE ${COVERAGE_COMPILER_FLAGS} CACHE STRING "Flags used by the Fortran compiler during coverage builds." - FORCE ) + FORCE) set(CMAKE_CXX_FLAGS_COVERAGE ${COVERAGE_COMPILER_FLAGS} - CACHE STRING "Flags used by the C++ compiler during coverage builds." - FORCE ) + CACHE STRING "Flags used by the C++ compiler during coverage builds." FORCE) set(CMAKE_C_FLAGS_COVERAGE ${COVERAGE_COMPILER_FLAGS} - CACHE STRING "Flags used by the C compiler during coverage builds." - FORCE ) + CACHE STRING "Flags used by the C compiler during coverage builds." FORCE) set(CMAKE_EXE_LINKER_FLAGS_COVERAGE "" CACHE STRING "Flags used for linking binaries during coverage builds." - FORCE ) + FORCE) set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE "" - CACHE STRING "Flags used by the shared libraries linker during coverage builds." - FORCE ) + CACHE STRING + "Flags used by the shared libraries linker during coverage builds." + FORCE) mark_as_advanced( - CMAKE_Fortran_FLAGS_COVERAGE - CMAKE_CXX_FLAGS_COVERAGE - CMAKE_C_FLAGS_COVERAGE - CMAKE_EXE_LINKER_FLAGS_COVERAGE - CMAKE_SHARED_LINKER_FLAGS_COVERAGE ) + CMAKE_Fortran_FLAGS_COVERAGE CMAKE_CXX_FLAGS_COVERAGE CMAKE_C_FLAGS_COVERAGE + CMAKE_EXE_LINKER_FLAGS_COVERAGE CMAKE_SHARED_LINKER_FLAGS_COVERAGE) -get_property(GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) +get_property(GENERATOR_IS_MULTI_CONFIG GLOBAL + PROPERTY GENERATOR_IS_MULTI_CONFIG) if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR GENERATOR_IS_MULTI_CONFIG)) - message(WARNING "Code coverage results with an optimised (non-Debug) build may be misleading") + message( + WARNING + "Code coverage results with an optimised (non-Debug) build may be misleading" + ) endif() # NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR GENERATOR_IS_MULTI_CONFIG) -if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") - link_libraries(gcov) +if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_Fortran_COMPILER_ID STREQUAL + "GNU") + link_libraries(gcov) endif() -# Defines a target for running and collection code coverage information -# Builds dependencies, runs the given executable and outputs reports. -# NOTE! The executable should always have a ZERO as exit code otherwise -# the coverage generation will not complete. -# -# setup_target_for_coverage_lcov( -# NAME testrunner_coverage # New target name -# EXECUTABLE testrunner -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR -# DEPENDENCIES testrunner # Dependencies to build first -# BASE_DIRECTORY "../" # Base directory for report -# # (defaults to PROJECT_SOURCE_DIR) -# EXCLUDE "src/dir1/*" "src/dir2/*" # Patterns to exclude (can be relative -# # to BASE_DIRECTORY, with CMake 3.4+) -# NO_DEMANGLE # Don't demangle C++ symbols -# # even if c++filt is found -# ) +# Defines a target for running and collection code coverage information Builds +# dependencies, runs the given executable and outputs reports. NOTE! The +# executable should always have a ZERO as exit code otherwise the coverage +# generation will not complete. +# +# setup_target_for_coverage_lcov( NAME testrunner_coverage # +# New target name EXECUTABLE testrunner -j ${PROCESSOR_COUNT} # Executable in +# PROJECT_BINARY_DIR DEPENDENCIES testrunner # Dependencies +# to build first BASE_DIRECTORY "../" # Base directory +# for report # (defaults to PROJECT_SOURCE_DIR) EXCLUDE "src/dir1/*" +# "src/dir2/*" # Patterns to exclude (can be relative # to +# BASE_DIRECTORY, with CMake 3.4+) NO_DEMANGLE # +# Don't demangle C++ symbols # even if c++filt is found ) function(setup_target_for_coverage_lcov) - set(options NO_DEMANGLE) - set(oneValueArgs BASE_DIRECTORY NAME) - set(multiValueArgs EXCLUDE EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES LCOV_ARGS GENHTML_ARGS) - cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - - if(NOT LCOV_PATH) - message(FATAL_ERROR "lcov not found! Aborting...") - endif() # NOT LCOV_PATH - - if(NOT GENHTML_PATH) - message(FATAL_ERROR "genhtml not found! Aborting...") - endif() # NOT GENHTML_PATH - - # Set base directory (as absolute path), or default to PROJECT_SOURCE_DIR - if(DEFINED Coverage_BASE_DIRECTORY) - get_filename_component(BASEDIR ${Coverage_BASE_DIRECTORY} ABSOLUTE) - else() - set(BASEDIR ${PROJECT_SOURCE_DIR}) - endif() - - # Collect excludes (CMake 3.4+: Also compute absolute paths) - set(LCOV_EXCLUDES "") - foreach(EXCLUDE ${Coverage_EXCLUDE} ${COVERAGE_EXCLUDES} ${COVERAGE_LCOV_EXCLUDES}) - if(CMAKE_VERSION VERSION_GREATER 3.4) - get_filename_component(EXCLUDE ${EXCLUDE} ABSOLUTE BASE_DIR ${BASEDIR}) - endif() - list(APPEND LCOV_EXCLUDES "${EXCLUDE}") - endforeach() - list(REMOVE_DUPLICATES LCOV_EXCLUDES) - - # Conditional arguments - if(CPPFILT_PATH AND NOT ${Coverage_NO_DEMANGLE}) - set(GENHTML_EXTRA_ARGS "--demangle-cpp") - endif() - - # Setting up commands which will be run to generate coverage data. - # Cleanup lcov - set(LCOV_CLEAN_CMD - ${LCOV_PATH} ${Coverage_LCOV_ARGS} --gcov-tool ${GCOV_PATH} -directory . - -b ${BASEDIR} --zerocounters - ) - # Create baseline to make sure untouched files show up in the report - set(LCOV_BASELINE_CMD - ${LCOV_PATH} ${Coverage_LCOV_ARGS} --gcov-tool ${GCOV_PATH} -c -i -d . -b - ${BASEDIR} -o ${Coverage_NAME}.base - ) - # Run tests - set(LCOV_EXEC_TESTS_CMD - ${Coverage_EXECUTABLE} ${Coverage_EXECUTABLE_ARGS} - ) - # Capturing lcov counters and generating report - set(LCOV_CAPTURE_CMD - ${LCOV_PATH} ${Coverage_LCOV_ARGS} --gcov-tool ${GCOV_PATH} --directory . -b - ${BASEDIR} --capture --output-file ${Coverage_NAME}.capture - ) - # add baseline counters - set(LCOV_BASELINE_COUNT_CMD - ${LCOV_PATH} ${Coverage_LCOV_ARGS} --gcov-tool ${GCOV_PATH} -a ${Coverage_NAME}.base - -a ${Coverage_NAME}.capture --output-file ${Coverage_NAME}.total - ) - # filter collected data to final coverage report - set(LCOV_FILTER_CMD - ${LCOV_PATH} ${Coverage_LCOV_ARGS} --gcov-tool ${GCOV_PATH} --remove - ${Coverage_NAME}.total ${LCOV_EXCLUDES} --output-file ${Coverage_NAME}.info - ) - # Generate HTML output - set(LCOV_GEN_HTML_CMD - ${GENHTML_PATH} ${GENHTML_EXTRA_ARGS} ${Coverage_GENHTML_ARGS} -o - ${Coverage_NAME} ${Coverage_NAME}.info - ) - - - if(CODE_COVERAGE_VERBOSE) - message(STATUS "Executed command report") - message(STATUS "Command to clean up lcov: ") - string(REPLACE ";" " " LCOV_CLEAN_CMD_SPACED "${LCOV_CLEAN_CMD}") - message(STATUS "${LCOV_CLEAN_CMD_SPACED}") - - message(STATUS "Command to create baseline: ") - string(REPLACE ";" " " LCOV_BASELINE_CMD_SPACED "${LCOV_BASELINE_CMD}") - message(STATUS "${LCOV_BASELINE_CMD_SPACED}") - - message(STATUS "Command to run the tests: ") - string(REPLACE ";" " " LCOV_EXEC_TESTS_CMD_SPACED "${LCOV_EXEC_TESTS_CMD}") - message(STATUS "${LCOV_EXEC_TESTS_CMD_SPACED}") - - message(STATUS "Command to capture counters and generate report: ") - string(REPLACE ";" " " LCOV_CAPTURE_CMD_SPACED "${LCOV_CAPTURE_CMD}") - message(STATUS "${LCOV_CAPTURE_CMD_SPACED}") - - message(STATUS "Command to add baseline counters: ") - string(REPLACE ";" " " LCOV_BASELINE_COUNT_CMD_SPACED "${LCOV_BASELINE_COUNT_CMD}") - message(STATUS "${LCOV_BASELINE_COUNT_CMD_SPACED}") - - message(STATUS "Command to filter collected data: ") - string(REPLACE ";" " " LCOV_FILTER_CMD_SPACED "${LCOV_FILTER_CMD}") - message(STATUS "${LCOV_FILTER_CMD_SPACED}") - - message(STATUS "Command to generate lcov HTML output: ") - string(REPLACE ";" " " LCOV_GEN_HTML_CMD_SPACED "${LCOV_GEN_HTML_CMD}") - message(STATUS "${LCOV_GEN_HTML_CMD_SPACED}") + set(options NO_DEMANGLE) + set(oneValueArgs BASE_DIRECTORY NAME) + set(multiValueArgs EXCLUDE EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES LCOV_ARGS + GENHTML_ARGS) + cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" + "${multiValueArgs}" ${ARGN}) + + if(NOT LCOV_PATH) + message(FATAL_ERROR "lcov not found! Aborting...") + endif() # NOT LCOV_PATH + + if(NOT GENHTML_PATH) + message(FATAL_ERROR "genhtml not found! Aborting...") + endif() # NOT GENHTML_PATH + + # Set base directory (as absolute path), or default to PROJECT_SOURCE_DIR + if(DEFINED Coverage_BASE_DIRECTORY) + get_filename_component(BASEDIR ${Coverage_BASE_DIRECTORY} ABSOLUTE) + else() + set(BASEDIR ${PROJECT_SOURCE_DIR}) + endif() + + # Collect excludes (CMake 3.4+: Also compute absolute paths) + set(LCOV_EXCLUDES "") + foreach(EXCLUDE ${Coverage_EXCLUDE} ${COVERAGE_EXCLUDES} + ${COVERAGE_LCOV_EXCLUDES}) + if(CMAKE_VERSION VERSION_GREATER 3.4) + get_filename_component(EXCLUDE ${EXCLUDE} ABSOLUTE BASE_DIR ${BASEDIR}) endif() - - # Setup target - add_custom_target(${Coverage_NAME} - COMMAND ${LCOV_CLEAN_CMD} - COMMAND ${LCOV_BASELINE_CMD} - COMMAND ${LCOV_EXEC_TESTS_CMD} - COMMAND ${LCOV_CAPTURE_CMD} - COMMAND ${LCOV_BASELINE_COUNT_CMD} - COMMAND ${LCOV_FILTER_CMD} - COMMAND ${LCOV_GEN_HTML_CMD} - - # Set output files as GENERATED (will be removed on 'make clean') - BYPRODUCTS - ${Coverage_NAME}.base - ${Coverage_NAME}.capture - ${Coverage_NAME}.total - ${Coverage_NAME}.info - ${Coverage_NAME}/index.html - WORKING_DIRECTORY ${PROJECT_BINARY_DIR} - DEPENDS ${Coverage_DEPENDENCIES} - VERBATIM # Protect arguments to commands - COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report." - ) - - # Show where to find the lcov info report - add_custom_command(TARGET ${Coverage_NAME} POST_BUILD - COMMAND ; - COMMENT "Lcov code coverage info report saved in ${Coverage_NAME}.info." - ) - - # Show info where to find the report - add_custom_command(TARGET ${Coverage_NAME} POST_BUILD - COMMAND ; - COMMENT "Open ./${Coverage_NAME}/index.html in your browser to view the coverage report." - ) + list(APPEND LCOV_EXCLUDES "${EXCLUDE}") + endforeach() + list(REMOVE_DUPLICATES LCOV_EXCLUDES) + + # Conditional arguments + if(CPPFILT_PATH AND NOT ${Coverage_NO_DEMANGLE}) + set(GENHTML_EXTRA_ARGS "--demangle-cpp") + endif() + + # Setting up commands which will be run to generate coverage data. Cleanup + # lcov + set(LCOV_CLEAN_CMD + ${LCOV_PATH} + ${Coverage_LCOV_ARGS} + --gcov-tool + ${GCOV_PATH} + -directory + . + -b + ${BASEDIR} + --zerocounters) + # Create baseline to make sure untouched files show up in the report + set(LCOV_BASELINE_CMD + ${LCOV_PATH} + ${Coverage_LCOV_ARGS} + --gcov-tool + ${GCOV_PATH} + -c + -i + -d + . + -b + ${BASEDIR} + -o + ${Coverage_NAME}.base) + # Run tests + set(LCOV_EXEC_TESTS_CMD ${Coverage_EXECUTABLE} ${Coverage_EXECUTABLE_ARGS}) + # Capturing lcov counters and generating report + set(LCOV_CAPTURE_CMD + ${LCOV_PATH} + ${Coverage_LCOV_ARGS} + --gcov-tool + ${GCOV_PATH} + --directory + . + -b + ${BASEDIR} + --capture + --output-file + ${Coverage_NAME}.capture) + # add baseline counters + set(LCOV_BASELINE_COUNT_CMD + ${LCOV_PATH} + ${Coverage_LCOV_ARGS} + --gcov-tool + ${GCOV_PATH} + -a + ${Coverage_NAME}.base + -a + ${Coverage_NAME}.capture + --output-file + ${Coverage_NAME}.total) + # filter collected data to final coverage report + set(LCOV_FILTER_CMD + ${LCOV_PATH} + ${Coverage_LCOV_ARGS} + --gcov-tool + ${GCOV_PATH} + --remove + ${Coverage_NAME}.total + ${LCOV_EXCLUDES} + --output-file + ${Coverage_NAME}.info) + # Generate HTML output + set(LCOV_GEN_HTML_CMD + ${GENHTML_PATH} ${GENHTML_EXTRA_ARGS} ${Coverage_GENHTML_ARGS} -o + ${Coverage_NAME} ${Coverage_NAME}.info) + + if(CODE_COVERAGE_VERBOSE) + message(STATUS "Executed command report") + message(STATUS "Command to clean up lcov: ") + string(REPLACE ";" " " LCOV_CLEAN_CMD_SPACED "${LCOV_CLEAN_CMD}") + message(STATUS "${LCOV_CLEAN_CMD_SPACED}") + + message(STATUS "Command to create baseline: ") + string(REPLACE ";" " " LCOV_BASELINE_CMD_SPACED "${LCOV_BASELINE_CMD}") + message(STATUS "${LCOV_BASELINE_CMD_SPACED}") + + message(STATUS "Command to run the tests: ") + string(REPLACE ";" " " LCOV_EXEC_TESTS_CMD_SPACED "${LCOV_EXEC_TESTS_CMD}") + message(STATUS "${LCOV_EXEC_TESTS_CMD_SPACED}") + + message(STATUS "Command to capture counters and generate report: ") + string(REPLACE ";" " " LCOV_CAPTURE_CMD_SPACED "${LCOV_CAPTURE_CMD}") + message(STATUS "${LCOV_CAPTURE_CMD_SPACED}") + + message(STATUS "Command to add baseline counters: ") + string(REPLACE ";" " " LCOV_BASELINE_COUNT_CMD_SPACED + "${LCOV_BASELINE_COUNT_CMD}") + message(STATUS "${LCOV_BASELINE_COUNT_CMD_SPACED}") + + message(STATUS "Command to filter collected data: ") + string(REPLACE ";" " " LCOV_FILTER_CMD_SPACED "${LCOV_FILTER_CMD}") + message(STATUS "${LCOV_FILTER_CMD_SPACED}") + + message(STATUS "Command to generate lcov HTML output: ") + string(REPLACE ";" " " LCOV_GEN_HTML_CMD_SPACED "${LCOV_GEN_HTML_CMD}") + message(STATUS "${LCOV_GEN_HTML_CMD_SPACED}") + endif() + + # Setup target + add_custom_target( + ${Coverage_NAME} + COMMAND ${LCOV_CLEAN_CMD} + COMMAND ${LCOV_BASELINE_CMD} + COMMAND ${LCOV_EXEC_TESTS_CMD} + COMMAND ${LCOV_CAPTURE_CMD} + COMMAND ${LCOV_BASELINE_COUNT_CMD} + COMMAND ${LCOV_FILTER_CMD} + COMMAND ${LCOV_GEN_HTML_CMD} + # Set output files as GENERATED (will be removed on 'make clean') + BYPRODUCTS ${Coverage_NAME}.base ${Coverage_NAME}.capture + ${Coverage_NAME}.total ${Coverage_NAME}.info + ${Coverage_NAME}/index.html + WORKING_DIRECTORY ${PROJECT_BINARY_DIR} + DEPENDS ${Coverage_DEPENDENCIES} + VERBATIM # Protect arguments to commands + COMMENT + "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report." + ) + + # Show where to find the lcov info report + add_custom_command( + TARGET ${Coverage_NAME} + POST_BUILD + COMMAND ; + COMMENT "Lcov code coverage info report saved in ${Coverage_NAME}.info.") + + # Show info where to find the report + add_custom_command( + TARGET ${Coverage_NAME} + POST_BUILD + COMMAND ; + COMMENT + "Open ./${Coverage_NAME}/index.html in your browser to view the coverage report." + ) endfunction() # setup_target_for_coverage_lcov -# Defines a target for running and collection code coverage information -# Builds dependencies, runs the given executable and outputs reports. -# NOTE! The executable should always have a ZERO as exit code otherwise -# the coverage generation will not complete. -# -# setup_target_for_coverage_gcovr_xml( -# NAME ctest_coverage # New target name -# EXECUTABLE ctest -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR -# DEPENDENCIES executable_target # Dependencies to build first -# BASE_DIRECTORY "../" # Base directory for report -# # (defaults to PROJECT_SOURCE_DIR) -# EXCLUDE "src/dir1/*" "src/dir2/*" # Patterns to exclude (can be relative -# # to BASE_DIRECTORY, with CMake 3.4+) -# ) -# The user can set the variable GCOVR_ADDITIONAL_ARGS to supply additional flags to the -# GCVOR command. +# Defines a target for running and collection code coverage information Builds +# dependencies, runs the given executable and outputs reports. NOTE! The +# executable should always have a ZERO as exit code otherwise the coverage +# generation will not complete. +# +# setup_target_for_coverage_gcovr_xml( NAME ctest_coverage # +# New target name EXECUTABLE ctest -j ${PROCESSOR_COUNT} # Executable in +# PROJECT_BINARY_DIR DEPENDENCIES executable_target # Dependencies to +# build first BASE_DIRECTORY "../" # Base directory for report +# # (defaults to PROJECT_SOURCE_DIR) EXCLUDE "src/dir1/*" "src/dir2/*" # +# Patterns to exclude (can be relative # to BASE_DIRECTORY, with CMake 3.4+) ) +# The user can set the variable GCOVR_ADDITIONAL_ARGS to supply additional flags +# to the GCVOR command. function(setup_target_for_coverage_gcovr_xml) - set(options NONE) - set(oneValueArgs BASE_DIRECTORY NAME) - set(multiValueArgs EXCLUDE EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES) - cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - - if(NOT GCOVR_PATH) - message(FATAL_ERROR "gcovr not found! Aborting...") - endif() # NOT GCOVR_PATH - - # Set base directory (as absolute path), or default to PROJECT_SOURCE_DIR - if(DEFINED Coverage_BASE_DIRECTORY) - get_filename_component(BASEDIR ${Coverage_BASE_DIRECTORY} ABSOLUTE) - else() - set(BASEDIR ${PROJECT_SOURCE_DIR}) + set(options NONE) + set(oneValueArgs BASE_DIRECTORY NAME) + set(multiValueArgs EXCLUDE EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES) + cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" + "${multiValueArgs}" ${ARGN}) + + if(NOT GCOVR_PATH) + message(FATAL_ERROR "gcovr not found! Aborting...") + endif() # NOT GCOVR_PATH + + # Set base directory (as absolute path), or default to PROJECT_SOURCE_DIR + if(DEFINED Coverage_BASE_DIRECTORY) + get_filename_component(BASEDIR ${Coverage_BASE_DIRECTORY} ABSOLUTE) + else() + set(BASEDIR ${PROJECT_SOURCE_DIR}) + endif() + + # Collect excludes (CMake 3.4+: Also compute absolute paths) + set(GCOVR_EXCLUDES "") + foreach(EXCLUDE ${Coverage_EXCLUDE} ${COVERAGE_EXCLUDES} + ${COVERAGE_GCOVR_EXCLUDES}) + if(CMAKE_VERSION VERSION_GREATER 3.4) + get_filename_component(EXCLUDE ${EXCLUDE} ABSOLUTE BASE_DIR ${BASEDIR}) endif() - - # Collect excludes (CMake 3.4+: Also compute absolute paths) - set(GCOVR_EXCLUDES "") - foreach(EXCLUDE ${Coverage_EXCLUDE} ${COVERAGE_EXCLUDES} ${COVERAGE_GCOVR_EXCLUDES}) - if(CMAKE_VERSION VERSION_GREATER 3.4) - get_filename_component(EXCLUDE ${EXCLUDE} ABSOLUTE BASE_DIR ${BASEDIR}) - endif() - list(APPEND GCOVR_EXCLUDES "${EXCLUDE}") - endforeach() - list(REMOVE_DUPLICATES GCOVR_EXCLUDES) - - # Combine excludes to several -e arguments - set(GCOVR_EXCLUDE_ARGS "") - foreach(EXCLUDE ${GCOVR_EXCLUDES}) - list(APPEND GCOVR_EXCLUDE_ARGS "-e") - list(APPEND GCOVR_EXCLUDE_ARGS "${EXCLUDE}") - endforeach() - - # Set up commands which will be run to generate coverage data - # Run tests - set(GCOVR_XML_EXEC_TESTS_CMD - ${Coverage_EXECUTABLE} ${Coverage_EXECUTABLE_ARGS} - ) - # Running gcovr - set(GCOVR_XML_CMD - ${GCOVR_PATH} --xml ${Coverage_NAME}.xml -r ${BASEDIR} ${GCOVR_ADDITIONAL_ARGS} - ${GCOVR_EXCLUDE_ARGS} --object-directory=${PROJECT_BINARY_DIR} - ) - - if(CODE_COVERAGE_VERBOSE) - message(STATUS "Executed command report") - - message(STATUS "Command to run tests: ") - string(REPLACE ";" " " GCOVR_XML_EXEC_TESTS_CMD_SPACED "${GCOVR_XML_EXEC_TESTS_CMD}") - message(STATUS "${GCOVR_XML_EXEC_TESTS_CMD_SPACED}") - - message(STATUS "Command to generate gcovr XML coverage data: ") - string(REPLACE ";" " " GCOVR_XML_CMD_SPACED "${GCOVR_XML_CMD}") - message(STATUS "${GCOVR_XML_CMD_SPACED}") - endif() - - add_custom_target(${Coverage_NAME} - COMMAND ${GCOVR_XML_EXEC_TESTS_CMD} - COMMAND ${GCOVR_XML_CMD} - - BYPRODUCTS ${Coverage_NAME}.xml - WORKING_DIRECTORY ${PROJECT_BINARY_DIR} - DEPENDS ${Coverage_DEPENDENCIES} - VERBATIM # Protect arguments to commands - COMMENT "Running gcovr to produce Cobertura code coverage report." - ) - - # Show info where to find the report - add_custom_command(TARGET ${Coverage_NAME} POST_BUILD - COMMAND ; - COMMENT "Cobertura code coverage report saved in ${Coverage_NAME}.xml." - ) + list(APPEND GCOVR_EXCLUDES "${EXCLUDE}") + endforeach() + list(REMOVE_DUPLICATES GCOVR_EXCLUDES) + + # Combine excludes to several -e arguments + set(GCOVR_EXCLUDE_ARGS "") + foreach(EXCLUDE ${GCOVR_EXCLUDES}) + list(APPEND GCOVR_EXCLUDE_ARGS "-e") + list(APPEND GCOVR_EXCLUDE_ARGS "${EXCLUDE}") + endforeach() + + # Set up commands which will be run to generate coverage data Run tests + set(GCOVR_XML_EXEC_TESTS_CMD ${Coverage_EXECUTABLE} + ${Coverage_EXECUTABLE_ARGS}) + # Running gcovr + set(GCOVR_XML_CMD + ${GCOVR_PATH} + --xml + ${Coverage_NAME}.xml + -r + ${BASEDIR} + ${GCOVR_ADDITIONAL_ARGS} + ${GCOVR_EXCLUDE_ARGS} + --object-directory=${PROJECT_BINARY_DIR}) + + if(CODE_COVERAGE_VERBOSE) + message(STATUS "Executed command report") + + message(STATUS "Command to run tests: ") + string(REPLACE ";" " " GCOVR_XML_EXEC_TESTS_CMD_SPACED + "${GCOVR_XML_EXEC_TESTS_CMD}") + message(STATUS "${GCOVR_XML_EXEC_TESTS_CMD_SPACED}") + + message(STATUS "Command to generate gcovr XML coverage data: ") + string(REPLACE ";" " " GCOVR_XML_CMD_SPACED "${GCOVR_XML_CMD}") + message(STATUS "${GCOVR_XML_CMD_SPACED}") + endif() + + add_custom_target( + ${Coverage_NAME} + COMMAND ${GCOVR_XML_EXEC_TESTS_CMD} + COMMAND ${GCOVR_XML_CMD} + BYPRODUCTS ${Coverage_NAME}.xml + WORKING_DIRECTORY ${PROJECT_BINARY_DIR} + DEPENDS ${Coverage_DEPENDENCIES} + VERBATIM # Protect arguments to commands + COMMENT "Running gcovr to produce Cobertura code coverage report.") + + # Show info where to find the report + add_custom_command( + TARGET ${Coverage_NAME} + POST_BUILD + COMMAND ; + COMMENT "Cobertura code coverage report saved in ${Coverage_NAME}.xml.") endfunction() # setup_target_for_coverage_gcovr_xml -# Defines a target for running and collection code coverage information -# Builds dependencies, runs the given executable and outputs reports. -# NOTE! The executable should always have a ZERO as exit code otherwise -# the coverage generation will not complete. -# -# setup_target_for_coverage_gcovr_html( -# NAME ctest_coverage # New target name -# EXECUTABLE ctest -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR -# DEPENDENCIES executable_target # Dependencies to build first -# BASE_DIRECTORY "../" # Base directory for report -# # (defaults to PROJECT_SOURCE_DIR) -# EXCLUDE "src/dir1/*" "src/dir2/*" # Patterns to exclude (can be relative -# # to BASE_DIRECTORY, with CMake 3.4+) -# ) -# The user can set the variable GCOVR_ADDITIONAL_ARGS to supply additional flags to the -# GCVOR command. +# Defines a target for running and collection code coverage information Builds +# dependencies, runs the given executable and outputs reports. NOTE! The +# executable should always have a ZERO as exit code otherwise the coverage +# generation will not complete. +# +# setup_target_for_coverage_gcovr_html( NAME ctest_coverage # +# New target name EXECUTABLE ctest -j ${PROCESSOR_COUNT} # Executable in +# PROJECT_BINARY_DIR DEPENDENCIES executable_target # Dependencies to +# build first BASE_DIRECTORY "../" # Base directory for report +# # (defaults to PROJECT_SOURCE_DIR) EXCLUDE "src/dir1/*" "src/dir2/*" # +# Patterns to exclude (can be relative # to BASE_DIRECTORY, with CMake 3.4+) ) +# The user can set the variable GCOVR_ADDITIONAL_ARGS to supply additional flags +# to the GCVOR command. function(setup_target_for_coverage_gcovr_html) - set(options NONE) - set(oneValueArgs BASE_DIRECTORY NAME) - set(multiValueArgs EXCLUDE EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES) - cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - - if(NOT GCOVR_PATH) - message(FATAL_ERROR "gcovr not found! Aborting...") - endif() # NOT GCOVR_PATH - - # Set base directory (as absolute path), or default to PROJECT_SOURCE_DIR - if(DEFINED Coverage_BASE_DIRECTORY) - get_filename_component(BASEDIR ${Coverage_BASE_DIRECTORY} ABSOLUTE) - else() - set(BASEDIR ${PROJECT_SOURCE_DIR}) + set(options NONE) + set(oneValueArgs BASE_DIRECTORY NAME) + set(multiValueArgs EXCLUDE EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES) + cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" + "${multiValueArgs}" ${ARGN}) + + if(NOT GCOVR_PATH) + message(FATAL_ERROR "gcovr not found! Aborting...") + endif() # NOT GCOVR_PATH + + # Set base directory (as absolute path), or default to PROJECT_SOURCE_DIR + if(DEFINED Coverage_BASE_DIRECTORY) + get_filename_component(BASEDIR ${Coverage_BASE_DIRECTORY} ABSOLUTE) + else() + set(BASEDIR ${PROJECT_SOURCE_DIR}) + endif() + + # Collect excludes (CMake 3.4+: Also compute absolute paths) + set(GCOVR_EXCLUDES "") + foreach(EXCLUDE ${Coverage_EXCLUDE} ${COVERAGE_EXCLUDES} + ${COVERAGE_GCOVR_EXCLUDES}) + if(CMAKE_VERSION VERSION_GREATER 3.4) + get_filename_component(EXCLUDE ${EXCLUDE} ABSOLUTE BASE_DIR ${BASEDIR}) endif() - - # Collect excludes (CMake 3.4+: Also compute absolute paths) - set(GCOVR_EXCLUDES "") - foreach(EXCLUDE ${Coverage_EXCLUDE} ${COVERAGE_EXCLUDES} ${COVERAGE_GCOVR_EXCLUDES}) - if(CMAKE_VERSION VERSION_GREATER 3.4) - get_filename_component(EXCLUDE ${EXCLUDE} ABSOLUTE BASE_DIR ${BASEDIR}) - endif() - list(APPEND GCOVR_EXCLUDES "${EXCLUDE}") - endforeach() - list(REMOVE_DUPLICATES GCOVR_EXCLUDES) - - # Combine excludes to several -e arguments - set(GCOVR_EXCLUDE_ARGS "") - foreach(EXCLUDE ${GCOVR_EXCLUDES}) - list(APPEND GCOVR_EXCLUDE_ARGS "-e") - list(APPEND GCOVR_EXCLUDE_ARGS "${EXCLUDE}") - endforeach() - - # Set up commands which will be run to generate coverage data - # Run tests - set(GCOVR_HTML_EXEC_TESTS_CMD - ${Coverage_EXECUTABLE} ${Coverage_EXECUTABLE_ARGS} - ) - # Create folder - set(GCOVR_HTML_FOLDER_CMD - ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/${Coverage_NAME} - ) - # Running gcovr - set(GCOVR_HTML_CMD - ${GCOVR_PATH} --html ${Coverage_NAME}/index.html --html-details -r ${BASEDIR} ${GCOVR_ADDITIONAL_ARGS} - ${GCOVR_EXCLUDE_ARGS} --object-directory=${PROJECT_BINARY_DIR} - ) - - if(CODE_COVERAGE_VERBOSE) - message(STATUS "Executed command report") - - message(STATUS "Command to run tests: ") - string(REPLACE ";" " " GCOVR_HTML_EXEC_TESTS_CMD_SPACED "${GCOVR_HTML_EXEC_TESTS_CMD}") - message(STATUS "${GCOVR_HTML_EXEC_TESTS_CMD_SPACED}") - - message(STATUS "Command to create a folder: ") - string(REPLACE ";" " " GCOVR_HTML_FOLDER_CMD_SPACED "${GCOVR_HTML_FOLDER_CMD}") - message(STATUS "${GCOVR_HTML_FOLDER_CMD_SPACED}") - - message(STATUS "Command to generate gcovr HTML coverage data: ") - string(REPLACE ";" " " GCOVR_HTML_CMD_SPACED "${GCOVR_HTML_CMD}") - message(STATUS "${GCOVR_HTML_CMD_SPACED}") - endif() - - add_custom_target(${Coverage_NAME} - COMMAND ${GCOVR_HTML_EXEC_TESTS_CMD} - COMMAND ${GCOVR_HTML_FOLDER_CMD} - COMMAND ${GCOVR_HTML_CMD} - - BYPRODUCTS ${PROJECT_BINARY_DIR}/${Coverage_NAME}/index.html # report directory - WORKING_DIRECTORY ${PROJECT_BINARY_DIR} - DEPENDS ${Coverage_DEPENDENCIES} - VERBATIM # Protect arguments to commands - COMMENT "Running gcovr to produce HTML code coverage report." - ) - - # Show info where to find the report - add_custom_command(TARGET ${Coverage_NAME} POST_BUILD - COMMAND ; - COMMENT "Open ./${Coverage_NAME}/index.html in your browser to view the coverage report." - ) + list(APPEND GCOVR_EXCLUDES "${EXCLUDE}") + endforeach() + list(REMOVE_DUPLICATES GCOVR_EXCLUDES) + + # Combine excludes to several -e arguments + set(GCOVR_EXCLUDE_ARGS "") + foreach(EXCLUDE ${GCOVR_EXCLUDES}) + list(APPEND GCOVR_EXCLUDE_ARGS "-e") + list(APPEND GCOVR_EXCLUDE_ARGS "${EXCLUDE}") + endforeach() + + # Set up commands which will be run to generate coverage data Run tests + set(GCOVR_HTML_EXEC_TESTS_CMD ${Coverage_EXECUTABLE} + ${Coverage_EXECUTABLE_ARGS}) + # Create folder + set(GCOVR_HTML_FOLDER_CMD ${CMAKE_COMMAND} -E make_directory + ${PROJECT_BINARY_DIR}/${Coverage_NAME}) + # Running gcovr + set(GCOVR_HTML_CMD + ${GCOVR_PATH} + --html + ${Coverage_NAME}/index.html + --html-details + -r + ${BASEDIR} + ${GCOVR_ADDITIONAL_ARGS} + ${GCOVR_EXCLUDE_ARGS} + --object-directory=${PROJECT_BINARY_DIR}) + + if(CODE_COVERAGE_VERBOSE) + message(STATUS "Executed command report") + + message(STATUS "Command to run tests: ") + string(REPLACE ";" " " GCOVR_HTML_EXEC_TESTS_CMD_SPACED + "${GCOVR_HTML_EXEC_TESTS_CMD}") + message(STATUS "${GCOVR_HTML_EXEC_TESTS_CMD_SPACED}") + + message(STATUS "Command to create a folder: ") + string(REPLACE ";" " " GCOVR_HTML_FOLDER_CMD_SPACED + "${GCOVR_HTML_FOLDER_CMD}") + message(STATUS "${GCOVR_HTML_FOLDER_CMD_SPACED}") + + message(STATUS "Command to generate gcovr HTML coverage data: ") + string(REPLACE ";" " " GCOVR_HTML_CMD_SPACED "${GCOVR_HTML_CMD}") + message(STATUS "${GCOVR_HTML_CMD_SPACED}") + endif() + + add_custom_target( + ${Coverage_NAME} + COMMAND ${GCOVR_HTML_EXEC_TESTS_CMD} + COMMAND ${GCOVR_HTML_FOLDER_CMD} + COMMAND ${GCOVR_HTML_CMD} + BYPRODUCTS ${PROJECT_BINARY_DIR}/${Coverage_NAME}/index.html # report + # directory + WORKING_DIRECTORY ${PROJECT_BINARY_DIR} + DEPENDS ${Coverage_DEPENDENCIES} + VERBATIM # Protect arguments to commands + COMMENT "Running gcovr to produce HTML code coverage report.") + + # Show info where to find the report + add_custom_command( + TARGET ${Coverage_NAME} + POST_BUILD + COMMAND ; + COMMENT + "Open ./${Coverage_NAME}/index.html in your browser to view the coverage report." + ) endfunction() # setup_target_for_coverage_gcovr_html -# Defines a target for running and collection code coverage information -# Builds dependencies, runs the given executable and outputs reports. -# NOTE! The executable should always have a ZERO as exit code otherwise -# the coverage generation will not complete. -# -# setup_target_for_coverage_fastcov( -# NAME testrunner_coverage # New target name -# EXECUTABLE testrunner -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR -# DEPENDENCIES testrunner # Dependencies to build first -# BASE_DIRECTORY "../" # Base directory for report -# # (defaults to PROJECT_SOURCE_DIR) -# EXCLUDE "src/dir1/" "src/dir2/" # Patterns to exclude. -# NO_DEMANGLE # Don't demangle C++ symbols -# # even if c++filt is found -# SKIP_HTML # Don't create html report -# POST_CMD perl -i -pe s!${PROJECT_SOURCE_DIR}/!!g ctest_coverage.json # E.g. for stripping source dir from file paths -# ) +# Defines a target for running and collection code coverage information Builds +# dependencies, runs the given executable and outputs reports. NOTE! The +# executable should always have a ZERO as exit code otherwise the coverage +# generation will not complete. +# +# setup_target_for_coverage_fastcov( NAME testrunner_coverage # New target name +# EXECUTABLE testrunner -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR +# DEPENDENCIES testrunner # Dependencies to build first +# BASE_DIRECTORY "../" # Base directory for report # +# (defaults to PROJECT_SOURCE_DIR) EXCLUDE "src/dir1/" "src/dir2/" # Patterns to +# exclude. NO_DEMANGLE # Don't demangle C++ +# symbols # even if c++filt is found SKIP_HTML # Don't create html report +# POST_CMD perl -i -pe s!${PROJECT_SOURCE_DIR}/!!g ctest_coverage.json # E.g. +# for stripping source dir from file paths ) function(setup_target_for_coverage_fastcov) - set(options NO_DEMANGLE SKIP_HTML) - set(oneValueArgs BASE_DIRECTORY NAME) - set(multiValueArgs EXCLUDE EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES FASTCOV_ARGS GENHTML_ARGS POST_CMD) - cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - - if(NOT FASTCOV_PATH) - message(FATAL_ERROR "fastcov not found! Aborting...") - endif() - - if(NOT Coverage_SKIP_HTML AND NOT GENHTML_PATH) - message(FATAL_ERROR "genhtml not found! Aborting...") - endif() - - # Set base directory (as absolute path), or default to PROJECT_SOURCE_DIR - if(Coverage_BASE_DIRECTORY) - get_filename_component(BASEDIR ${Coverage_BASE_DIRECTORY} ABSOLUTE) - else() - set(BASEDIR ${PROJECT_SOURCE_DIR}) - endif() - - # Collect excludes (Patterns, not paths, for fastcov) - set(FASTCOV_EXCLUDES "") - foreach(EXCLUDE ${Coverage_EXCLUDE} ${COVERAGE_EXCLUDES} ${COVERAGE_FASTCOV_EXCLUDES}) - list(APPEND FASTCOV_EXCLUDES "${EXCLUDE}") - endforeach() - list(REMOVE_DUPLICATES FASTCOV_EXCLUDES) - - # Conditional arguments - if(CPPFILT_PATH AND NOT ${Coverage_NO_DEMANGLE}) - set(GENHTML_EXTRA_ARGS "--demangle-cpp") - endif() - - # Set up commands which will be run to generate coverage data - set(FASTCOV_EXEC_TESTS_CMD ${Coverage_EXECUTABLE} ${Coverage_EXECUTABLE_ARGS}) - - set(FASTCOV_CAPTURE_CMD ${FASTCOV_PATH} ${Coverage_FASTCOV_ARGS} --gcov ${GCOV_PATH} - --search-directory ${BASEDIR} - --process-gcno - --output ${Coverage_NAME}.json - --exclude ${FASTCOV_EXCLUDES} - --exclude ${FASTCOV_EXCLUDES} - ) - - set(FASTCOV_CONVERT_CMD ${FASTCOV_PATH} - -C ${Coverage_NAME}.json --lcov --output ${Coverage_NAME}.info - ) + set(options NO_DEMANGLE SKIP_HTML) + set(oneValueArgs BASE_DIRECTORY NAME) + set(multiValueArgs + EXCLUDE + EXECUTABLE + EXECUTABLE_ARGS + DEPENDENCIES + FASTCOV_ARGS + GENHTML_ARGS + POST_CMD) + cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" + "${multiValueArgs}" ${ARGN}) + + if(NOT FASTCOV_PATH) + message(FATAL_ERROR "fastcov not found! Aborting...") + endif() + + if(NOT Coverage_SKIP_HTML AND NOT GENHTML_PATH) + message(FATAL_ERROR "genhtml not found! Aborting...") + endif() + + # Set base directory (as absolute path), or default to PROJECT_SOURCE_DIR + if(Coverage_BASE_DIRECTORY) + get_filename_component(BASEDIR ${Coverage_BASE_DIRECTORY} ABSOLUTE) + else() + set(BASEDIR ${PROJECT_SOURCE_DIR}) + endif() + + # Collect excludes (Patterns, not paths, for fastcov) + set(FASTCOV_EXCLUDES "") + foreach(EXCLUDE ${Coverage_EXCLUDE} ${COVERAGE_EXCLUDES} + ${COVERAGE_FASTCOV_EXCLUDES}) + list(APPEND FASTCOV_EXCLUDES "${EXCLUDE}") + endforeach() + list(REMOVE_DUPLICATES FASTCOV_EXCLUDES) + + # Conditional arguments + if(CPPFILT_PATH AND NOT ${Coverage_NO_DEMANGLE}) + set(GENHTML_EXTRA_ARGS "--demangle-cpp") + endif() + + # Set up commands which will be run to generate coverage data + set(FASTCOV_EXEC_TESTS_CMD ${Coverage_EXECUTABLE} ${Coverage_EXECUTABLE_ARGS}) + + set(FASTCOV_CAPTURE_CMD + ${FASTCOV_PATH} + ${Coverage_FASTCOV_ARGS} + --gcov + ${GCOV_PATH} + --search-directory + ${BASEDIR} + --process-gcno + --output + ${Coverage_NAME}.json + --exclude + ${FASTCOV_EXCLUDES} + --exclude + ${FASTCOV_EXCLUDES}) + + set(FASTCOV_CONVERT_CMD ${FASTCOV_PATH} -C ${Coverage_NAME}.json --lcov + --output ${Coverage_NAME}.info) + + if(Coverage_SKIP_HTML) + set(FASTCOV_HTML_CMD ";") + else() + set(FASTCOV_HTML_CMD + ${GENHTML_PATH} ${GENHTML_EXTRA_ARGS} ${Coverage_GENHTML_ARGS} -o + ${Coverage_NAME} ${Coverage_NAME}.info) + endif() + + set(FASTCOV_POST_CMD ";") + if(Coverage_POST_CMD) + set(FASTCOV_POST_CMD ${Coverage_POST_CMD}) + endif() + + if(CODE_COVERAGE_VERBOSE) + message( + STATUS "Code coverage commands for target ${Coverage_NAME} (fastcov):") + + message(" Running tests:") + string(REPLACE ";" " " FASTCOV_EXEC_TESTS_CMD_SPACED + "${FASTCOV_EXEC_TESTS_CMD}") + message(" ${FASTCOV_EXEC_TESTS_CMD_SPACED}") + + message(" Capturing fastcov counters and generating report:") + string(REPLACE ";" " " FASTCOV_CAPTURE_CMD_SPACED "${FASTCOV_CAPTURE_CMD}") + message(" ${FASTCOV_CAPTURE_CMD_SPACED}") + + message(" Converting fastcov .json to lcov .info:") + string(REPLACE ";" " " FASTCOV_CONVERT_CMD_SPACED "${FASTCOV_CONVERT_CMD}") + message(" ${FASTCOV_CONVERT_CMD_SPACED}") - if(Coverage_SKIP_HTML) - set(FASTCOV_HTML_CMD ";") - else() - set(FASTCOV_HTML_CMD ${GENHTML_PATH} ${GENHTML_EXTRA_ARGS} ${Coverage_GENHTML_ARGS} - -o ${Coverage_NAME} ${Coverage_NAME}.info - ) + if(NOT Coverage_SKIP_HTML) + message(" Generating HTML report: ") + string(REPLACE ";" " " FASTCOV_HTML_CMD_SPACED "${FASTCOV_HTML_CMD}") + message(" ${FASTCOV_HTML_CMD_SPACED}") endif() - - set(FASTCOV_POST_CMD ";") if(Coverage_POST_CMD) - set(FASTCOV_POST_CMD ${Coverage_POST_CMD}) - endif() - - if(CODE_COVERAGE_VERBOSE) - message(STATUS "Code coverage commands for target ${Coverage_NAME} (fastcov):") - - message(" Running tests:") - string(REPLACE ";" " " FASTCOV_EXEC_TESTS_CMD_SPACED "${FASTCOV_EXEC_TESTS_CMD}") - message(" ${FASTCOV_EXEC_TESTS_CMD_SPACED}") - - message(" Capturing fastcov counters and generating report:") - string(REPLACE ";" " " FASTCOV_CAPTURE_CMD_SPACED "${FASTCOV_CAPTURE_CMD}") - message(" ${FASTCOV_CAPTURE_CMD_SPACED}") - - message(" Converting fastcov .json to lcov .info:") - string(REPLACE ";" " " FASTCOV_CONVERT_CMD_SPACED "${FASTCOV_CONVERT_CMD}") - message(" ${FASTCOV_CONVERT_CMD_SPACED}") - - if(NOT Coverage_SKIP_HTML) - message(" Generating HTML report: ") - string(REPLACE ";" " " FASTCOV_HTML_CMD_SPACED "${FASTCOV_HTML_CMD}") - message(" ${FASTCOV_HTML_CMD_SPACED}") - endif() - if(Coverage_POST_CMD) - message(" Running post command: ") - string(REPLACE ";" " " FASTCOV_POST_CMD_SPACED "${FASTCOV_POST_CMD}") - message(" ${FASTCOV_POST_CMD_SPACED}") - endif() - endif() - - # Setup target - add_custom_target(${Coverage_NAME} - - # Cleanup fastcov - COMMAND ${FASTCOV_PATH} ${Coverage_FASTCOV_ARGS} --gcov ${GCOV_PATH} - --search-directory ${BASEDIR} - --zerocounters - - COMMAND ${FASTCOV_EXEC_TESTS_CMD} - COMMAND ${FASTCOV_CAPTURE_CMD} - COMMAND ${FASTCOV_CONVERT_CMD} - COMMAND ${FASTCOV_HTML_CMD} - COMMAND ${FASTCOV_POST_CMD} - - # Set output files as GENERATED (will be removed on 'make clean') - BYPRODUCTS - ${Coverage_NAME}.info - ${Coverage_NAME}.json - ${Coverage_NAME}/index.html # report directory - - WORKING_DIRECTORY ${PROJECT_BINARY_DIR} - DEPENDS ${Coverage_DEPENDENCIES} - VERBATIM # Protect arguments to commands - COMMENT "Resetting code coverage counters to zero. Processing code coverage counters and generating report." - ) - - set(INFO_MSG "fastcov code coverage info report saved in ${Coverage_NAME}.info and ${Coverage_NAME}.json.") - if(NOT Coverage_SKIP_HTML) - string(APPEND INFO_MSG " Open ${PROJECT_BINARY_DIR}/${Coverage_NAME}/index.html in your browser to view the coverage report.") + message(" Running post command: ") + string(REPLACE ";" " " FASTCOV_POST_CMD_SPACED "${FASTCOV_POST_CMD}") + message(" ${FASTCOV_POST_CMD_SPACED}") endif() - # Show where to find the fastcov info report - add_custom_command(TARGET ${Coverage_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E echo ${INFO_MSG} + endif() + + # Setup target + add_custom_target( + ${Coverage_NAME} + # Cleanup fastcov + COMMAND ${FASTCOV_PATH} ${Coverage_FASTCOV_ARGS} --gcov ${GCOV_PATH} + --search-directory ${BASEDIR} --zerocounters + COMMAND ${FASTCOV_EXEC_TESTS_CMD} + COMMAND ${FASTCOV_CAPTURE_CMD} + COMMAND ${FASTCOV_CONVERT_CMD} + COMMAND ${FASTCOV_HTML_CMD} + COMMAND ${FASTCOV_POST_CMD} + # Set output files as GENERATED (will be removed on 'make clean') + BYPRODUCTS ${Coverage_NAME}.info ${Coverage_NAME}.json + ${Coverage_NAME}/index.html # report directory + WORKING_DIRECTORY ${PROJECT_BINARY_DIR} + DEPENDS ${Coverage_DEPENDENCIES} + VERBATIM # Protect arguments to commands + COMMENT + "Resetting code coverage counters to zero. Processing code coverage counters and generating report." + ) + + set(INFO_MSG + "fastcov code coverage info report saved in ${Coverage_NAME}.info and ${Coverage_NAME}.json." + ) + if(NOT Coverage_SKIP_HTML) + string( + APPEND + INFO_MSG + " Open ${PROJECT_BINARY_DIR}/${Coverage_NAME}/index.html in your browser to view the coverage report." ) + endif() + # Show where to find the fastcov info report + add_custom_command( + TARGET ${Coverage_NAME} + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E echo ${INFO_MSG}) endfunction() # setup_target_for_coverage_fastcov function(append_coverage_compiler_flags) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE) - set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE) - message(STATUS "Appending code coverage compiler flags: ${COVERAGE_COMPILER_FLAGS}") + set(CMAKE_C_FLAGS + "${CMAKE_C_FLAGS} ${COVERAGE_COMPILER_FLAGS}" + PARENT_SCOPE) + set(CMAKE_CXX_FLAGS + "${CMAKE_CXX_FLAGS} ${COVERAGE_COMPILER_FLAGS}" + PARENT_SCOPE) + set(CMAKE_Fortran_FLAGS + "${CMAKE_Fortran_FLAGS} ${COVERAGE_COMPILER_FLAGS}" + PARENT_SCOPE) + message( + STATUS "Appending code coverage compiler flags: ${COVERAGE_COMPILER_FLAGS}") endfunction() # append_coverage_compiler_flags # Setup coverage for specific library function(append_coverage_compiler_flags_to_target name) - target_compile_options(${name} - PRIVATE ${COVERAGE_COMPILER_FLAGS}) + target_compile_options(${name} PRIVATE ${COVERAGE_COMPILER_FLAGS}) endfunction() diff --git a/tools/cmake/CompilerOptions.cmake b/tools/cmake/CompilerOptions.cmake index a19c700f3..bab02b953 100644 --- a/tools/cmake/CompilerOptions.cmake +++ b/tools/cmake/CompilerOptions.cmake @@ -1,110 +1,107 @@ -# SPDX-FileCopyrightText: 2021 Philipp Basler, Margarete Mühlleitner and Jonas Müller +# SPDX-FileCopyrightText: 2021 Philipp Basler, Margarete Mühlleitner and Jonas +# Müller # # SPDX-License-Identifier: GPL-3.0-or-later add_compile_options( - $<$:-DCOMPILEDEBUG=true> - $<$,$,$>:-pedantic> - $<$,$,$>:-Wall> - $<$,$,$>:-Wextra> - $<$,$,$>:-Wshadow> - $<$,$,$,$>>:-Wmissing-declarations> - $<$,$,$,$>>:-Wmissing-include-dirs> - $<$,$,$,$>>:-O3> - ) - - + $<$:-DCOMPILEDEBUG=true> + $<$,$,$>:-pedantic> + $<$,$,$>:-Wall> + $<$,$,$>:-Wextra> + $<$,$,$>:-Wshadow> + $<$,$,$,$>>:-Wmissing-declarations> + $<$,$,$,$>>:-Wmissing-include-dirs> + $<$,$,$,$>>:-O3> +) if(BSMPT_USE_VECTORIZATION) - include(CheckCXXCompilerFlag) + include(CheckCXXCompilerFlag) - check_cxx_compiler_flag("-march=native" _march_native_works) - check_cxx_compiler_flag("-xHost" _xhost_works) + check_cxx_compiler_flag("-march=native" _march_native_works) + check_cxx_compiler_flag("-xHost" _xhost_works) - if(_march_native_works) - message(STATUS "Using processor's vector instructions (-march=native compiler flag set)") - add_compile_options(-march=native) - elseif(_xhost_works) - message(STATUS "Using processor's vector instructions (-xHost compiler flag set)") - add_compile_options(-xHost) - else() - message(STATUS "No suitable compiler flag found for vectorization") - endif() + if(_march_native_works) + message( + STATUS + "Using processor's vector instructions (-march=native compiler flag set)" + ) + add_compile_options(-march=native) + elseif(_xhost_works) + message( + STATUS "Using processor's vector instructions (-xHost compiler flag set)") + add_compile_options(-xHost) + else() + message(STATUS "No suitable compiler flag found for vectorization") + endif() endif(BSMPT_USE_VECTORIZATION) - add_compile_options( - $<$:/permissive-> - $<$,$>:/bigobj> - $<$:/w44101> - $<$,$>:/Ox> - ) +add_compile_options( + $<$:/permissive-> + $<$,$>:/bigobj> + $<$:/w44101> + $<$,$>:/Ox>) - list(APPEND MSVC_DISABLED_WARNINGS_LIST - "C4061" # enumerator 'identifier' in switch of enum 'enumeration' is not - # explicitly handled by a case label - # Disable this because it flags even when there is a default. - "C4068" - "C4100" # 'exarg' : unreferenced formal parameter - "C4127" # conditional expression is constant - "C4200" # nonstandard extension used : zero-sized array in - # struct/union. - "C4204" # nonstandard extension used: non-constant aggregate initializer - "C4221" # nonstandard extension used : 'identifier' : cannot be - # initialized using address of automatic variable - "C4242" # 'function' : conversion from 'int' to 'uint8_t', - # possible loss of data - "C4244" # 'function' : conversion from 'int' to 'uint8_t', - # possible loss of data - "C4245" # 'initializing' : conversion from 'long' to - # 'unsigned long', signed/unsigned mismatch - "C4267" # conversion from 'size_t' to 'int', possible loss of data - "C4355" - "C4371" # layout of class may have changed from a previous version of the - # compiler due to better packing of member '...' - "C4388" # signed/unsigned mismatch - "C4296" # '>=' : expression is always true - "C4350" # behavior change: 'std::_Wrap_alloc...' - "C4365" # '=' : conversion from 'size_t' to 'int', - # signed/unsigned mismatch - "C4389" # '!=' : signed/unsigned mismatch - "C4464" # relative include path contains '..' - "C4510" # 'argument' : default constructor could not be generated - "C4571" - "C4512" # 'argument' : assignment operator could not be generated - "C4514" # 'function': unreferenced inline function has been removed - "C4548" # expression before comma has no effect; expected expression with - # side-effect" caused by FD_* macros. - "C4610" # struct 'argument' can never be instantiated - user defined - # constructor required. - "C4619" - "C4623" # default constructor was implicitly defined as deleted - "C4625" # copy constructor could not be generated because a base class - # copy constructor is inaccessible or deleted - "C4626" # assignment operator could not be generated because a base class - # assignment operator is inaccessible or deleted - "C4643" - "C4668" # 'symbol' is not defined as a preprocessor macro, replacing with - # '0' for 'directives' - # Disable this because GTest uses it everywhere. - "C4706" # assignment within conditional expression - "C4710" # 'function': function not inlined - "C4711" # function 'function' selected for inline expansion - "C4800" # 'int' : forcing value to bool 'true' or 'false' - # (performance warning) - "C4820" # 'bytes' bytes padding added after construct 'member_name' - "C4868" - "C4996" - "C5026" # move constructor was implicitly defined as deleted - "C5027" # move assignment operator was implicitly defined as deleted - "C5031" - "C5039" - "C5045" - ) +list( + APPEND + MSVC_DISABLED_WARNINGS_LIST + "C4061" # enumerator 'identifier' in switch of enum 'enumeration' is not + # explicitly handled by a case label Disable this because it flags + # even when there is a default. + "C4068" + "C4100" # 'exarg' : unreferenced formal parameter + "C4127" # conditional expression is constant + "C4200" # nonstandard extension used : zero-sized array in struct/union. + "C4204" # nonstandard extension used: non-constant aggregate initializer + "C4221" # nonstandard extension used : 'identifier' : cannot be initialized + # using address of automatic variable + "C4242" # 'function' : conversion from 'int' to 'uint8_t', possible loss of + # data + "C4244" # 'function' : conversion from 'int' to 'uint8_t', possible loss of + # data + "C4245" # 'initializing' : conversion from 'long' to 'unsigned long', + # signed/unsigned mismatch + "C4267" # conversion from 'size_t' to 'int', possible loss of data + "C4355" + "C4371" # layout of class may have changed from a previous version of the + # compiler due to better packing of member '...' + "C4388" # signed/unsigned mismatch + "C4296" # '>=' : expression is always true + "C4350" # behavior change: 'std::_Wrap_alloc...' + "C4365" # '=' : conversion from 'size_t' to 'int', signed/unsigned mismatch + "C4389" # '!=' : signed/unsigned mismatch + "C4464" # relative include path contains '..' + "C4510" # 'argument' : default constructor could not be generated + "C4571" + "C4512" # 'argument' : assignment operator could not be generated + "C4514" # 'function': unreferenced inline function has been removed + "C4548" # expression before comma has no effect; expected expression with + # side-effect" caused by FD_* macros. + "C4610" # struct 'argument' can never be instantiated - user defined + # constructor required. + "C4619" + "C4623" # default constructor was implicitly defined as deleted + "C4625" # copy constructor could not be generated because a base class copy + # constructor is inaccessible or deleted + "C4626" # assignment operator could not be generated because a base class + # assignment operator is inaccessible or deleted + "C4643" + "C4668" # 'symbol' is not defined as a preprocessor macro, replacing with '0' + # for 'directives' Disable this because GTest uses it everywhere. + "C4706" # assignment within conditional expression + "C4710" # 'function': function not inlined + "C4711" # function 'function' selected for inline expansion + "C4800" # 'int' : forcing value to bool 'true' or 'false' (performance + # warning) + "C4820" # 'bytes' bytes padding added after construct 'member_name' + "C4868" + "C4996" + "C5026" # move constructor was implicitly defined as deleted + "C5027" # move assignment operator was implicitly defined as deleted + "C5031" + "C5039" + "C5045") - foreach(warning IN LISTS MSVC_DISABLED_WARNINGS_LIST) - string(REPLACE "C" "" warning_stripped - ${warning}) - add_compile_options( - $<$:-wd${warning_stripped}> - ) - endforeach() +foreach(warning IN LISTS MSVC_DISABLED_WARNINGS_LIST) + string(REPLACE "C" "" warning_stripped ${warning}) + add_compile_options($<$:-wd${warning_stripped}>) +endforeach() diff --git a/tools/cmake/ConanDependencies.cmake b/tools/cmake/ConanDependencies.cmake new file mode 100644 index 000000000..9884d4e9d --- /dev/null +++ b/tools/cmake/ConanDependencies.cmake @@ -0,0 +1,23 @@ +list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR}) +include(conan) +set(ConanPkgList eigen/3.4.0 gsl/2.7 boost/1.78.0 nlohmann_json/3.10.5) + +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + set(ConanPkgList ${ConanPkgList} benchmark/1.6.1) +endif() +if(UseNLopt) + set(ConanPkgList ${ConanPkgList} nlopt/2.7.1) +endif(UseNLopt) +conan_cmake_configure(REQUIRES ${ConanPkgList} GENERATORS cmake_find_package) + +conan_cmake_autodetect(settings) + +conan_cmake_install( + PATH_OR_REFERENCE + . + BUILD + missing + REMOTE + conancenter + SETTINGS + ${settings}) diff --git a/tools/cmake/LTO.cmake b/tools/cmake/LTO.cmake index ca68e047e..32878dc3f 100644 --- a/tools/cmake/LTO.cmake +++ b/tools/cmake/LTO.cmake @@ -2,252 +2,292 @@ # # Variable : ENABLE_LTO | Enable or disable LTO support for this build # -# find_lto(lang) -# - lang is C or CXX (the language to test LTO for) -# - call it after project() so that the compiler is already detected +# find_lto(lang) - lang is C or CXX (the language to test LTO for) - call it +# after project() so that the compiler is already detected # -# This will check for LTO support and create a target_enable_lto(target [debug,optimized,general]) macro. -# The 2nd parameter has the same meaning as in target_link_libraries, and is used to enable LTO only for those build configurations -# 'debug' is by default the Debug configuration, and 'optimized' all the other configurations +# This will check for LTO support and create a target_enable_lto(target +# [debug,optimized,general]) macro. The 2nd parameter has the same meaning as in +# target_link_libraries, and is used to enable LTO only for those build +# configurations 'debug' is by default the Debug configuration, and 'optimized' +# all the other configurations # # if ENABLE_LTO is set to false, an empty macro will be generated # # Then to enable LTO for your target use # -# target_enable_lto(mytarget general) +# target_enable_lto(mytarget general) # -# It is however recommended to use it only for non debug builds the following way : +# It is however recommended to use it only for non debug builds the following +# way : # -# target_enable_lto(mytarget optimized) +# target_enable_lto(mytarget optimized) # -# Note : For CMake versions < 3.9, target_link_library is used in it's non plain version. -# You will need to specify PUBLIC/PRIVATE/INTERFACE to all your other target_link_library calls for the target +# Note : For CMake versions < 3.9, target_link_library is used in it's non plain +# version. You will need to specify PUBLIC/PRIVATE/INTERFACE to all your other +# target_link_library calls for the target # -# WARNING for cmake versions older than 3.9 : -# This module will override CMAKE_AR CMAKE_RANLIB and CMAKE_NM by the gcc versions if found when building with gcc - +# WARNING for cmake versions older than 3.9 : This module will override CMAKE_AR +# CMAKE_RANLIB and CMAKE_NM by the gcc versions if found when building with gcc # License: # # Copyright (C) 2016 Lectem # -# Permission is hereby granted, free of charge, to any person -# obtaining a copy of this software and associated documentation files -# (the 'Software') deal in the Software without restriction, -# including without limitation the rights to use, copy, modify, merge, -# publish, distribute, sublicense, and/or sell copies of the Software, -# and to permit persons to whom the Software is furnished to do so, -# subject to the following conditions: +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the 'Software') deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +# of the Software, and to permit persons to whom the Software is furnished to do +# so, subject to the following conditions: # -# The above copyright notice and this permission notice shall be -# included in all copies or substantial portions of the Software. +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. # -# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. - cmake_minimum_required(VERSION 3.1) option(ENABLE_LTO "enable link time optimization" ON) macro(find_lto lang) - if(ENABLE_LTO AND NOT LTO_${lang}_CHECKED) + if(ENABLE_LTO AND NOT LTO_${lang}_CHECKED) - #LTO support was added for clang/gcc in 3.9 - if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_LESS 3.9) - cmake_policy(SET CMP0054 NEW) + # LTO support was added for clang/gcc in 3.9 + if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_LESS 3.9) + cmake_policy(SET CMP0054 NEW) message(STATUS "Checking for LTO Compatibility") - # Since GCC 4.9 we need to use gcc-ar / gcc-ranlib / gcc-nm - if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") - if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_GCC_AR OR NOT CMAKE_GCC_RANLIB OR NOT CMAKE_GCC_NM) - find_program(CMAKE_GCC_AR NAMES - "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar" - "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar-${_version}" - DOC "gcc provided wrapper for ar which adds the --plugin option" - ) - find_program(CMAKE_GCC_RANLIB NAMES - "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib" - "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib-${_version}" - DOC "gcc provided wrapper for ranlib which adds the --plugin option" - ) - # Not needed, but at least stay coherent - find_program(CMAKE_GCC_NM NAMES - "${_CMAKE_TOOLCHAIN_PREFIX}gcc-nm" - "${_CMAKE_TOOLCHAIN_PREFIX}gcc-nm-${_version}" - DOC "gcc provided wrapper for nm which adds the --plugin option" - ) - mark_as_advanced(CMAKE_GCC_AR CMAKE_GCC_RANLIB CMAKE_GCC_NM) - set(CMAKE_LTO_AR ${CMAKE_GCC_AR}) - set(CMAKE_LTO_RANLIB ${CMAKE_GCC_RANLIB}) - set(CMAKE_LTO_NM ${CMAKE_GCC_NM}) - endif() - if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") - set(CMAKE_LTO_AR ${CMAKE_AR}) - set(CMAKE_LTO_RANLIB ${CMAKE_RANLIB}) - set(CMAKE_LTO_NM ${CMAKE_NM}) - endif() - - if(CMAKE_LTO_AR AND CMAKE_LTO_RANLIB) - set(__lto_flags -flto) - - if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 4.7) - list(APPEND __lto_flags -fno-fat-lto-objects) - endif() - - if(NOT DEFINED CMAKE_${lang}_PASSED_LTO_TEST) - set(__output_dir "${CMAKE_PLATFORM_INFO_DIR}/LtoTest1${lang}") - file(MAKE_DIRECTORY "${__output_dir}") - set(__output_base "${__output_dir}/lto-test-${lang}") - - execute_process( - COMMAND ${CMAKE_COMMAND} -E echo "void foo() {}" - COMMAND ${CMAKE_${lang}_COMPILER} ${__lto_flags} -c -xc - - -o "${__output_base}.o" - RESULT_VARIABLE __result - ERROR_QUIET - OUTPUT_QUIET - ) - - if("${__result}" STREQUAL "0") - execute_process( - COMMAND ${CMAKE_LTO_AR} cr "${__output_base}.a" "${__output_base}.o" - RESULT_VARIABLE __result - ERROR_QUIET - OUTPUT_QUIET - ) - endif() - - if("${__result}" STREQUAL "0") - execute_process( - COMMAND ${CMAKE_LTO_RANLIB} "${__output_base}.a" - RESULT_VARIABLE __result - ERROR_QUIET - OUTPUT_QUIET - ) - endif() - - if("${__result}" STREQUAL "0") - execute_process( - COMMAND ${CMAKE_COMMAND} -E echo "void foo(); int main() {foo();}" - COMMAND ${CMAKE_${lang}_COMPILER} ${__lto_flags} -xc - - -x none "${__output_base}.a" -o "${__output_base}" - RESULT_VARIABLE __result - ERROR_QUIET - OUTPUT_QUIET - ) - endif() - - if("${__result}" STREQUAL "0") - set(__lto_found TRUE) - endif() - - set(CMAKE_${lang}_PASSED_LTO_TEST - ${__lto_found} CACHE INTERNAL - "If the compiler passed a simple LTO test compile") - endif() - if(CMAKE_${lang}_PASSED_LTO_TEST) - message(STATUS "Checking for LTO Compatibility - works") - set(LTO_${lang}_SUPPORT TRUE CACHE BOOL "Do we have LTO support ?") - set(LTO_COMPILE_FLAGS -flto CACHE STRING "Link Time Optimization compile flags") - set(LTO_LINK_FLAGS -flto CACHE STRING "Link Time Optimization link flags") - else() - message(STATUS "Checking for LTO Compatibility - not working") - endif() - - endif() - elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - message(STATUS "Checking for LTO Compatibility - works (assumed for clang)") - set(LTO_${lang}_SUPPORT TRUE CACHE BOOL "Do we have LTO support ?") - set(LTO_COMPILE_FLAGS -flto CACHE STRING "Link Time Optimization compile flags") - set(LTO_LINK_FLAGS -flto CACHE STRING "Link Time Optimization link flags") - elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - message(STATUS "Checking for LTO Compatibility - works") - set(LTO_${lang}_SUPPORT TRUE CACHE BOOL "Do we have LTO support ?") - set(LTO_COMPILE_FLAGS /GL CACHE STRING "Link Time Optimization compile flags") - set(LTO_LINK_FLAGS -LTCG:INCREMENTAL CACHE STRING "Link Time Optimization link flags") - else() - message(STATUS "Checking for LTO Compatibility - compiler not handled by module") - endif() - mark_as_advanced(LTO_${lang}_SUPPORT LTO_COMPILE_FLAGS LTO_LINK_FLAGS) + # Since GCC 4.9 we need to use gcc-ar / gcc-ranlib / gcc-nm + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES + "Clang") + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" + AND NOT CMAKE_GCC_AR + OR NOT CMAKE_GCC_RANLIB + OR NOT CMAKE_GCC_NM) + find_program( + CMAKE_GCC_AR + NAMES "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar" + "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar-${_version}" + DOC "gcc provided wrapper for ar which adds the --plugin option") + find_program( + CMAKE_GCC_RANLIB + NAMES "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib" + "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib-${_version}" + DOC "gcc provided wrapper for ranlib which adds the --plugin option" + ) + # Not needed, but at least stay coherent + find_program( + CMAKE_GCC_NM + NAMES "${_CMAKE_TOOLCHAIN_PREFIX}gcc-nm" + "${_CMAKE_TOOLCHAIN_PREFIX}gcc-nm-${_version}" + DOC "gcc provided wrapper for nm which adds the --plugin option") + mark_as_advanced(CMAKE_GCC_AR CMAKE_GCC_RANLIB CMAKE_GCC_NM) + set(CMAKE_LTO_AR ${CMAKE_GCC_AR}) + set(CMAKE_LTO_RANLIB ${CMAKE_GCC_RANLIB}) + set(CMAKE_LTO_NM ${CMAKE_GCC_NM}) + endif() + if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") + set(CMAKE_LTO_AR ${CMAKE_AR}) + set(CMAKE_LTO_RANLIB ${CMAKE_RANLIB}) + set(CMAKE_LTO_NM ${CMAKE_NM}) + endif() + if(CMAKE_LTO_AR AND CMAKE_LTO_RANLIB) + set(__lto_flags -flto) - set(LTO_${lang}_CHECKED TRUE CACHE INTERNAL "" ) + if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 4.7) + list(APPEND __lto_flags -fno-fat-lto-objects) + endif() + + if(NOT DEFINED CMAKE_${lang}_PASSED_LTO_TEST) + set(__output_dir "${CMAKE_PLATFORM_INFO_DIR}/LtoTest1${lang}") + file(MAKE_DIRECTORY "${__output_dir}") + set(__output_base "${__output_dir}/lto-test-${lang}") + + execute_process( + COMMAND ${CMAKE_COMMAND} -E echo "void foo() {}" + COMMAND ${CMAKE_${lang}_COMPILER} ${__lto_flags} -c -xc - -o + "${__output_base}.o" + RESULT_VARIABLE __result + ERROR_QUIET OUTPUT_QUIET) - if(CMAKE_GCC_AR AND CMAKE_GCC_RANLIB AND CMAKE_GCC_NM) - # THIS IS HACKY BUT THERE IS NO OTHER SOLUTION ATM - set(CMAKE_AR ${CMAKE_GCC_AR} CACHE FILEPATH "Forcing gcc-ar instead of ar" FORCE) - set(CMAKE_NM ${CMAKE_GCC_NM} CACHE FILEPATH "Forcing gcc-nm instead of nm" FORCE) - set(CMAKE_RANLIB ${CMAKE_GCC_RANLIB} CACHE FILEPATH "Forcing gcc-ranlib instead of ranlib" FORCE) + if("${__result}" STREQUAL "0") + execute_process( + COMMAND ${CMAKE_LTO_AR} cr "${__output_base}.a" + "${__output_base}.o" + RESULT_VARIABLE __result + ERROR_QUIET OUTPUT_QUIET) endif() - endif(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_LESS 3.9) - endif(ENABLE_LTO AND NOT LTO_${lang}_CHECKED) + if("${__result}" STREQUAL "0") + execute_process( + COMMAND ${CMAKE_LTO_RANLIB} "${__output_base}.a" + RESULT_VARIABLE __result + ERROR_QUIET OUTPUT_QUIET) + endif() - if(ENABLE_LTO) - #Special case for cmake older than 3.9, using a library for gcc/clang, but could setup the flags directly. - #Taking advantage of the [debug,optimized] parameter of target_link_libraries - if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_LESS 3.9) - if(LTO_${lang}_SUPPORT) - if(NOT TARGET __enable_lto_tgt) - add_library(__enable_lto_tgt INTERFACE) + if("${__result}" STREQUAL "0") + execute_process( + COMMAND ${CMAKE_COMMAND} -E echo + "void foo(); int main() {foo();}" + COMMAND ${CMAKE_${lang}_COMPILER} ${__lto_flags} -xc - -x none + "${__output_base}.a" -o "${__output_base}" + RESULT_VARIABLE __result + ERROR_QUIET OUTPUT_QUIET) endif() - target_compile_options(__enable_lto_tgt INTERFACE ${LTO_COMPILE_FLAGS}) - #this might not work for all platforms... in which case we'll have to set the link flags on the target directly - target_link_libraries(__enable_lto_tgt INTERFACE ${LTO_LINK_FLAGS} ) - macro(target_enable_lto _target _build_configuration) - if(${_build_configuration} STREQUAL "optimized" OR ${_build_configuration} STREQUAL "debug" ) - target_link_libraries(${_target} PRIVATE ${_build_configuration} __enable_lto_tgt) - else() - target_link_libraries(${_target} PRIVATE __enable_lto_tgt) - endif() - endmacro() - else() - #In old cmake versions, we can set INTERPROCEDURAL_OPTIMIZATION even if not supported by the compiler - #So if we didn't detect it, let cmake give it a try - set(__IPO_SUPPORTED TRUE) - endif() - else() - cmake_policy(SET CMP0069 NEW) - include(CheckIPOSupported) - # Optional IPO. Do not use IPO if it's not supported by compiler. - check_ipo_supported(RESULT __IPO_SUPPORTED OUTPUT output) - if(NOT __IPO_SUPPORTED) - message(STATUS "IPO is not supported or broken.") + + if("${__result}" STREQUAL "0") + set(__lto_found TRUE) + endif() + + set(CMAKE_${lang}_PASSED_LTO_TEST + ${__lto_found} + CACHE INTERNAL + "If the compiler passed a simple LTO test compile") + endif() + if(CMAKE_${lang}_PASSED_LTO_TEST) + message(STATUS "Checking for LTO Compatibility - works") + set(LTO_${lang}_SUPPORT + TRUE + CACHE BOOL "Do we have LTO support ?") + set(LTO_COMPILE_FLAGS + -flto + CACHE STRING "Link Time Optimization compile flags") + set(LTO_LINK_FLAGS + -flto + CACHE STRING "Link Time Optimization link flags") else() - message(STATUS "IPO is supported !") + message(STATUS "Checking for LTO Compatibility - not working") endif() + + endif() + elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + message( + STATUS "Checking for LTO Compatibility - works (assumed for clang)") + set(LTO_${lang}_SUPPORT + TRUE + CACHE BOOL "Do we have LTO support ?") + set(LTO_COMPILE_FLAGS + -flto + CACHE STRING "Link Time Optimization compile flags") + set(LTO_LINK_FLAGS + -flto + CACHE STRING "Link Time Optimization link flags") + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + message(STATUS "Checking for LTO Compatibility - works") + set(LTO_${lang}_SUPPORT + TRUE + CACHE BOOL "Do we have LTO support ?") + set(LTO_COMPILE_FLAGS + /GL + CACHE STRING "Link Time Optimization compile flags") + set(LTO_LINK_FLAGS + -LTCG:INCREMENTAL + CACHE STRING "Link Time Optimization link flags") + else() + message( + STATUS + "Checking for LTO Compatibility - compiler not handled by module") endif() - if(__IPO_SUPPORTED) + mark_as_advanced(LTO_${lang}_SUPPORT LTO_COMPILE_FLAGS LTO_LINK_FLAGS) + + set(LTO_${lang}_CHECKED + TRUE + CACHE INTERNAL "") + + if(CMAKE_GCC_AR + AND CMAKE_GCC_RANLIB + AND CMAKE_GCC_NM) + # THIS IS HACKY BUT THERE IS NO OTHER SOLUTION ATM + set(CMAKE_AR + ${CMAKE_GCC_AR} + CACHE FILEPATH "Forcing gcc-ar instead of ar" FORCE) + set(CMAKE_NM + ${CMAKE_GCC_NM} + CACHE FILEPATH "Forcing gcc-nm instead of nm" FORCE) + set(CMAKE_RANLIB + ${CMAKE_GCC_RANLIB} + CACHE FILEPATH "Forcing gcc-ranlib instead of ranlib" FORCE) + endif() + endif(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_LESS 3.9) + endif(ENABLE_LTO AND NOT LTO_${lang}_CHECKED) + + if(ENABLE_LTO) + # Special case for cmake older than 3.9, using a library for gcc/clang, but + # could setup the flags directly. Taking advantage of the [debug,optimized] + # parameter of target_link_libraries + if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_LESS 3.9) + if(LTO_${lang}_SUPPORT) + if(NOT TARGET __enable_lto_tgt) + add_library(__enable_lto_tgt INTERFACE) + endif() + target_compile_options(__enable_lto_tgt INTERFACE ${LTO_COMPILE_FLAGS}) + # this might not work for all platforms... in which case we'll have to + # set the link flags on the target directly + target_link_libraries(__enable_lto_tgt INTERFACE ${LTO_LINK_FLAGS}) macro(target_enable_lto _target _build_configuration) - if(NOT ${_build_configuration} STREQUAL "debug" ) - #enable for all configurations - set_target_properties(${_target} PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE) - endif() - if(${_build_configuration} STREQUAL "optimized" ) - #blacklist debug configurations - set(__enable_debug_lto FALSE) - else() - #enable only for debug configurations - set(__enable_debug_lto TRUE) - endif() - get_property(DEBUG_CONFIGURATIONS GLOBAL PROPERTY DEBUG_CONFIGURATIONS) - if(NOT DEBUG_CONFIGURATIONS) - set(DEBUG_CONFIGURATIONS DEBUG) # This is what is done by CMAKE internally... since DEBUG_CONFIGURATIONS is empty by default - endif() - foreach(config IN LISTS DEBUG_CONFIGURATIONS) - set_target_properties(${_target} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_${config} ${__enable_debug_lto}) - endforeach() + if(${_build_configuration} STREQUAL "optimized" + OR ${_build_configuration} STREQUAL "debug") + target_link_libraries(${_target} PRIVATE ${_build_configuration} + __enable_lto_tgt) + else() + target_link_libraries(${_target} PRIVATE __enable_lto_tgt) + endif() endmacro() + else() + # In old cmake versions, we can set INTERPROCEDURAL_OPTIMIZATION even if + # not supported by the compiler So if we didn't detect it, let cmake + # give it a try + set(__IPO_SUPPORTED TRUE) + endif() + else() + cmake_policy(SET CMP0069 NEW) + include(CheckIPOSupported) + # Optional IPO. Do not use IPO if it's not supported by compiler. + check_ipo_supported(RESULT __IPO_SUPPORTED OUTPUT output) + if(NOT __IPO_SUPPORTED) + message(STATUS "IPO is not supported or broken.") + else() + message(STATUS "IPO is supported !") endif() endif() - if(NOT COMMAND target_enable_lto) - macro(target_enable_lto _target _build_configuration) - endmacro() + if(__IPO_SUPPORTED) + macro(target_enable_lto _target _build_configuration) + if(NOT ${_build_configuration} STREQUAL "debug") + # enable for all configurations + set_target_properties(${_target} + PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE) + endif() + if(${_build_configuration} STREQUAL "optimized") + # blacklist debug configurations + set(__enable_debug_lto FALSE) + else() + # enable only for debug configurations + set(__enable_debug_lto TRUE) + endif() + get_property(DEBUG_CONFIGURATIONS GLOBAL PROPERTY DEBUG_CONFIGURATIONS) + if(NOT DEBUG_CONFIGURATIONS) + set(DEBUG_CONFIGURATIONS DEBUG) # This is what is done by CMAKE + # internally... since + # DEBUG_CONFIGURATIONS is empty by + # default + endif() + foreach(config IN LISTS DEBUG_CONFIGURATIONS) + set_target_properties( + ${_target} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_${config} + ${__enable_debug_lto}) + endforeach() + endmacro() endif() + endif() + if(NOT COMMAND target_enable_lto) + macro(target_enable_lto _target _build_configuration) + + endmacro() + endif() endmacro() diff --git a/tools/cmake/conan.cmake b/tools/cmake/conan.cmake index 208ce2485..a89899021 100644 --- a/tools/cmake/conan.cmake +++ b/tools/cmake/conan.cmake @@ -20,624 +20,812 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +# This file comes from: https://github.com/conan-io/cmake-conan. Please refer to +# this repository for issues and documentation. +# Its purpose is to wrap and launch Conan C/C++ Package Manager when cmake is +# called. It will take CMake current settings (os, compiler, compiler version, +# architecture) and translate them to conan settings for installing and +# retrieving dependencies. -# This file comes from: https://github.com/conan-io/cmake-conan. Please refer -# to this repository for issues and documentation. - -# Its purpose is to wrap and launch Conan C/C++ Package Manager when cmake is called. -# It will take CMake current settings (os, compiler, compiler version, architecture) -# and translate them to conan settings for installing and retrieving dependencies. - -# It is intended to facilitate developers building projects that have conan dependencies, -# but it is only necessary on the end-user side. It is not necessary to create conan -# packages, in fact it shouldn't be use for that. Check the project documentation. +# It is intended to facilitate developers building projects that have conan +# dependencies, but it is only necessary on the end-user side. It is not +# necessary to create conan packages, in fact it shouldn't be use for that. +# Check the project documentation. # version: 0.18.0-dev include(CMakeParseArguments) function(_get_msvc_ide_version result) - set(${result} "" PARENT_SCOPE) - if(NOT MSVC_VERSION VERSION_LESS 1400 AND MSVC_VERSION VERSION_LESS 1500) - set(${result} 8 PARENT_SCOPE) - elseif(NOT MSVC_VERSION VERSION_LESS 1500 AND MSVC_VERSION VERSION_LESS 1600) - set(${result} 9 PARENT_SCOPE) - elseif(NOT MSVC_VERSION VERSION_LESS 1600 AND MSVC_VERSION VERSION_LESS 1700) - set(${result} 10 PARENT_SCOPE) - elseif(NOT MSVC_VERSION VERSION_LESS 1700 AND MSVC_VERSION VERSION_LESS 1800) - set(${result} 11 PARENT_SCOPE) - elseif(NOT MSVC_VERSION VERSION_LESS 1800 AND MSVC_VERSION VERSION_LESS 1900) - set(${result} 12 PARENT_SCOPE) - elseif(NOT MSVC_VERSION VERSION_LESS 1900 AND MSVC_VERSION VERSION_LESS 1910) - set(${result} 14 PARENT_SCOPE) - elseif(NOT MSVC_VERSION VERSION_LESS 1910 AND MSVC_VERSION VERSION_LESS 1920) - set(${result} 15 PARENT_SCOPE) - elseif(NOT MSVC_VERSION VERSION_LESS 1920 AND MSVC_VERSION VERSION_LESS 1930) - set(${result} 16 PARENT_SCOPE) - elseif(NOT MSVC_VERSION VERSION_LESS 1930 AND MSVC_VERSION VERSION_LESS 1940) - set(${result} 17 PARENT_SCOPE) - else() - message(FATAL_ERROR "Conan: Unknown MSVC compiler version [${MSVC_VERSION}]") - endif() + set(${result} + "" + PARENT_SCOPE) + if(NOT MSVC_VERSION VERSION_LESS 1400 AND MSVC_VERSION VERSION_LESS 1500) + set(${result} + 8 + PARENT_SCOPE) + elseif(NOT MSVC_VERSION VERSION_LESS 1500 AND MSVC_VERSION VERSION_LESS 1600) + set(${result} + 9 + PARENT_SCOPE) + elseif(NOT MSVC_VERSION VERSION_LESS 1600 AND MSVC_VERSION VERSION_LESS 1700) + set(${result} + 10 + PARENT_SCOPE) + elseif(NOT MSVC_VERSION VERSION_LESS 1700 AND MSVC_VERSION VERSION_LESS 1800) + set(${result} + 11 + PARENT_SCOPE) + elseif(NOT MSVC_VERSION VERSION_LESS 1800 AND MSVC_VERSION VERSION_LESS 1900) + set(${result} + 12 + PARENT_SCOPE) + elseif(NOT MSVC_VERSION VERSION_LESS 1900 AND MSVC_VERSION VERSION_LESS 1910) + set(${result} + 14 + PARENT_SCOPE) + elseif(NOT MSVC_VERSION VERSION_LESS 1910 AND MSVC_VERSION VERSION_LESS 1920) + set(${result} + 15 + PARENT_SCOPE) + elseif(NOT MSVC_VERSION VERSION_LESS 1920 AND MSVC_VERSION VERSION_LESS 1930) + set(${result} + 16 + PARENT_SCOPE) + elseif(NOT MSVC_VERSION VERSION_LESS 1930 AND MSVC_VERSION VERSION_LESS 1940) + set(${result} + 17 + PARENT_SCOPE) + else() + message( + FATAL_ERROR "Conan: Unknown MSVC compiler version [${MSVC_VERSION}]") + endif() endfunction() macro(_conan_detect_build_type) - conan_parse_arguments(${ARGV}) + conan_parse_arguments(${ARGV}) - if(ARGUMENTS_BUILD_TYPE) - set(_CONAN_SETTING_BUILD_TYPE ${ARGUMENTS_BUILD_TYPE}) - elseif(CMAKE_BUILD_TYPE) - set(_CONAN_SETTING_BUILD_TYPE ${CMAKE_BUILD_TYPE}) - else() - message(FATAL_ERROR "Please specify in command line CMAKE_BUILD_TYPE (-DCMAKE_BUILD_TYPE=Release)") - endif() + if(ARGUMENTS_BUILD_TYPE) + set(_CONAN_SETTING_BUILD_TYPE ${ARGUMENTS_BUILD_TYPE}) + elseif(CMAKE_BUILD_TYPE) + set(_CONAN_SETTING_BUILD_TYPE ${CMAKE_BUILD_TYPE}) + else() + message( + FATAL_ERROR + "Please specify in command line CMAKE_BUILD_TYPE (-DCMAKE_BUILD_TYPE=Release)" + ) + endif() - string(TOUPPER ${_CONAN_SETTING_BUILD_TYPE} _CONAN_SETTING_BUILD_TYPE_UPPER) - if (_CONAN_SETTING_BUILD_TYPE_UPPER STREQUAL "DEBUG") - set(_CONAN_SETTING_BUILD_TYPE "Debug") - elseif(_CONAN_SETTING_BUILD_TYPE_UPPER STREQUAL "RELEASE") - set(_CONAN_SETTING_BUILD_TYPE "Release") - elseif(_CONAN_SETTING_BUILD_TYPE_UPPER STREQUAL "RELWITHDEBINFO") - set(_CONAN_SETTING_BUILD_TYPE "RelWithDebInfo") - elseif(_CONAN_SETTING_BUILD_TYPE_UPPER STREQUAL "MINSIZEREL") - set(_CONAN_SETTING_BUILD_TYPE "MinSizeRel") - endif() + string(TOUPPER ${_CONAN_SETTING_BUILD_TYPE} _CONAN_SETTING_BUILD_TYPE_UPPER) + if(_CONAN_SETTING_BUILD_TYPE_UPPER STREQUAL "DEBUG") + set(_CONAN_SETTING_BUILD_TYPE "Debug") + elseif(_CONAN_SETTING_BUILD_TYPE_UPPER STREQUAL "RELEASE") + set(_CONAN_SETTING_BUILD_TYPE "Release") + elseif(_CONAN_SETTING_BUILD_TYPE_UPPER STREQUAL "RELWITHDEBINFO") + set(_CONAN_SETTING_BUILD_TYPE "RelWithDebInfo") + elseif(_CONAN_SETTING_BUILD_TYPE_UPPER STREQUAL "MINSIZEREL") + set(_CONAN_SETTING_BUILD_TYPE "MinSizeRel") + endif() endmacro() macro(_conan_check_system_name) - #handle -s os setting - if(CMAKE_SYSTEM_NAME AND NOT CMAKE_SYSTEM_NAME STREQUAL "Generic") - #use default conan os setting if CMAKE_SYSTEM_NAME is not defined - set(CONAN_SYSTEM_NAME ${CMAKE_SYSTEM_NAME}) - if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") - set(CONAN_SYSTEM_NAME Macos) - endif() - if(${CMAKE_SYSTEM_NAME} STREQUAL "QNX") - set(CONAN_SYSTEM_NAME Neutrino) - endif() - set(CONAN_SUPPORTED_PLATFORMS Windows Linux Macos Android iOS FreeBSD WindowsStore WindowsCE watchOS tvOS FreeBSD SunOS AIX Arduino Emscripten Neutrino) - list (FIND CONAN_SUPPORTED_PLATFORMS "${CONAN_SYSTEM_NAME}" _index) - if (${_index} GREATER -1) - #check if the cmake system is a conan supported one - set(_CONAN_SETTING_OS ${CONAN_SYSTEM_NAME}) - else() - message(FATAL_ERROR "cmake system ${CONAN_SYSTEM_NAME} is not supported by conan. Use one of ${CONAN_SUPPORTED_PLATFORMS}") - endif() + # handle -s os setting + if(CMAKE_SYSTEM_NAME AND NOT CMAKE_SYSTEM_NAME STREQUAL "Generic") + # use default conan os setting if CMAKE_SYSTEM_NAME is not defined + set(CONAN_SYSTEM_NAME ${CMAKE_SYSTEM_NAME}) + if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") + set(CONAN_SYSTEM_NAME Macos) endif() + if(${CMAKE_SYSTEM_NAME} STREQUAL "QNX") + set(CONAN_SYSTEM_NAME Neutrino) + endif() + set(CONAN_SUPPORTED_PLATFORMS + Windows + Linux + Macos + Android + iOS + FreeBSD + WindowsStore + WindowsCE + watchOS + tvOS + FreeBSD + SunOS + AIX + Arduino + Emscripten + Neutrino) + list(FIND CONAN_SUPPORTED_PLATFORMS "${CONAN_SYSTEM_NAME}" _index) + if(${_index} GREATER -1) + # check if the cmake system is a conan supported one + set(_CONAN_SETTING_OS ${CONAN_SYSTEM_NAME}) + else() + message( + FATAL_ERROR + "cmake system ${CONAN_SYSTEM_NAME} is not supported by conan. Use one of ${CONAN_SUPPORTED_PLATFORMS}" + ) + endif() + endif() endmacro() macro(_conan_check_language) - get_property(_languages GLOBAL PROPERTY ENABLED_LANGUAGES) - if (";${_languages};" MATCHES ";CXX;") - set(LANGUAGE CXX) - set(USING_CXX 1) - elseif (";${_languages};" MATCHES ";C;") - set(LANGUAGE C) - set(USING_CXX 0) - else () - message(FATAL_ERROR "Conan: Neither C or C++ was detected as a language for the project. Unabled to detect compiler version.") - endif() + get_property(_languages GLOBAL PROPERTY ENABLED_LANGUAGES) + if(";${_languages};" MATCHES ";CXX;") + set(LANGUAGE CXX) + set(USING_CXX 1) + elseif(";${_languages};" MATCHES ";C;") + set(LANGUAGE C) + set(USING_CXX 0) + else() + message( + FATAL_ERROR + "Conan: Neither C or C++ was detected as a language for the project. Unabled to detect compiler version." + ) + endif() endmacro() macro(_conan_detect_compiler) - conan_parse_arguments(${ARGV}) + conan_parse_arguments(${ARGV}) - if(ARGUMENTS_ARCH) - set(_CONAN_SETTING_ARCH ${ARGUMENTS_ARCH}) - endif() + if(ARGUMENTS_ARCH) + set(_CONAN_SETTING_ARCH ${ARGUMENTS_ARCH}) + endif() + + if(USING_CXX) + set(_CONAN_SETTING_COMPILER_CPPSTD ${CMAKE_CXX_STANDARD}) + endif() + if(${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL GNU) + # using GCC TODO: Handle other params + string(REPLACE "." ";" VERSION_LIST ${CMAKE_${LANGUAGE}_COMPILER_VERSION}) + list(GET VERSION_LIST 0 MAJOR) + list(GET VERSION_LIST 1 MINOR) + set(COMPILER_VERSION ${MAJOR}.${MINOR}) + if(${MAJOR} GREATER 4) + set(COMPILER_VERSION ${MAJOR}) + endif() + set(_CONAN_SETTING_COMPILER gcc) + set(_CONAN_SETTING_COMPILER_VERSION ${COMPILER_VERSION}) if(USING_CXX) - set(_CONAN_SETTING_COMPILER_CPPSTD ${CMAKE_CXX_STANDARD}) + conan_cmake_detect_unix_libcxx(_LIBCXX) + set(_CONAN_SETTING_COMPILER_LIBCXX ${_LIBCXX}) endif() - - if (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL GNU) - # using GCC - # TODO: Handle other params - string(REPLACE "." ";" VERSION_LIST ${CMAKE_${LANGUAGE}_COMPILER_VERSION}) - list(GET VERSION_LIST 0 MAJOR) - list(GET VERSION_LIST 1 MINOR) - set(COMPILER_VERSION ${MAJOR}.${MINOR}) - if(${MAJOR} GREATER 4) - set(COMPILER_VERSION ${MAJOR}) - endif() - set(_CONAN_SETTING_COMPILER gcc) - set(_CONAN_SETTING_COMPILER_VERSION ${COMPILER_VERSION}) - if (USING_CXX) - conan_cmake_detect_unix_libcxx(_LIBCXX) - set(_CONAN_SETTING_COMPILER_LIBCXX ${_LIBCXX}) - endif () - elseif (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL Intel) - string(REPLACE "." ";" VERSION_LIST ${CMAKE_${LANGUAGE}_COMPILER_VERSION}) - list(GET VERSION_LIST 0 MAJOR) - list(GET VERSION_LIST 1 MINOR) - set(COMPILER_VERSION ${MAJOR}.${MINOR}) - set(_CONAN_SETTING_COMPILER intel) - set(_CONAN_SETTING_COMPILER_VERSION ${COMPILER_VERSION}) - if (USING_CXX) - conan_cmake_detect_unix_libcxx(_LIBCXX) - set(_CONAN_SETTING_COMPILER_LIBCXX ${_LIBCXX}) - endif () - elseif (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL AppleClang) - # using AppleClang - string(REPLACE "." ";" VERSION_LIST ${CMAKE_${LANGUAGE}_COMPILER_VERSION}) - list(GET VERSION_LIST 0 MAJOR) - list(GET VERSION_LIST 1 MINOR) + elseif(${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL Intel) + string(REPLACE "." ";" VERSION_LIST ${CMAKE_${LANGUAGE}_COMPILER_VERSION}) + list(GET VERSION_LIST 0 MAJOR) + list(GET VERSION_LIST 1 MINOR) + set(COMPILER_VERSION ${MAJOR}.${MINOR}) + set(_CONAN_SETTING_COMPILER intel) + set(_CONAN_SETTING_COMPILER_VERSION ${COMPILER_VERSION}) + if(USING_CXX) + conan_cmake_detect_unix_libcxx(_LIBCXX) + set(_CONAN_SETTING_COMPILER_LIBCXX ${_LIBCXX}) + endif() + elseif(${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL AppleClang) + # using AppleClang + string(REPLACE "." ";" VERSION_LIST ${CMAKE_${LANGUAGE}_COMPILER_VERSION}) + list(GET VERSION_LIST 0 MAJOR) + list(GET VERSION_LIST 1 MINOR) + set(_CONAN_SETTING_COMPILER apple-clang) + set(_CONAN_SETTING_COMPILER_VERSION ${MAJOR}.${MINOR}) + if(USING_CXX) + conan_cmake_detect_unix_libcxx(_LIBCXX) + set(_CONAN_SETTING_COMPILER_LIBCXX ${_LIBCXX}) + endif() + elseif(${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL Clang) + string(REPLACE "." ";" VERSION_LIST ${CMAKE_${LANGUAGE}_COMPILER_VERSION}) + list(GET VERSION_LIST 0 MAJOR) + list(GET VERSION_LIST 1 MINOR) + set(_CONAN_SETTING_COMPILER clang) + set(_CONAN_SETTING_COMPILER_VERSION ${MAJOR}.${MINOR}) + if(APPLE) + cmake_policy(GET CMP0025 APPLE_CLANG_POLICY) + if(NOT APPLE_CLANG_POLICY STREQUAL NEW) + message( + STATUS + "Conan: APPLE and Clang detected. Assuming apple-clang compiler. Set CMP0025 to avoid it" + ) set(_CONAN_SETTING_COMPILER apple-clang) - set(_CONAN_SETTING_COMPILER_VERSION ${MAJOR}.${MINOR}) - if (USING_CXX) - conan_cmake_detect_unix_libcxx(_LIBCXX) - set(_CONAN_SETTING_COMPILER_LIBCXX ${_LIBCXX}) - endif () - elseif (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL Clang) - string(REPLACE "." ";" VERSION_LIST ${CMAKE_${LANGUAGE}_COMPILER_VERSION}) - list(GET VERSION_LIST 0 MAJOR) - list(GET VERSION_LIST 1 MINOR) - set(_CONAN_SETTING_COMPILER clang) - set(_CONAN_SETTING_COMPILER_VERSION ${MAJOR}.${MINOR}) - if(APPLE) - cmake_policy(GET CMP0025 APPLE_CLANG_POLICY) - if(NOT APPLE_CLANG_POLICY STREQUAL NEW) - message(STATUS "Conan: APPLE and Clang detected. Assuming apple-clang compiler. Set CMP0025 to avoid it") - set(_CONAN_SETTING_COMPILER apple-clang) - endif() - endif() - if(${_CONAN_SETTING_COMPILER} STREQUAL clang AND ${MAJOR} GREATER 7) - set(_CONAN_SETTING_COMPILER_VERSION ${MAJOR}) - endif() - if (USING_CXX) - conan_cmake_detect_unix_libcxx(_LIBCXX) - set(_CONAN_SETTING_COMPILER_LIBCXX ${_LIBCXX}) - endif () - elseif(${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL MSVC) - set(_VISUAL "Visual Studio") - _get_msvc_ide_version(_VISUAL_VERSION) - if("${_VISUAL_VERSION}" STREQUAL "") - message(FATAL_ERROR "Conan: Visual Studio not recognized") - else() - set(_CONAN_SETTING_COMPILER ${_VISUAL}) - set(_CONAN_SETTING_COMPILER_VERSION ${_VISUAL_VERSION}) - endif() + endif() + endif() + if(${_CONAN_SETTING_COMPILER} STREQUAL clang AND ${MAJOR} GREATER 7) + set(_CONAN_SETTING_COMPILER_VERSION ${MAJOR}) + endif() + if(USING_CXX) + conan_cmake_detect_unix_libcxx(_LIBCXX) + set(_CONAN_SETTING_COMPILER_LIBCXX ${_LIBCXX}) + endif() + elseif(${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL MSVC) + set(_VISUAL "Visual Studio") + _get_msvc_ide_version(_VISUAL_VERSION) + if("${_VISUAL_VERSION}" STREQUAL "") + message(FATAL_ERROR "Conan: Visual Studio not recognized") + else() + set(_CONAN_SETTING_COMPILER ${_VISUAL}) + set(_CONAN_SETTING_COMPILER_VERSION ${_VISUAL_VERSION}) + endif() - if(NOT _CONAN_SETTING_ARCH) - if (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "64") - set(_CONAN_SETTING_ARCH x86_64) - elseif (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "^ARM") - message(STATUS "Conan: Using default ARM architecture from MSVC") - set(_CONAN_SETTING_ARCH armv6) - elseif (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "86") - set(_CONAN_SETTING_ARCH x86) - else () - message(FATAL_ERROR "Conan: Unknown MSVC architecture [${MSVC_${LANGUAGE}_ARCHITECTURE_ID}]") - endif() - endif() + if(NOT _CONAN_SETTING_ARCH) + if(MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "64") + set(_CONAN_SETTING_ARCH x86_64) + elseif(MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "^ARM") + message(STATUS "Conan: Using default ARM architecture from MSVC") + set(_CONAN_SETTING_ARCH armv6) + elseif(MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "86") + set(_CONAN_SETTING_ARCH x86) + else() + message( + FATAL_ERROR + "Conan: Unknown MSVC architecture [${MSVC_${LANGUAGE}_ARCHITECTURE_ID}]" + ) + endif() + endif() - conan_cmake_detect_vs_runtime(_vs_runtime ${ARGV}) - message(STATUS "Conan: Detected VS runtime: ${_vs_runtime}") - set(_CONAN_SETTING_COMPILER_RUNTIME ${_vs_runtime}) + conan_cmake_detect_vs_runtime(_vs_runtime ${ARGV}) + message(STATUS "Conan: Detected VS runtime: ${_vs_runtime}") + set(_CONAN_SETTING_COMPILER_RUNTIME ${_vs_runtime}) - if (CMAKE_GENERATOR_TOOLSET) - set(_CONAN_SETTING_COMPILER_TOOLSET ${CMAKE_VS_PLATFORM_TOOLSET}) - elseif(CMAKE_VS_PLATFORM_TOOLSET AND (CMAKE_GENERATOR STREQUAL "Ninja")) - set(_CONAN_SETTING_COMPILER_TOOLSET ${CMAKE_VS_PLATFORM_TOOLSET}) - endif() - else() - message(FATAL_ERROR "Conan: compiler setup not recognized") + if(CMAKE_GENERATOR_TOOLSET) + set(_CONAN_SETTING_COMPILER_TOOLSET ${CMAKE_VS_PLATFORM_TOOLSET}) + elseif(CMAKE_VS_PLATFORM_TOOLSET AND (CMAKE_GENERATOR STREQUAL "Ninja")) + set(_CONAN_SETTING_COMPILER_TOOLSET ${CMAKE_VS_PLATFORM_TOOLSET}) endif() + else() + message(FATAL_ERROR "Conan: compiler setup not recognized") + endif() endmacro() function(conan_cmake_settings result) - #message(STATUS "COMPILER " ${CMAKE_CXX_COMPILER}) - #message(STATUS "COMPILER " ${CMAKE_CXX_COMPILER_ID}) - #message(STATUS "VERSION " ${CMAKE_CXX_COMPILER_VERSION}) - #message(STATUS "FLAGS " ${CMAKE_LANG_FLAGS}) - #message(STATUS "LIB ARCH " ${CMAKE_CXX_LIBRARY_ARCHITECTURE}) - #message(STATUS "BUILD TYPE " ${CMAKE_BUILD_TYPE}) - #message(STATUS "GENERATOR " ${CMAKE_GENERATOR}) - #message(STATUS "GENERATOR WIN64 " ${CMAKE_CL_64}) - - message(STATUS "Conan: Automatic detection of conan settings from cmake") - - conan_parse_arguments(${ARGV}) - - _conan_detect_build_type(${ARGV}) - - _conan_check_system_name() - - _conan_check_language() - - _conan_detect_compiler(${ARGV}) - - # If profile is defined it is used - if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND ARGUMENTS_DEBUG_PROFILE) - set(_APPLIED_PROFILES ${ARGUMENTS_DEBUG_PROFILE}) - elseif(CMAKE_BUILD_TYPE STREQUAL "Release" AND ARGUMENTS_RELEASE_PROFILE) - set(_APPLIED_PROFILES ${ARGUMENTS_RELEASE_PROFILE}) - elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" AND ARGUMENTS_RELWITHDEBINFO_PROFILE) - set(_APPLIED_PROFILES ${ARGUMENTS_RELWITHDEBINFO_PROFILE}) - elseif(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" AND ARGUMENTS_MINSIZEREL_PROFILE) - set(_APPLIED_PROFILES ${ARGUMENTS_MINSIZEREL_PROFILE}) - elseif(ARGUMENTS_PROFILE) - set(_APPLIED_PROFILES ${ARGUMENTS_PROFILE}) - endif() + # message(STATUS "COMPILER " ${CMAKE_CXX_COMPILER}) message(STATUS "COMPILER " + # ${CMAKE_CXX_COMPILER_ID}) message(STATUS "VERSION " + # ${CMAKE_CXX_COMPILER_VERSION}) message(STATUS "FLAGS " ${CMAKE_LANG_FLAGS}) + # message(STATUS "LIB ARCH " ${CMAKE_CXX_LIBRARY_ARCHITECTURE}) message(STATUS + # "BUILD TYPE " ${CMAKE_BUILD_TYPE}) message(STATUS "GENERATOR " + # ${CMAKE_GENERATOR}) message(STATUS "GENERATOR WIN64 " ${CMAKE_CL_64}) - foreach(ARG ${_APPLIED_PROFILES}) - set(_SETTINGS ${_SETTINGS} -pr=${ARG}) - endforeach() - foreach(ARG ${ARGUMENTS_PROFILE_BUILD}) - conan_check(VERSION 1.24.0 REQUIRED DETECT_QUIET) - set(_SETTINGS ${_SETTINGS} -pr:b=${ARG}) - endforeach() + message(STATUS "Conan: Automatic detection of conan settings from cmake") - if(NOT _SETTINGS OR ARGUMENTS_PROFILE_AUTO STREQUAL "ALL") - set(ARGUMENTS_PROFILE_AUTO arch build_type compiler compiler.version - compiler.runtime compiler.libcxx compiler.toolset) - endif() + conan_parse_arguments(${ARGV}) - # remove any manually specified settings from the autodetected settings - foreach(ARG ${ARGUMENTS_SETTINGS}) - string(REGEX MATCH "[^=]*" MANUAL_SETTING "${ARG}") - message(STATUS "Conan: ${MANUAL_SETTING} was added as an argument. Not using the autodetected one.") - list(REMOVE_ITEM ARGUMENTS_PROFILE_AUTO "${MANUAL_SETTING}") - endforeach() - - # Automatic from CMake - foreach(ARG ${ARGUMENTS_PROFILE_AUTO}) - string(TOUPPER ${ARG} _arg_name) - string(REPLACE "." "_" _arg_name ${_arg_name}) - if(_CONAN_SETTING_${_arg_name}) - set(_SETTINGS ${_SETTINGS} -s ${ARG}=${_CONAN_SETTING_${_arg_name}}) - endif() - endforeach() + _conan_detect_build_type(${ARGV}) - foreach(ARG ${ARGUMENTS_SETTINGS}) - set(_SETTINGS ${_SETTINGS} -s ${ARG}) - endforeach() + _conan_check_system_name() - message(STATUS "Conan: Settings= ${_SETTINGS}") + _conan_check_language() - set(${result} ${_SETTINGS} PARENT_SCOPE) -endfunction() + _conan_detect_compiler(${ARGV}) + # If profile is defined it is used + if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND ARGUMENTS_DEBUG_PROFILE) + set(_APPLIED_PROFILES ${ARGUMENTS_DEBUG_PROFILE}) + elseif(CMAKE_BUILD_TYPE STREQUAL "Release" AND ARGUMENTS_RELEASE_PROFILE) + set(_APPLIED_PROFILES ${ARGUMENTS_RELEASE_PROFILE}) + elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" + AND ARGUMENTS_RELWITHDEBINFO_PROFILE) + set(_APPLIED_PROFILES ${ARGUMENTS_RELWITHDEBINFO_PROFILE}) + elseif(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" + AND ARGUMENTS_MINSIZEREL_PROFILE) + set(_APPLIED_PROFILES ${ARGUMENTS_MINSIZEREL_PROFILE}) + elseif(ARGUMENTS_PROFILE) + set(_APPLIED_PROFILES ${ARGUMENTS_PROFILE}) + endif() -function(conan_cmake_detect_unix_libcxx result) - # Take into account any -stdlib in compile options - get_directory_property(compile_options DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMPILE_OPTIONS) - string(GENEX_STRIP "${compile_options}" compile_options) - - # Take into account any _GLIBCXX_USE_CXX11_ABI in compile definitions - get_directory_property(defines DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMPILE_DEFINITIONS) - string(GENEX_STRIP "${defines}" defines) - - foreach(define ${defines}) - if(define MATCHES "_GLIBCXX_USE_CXX11_ABI") - if(define MATCHES "^-D") - set(compile_options ${compile_options} "${define}") - else() - set(compile_options ${compile_options} "-D${define}") - endif() - endif() - endforeach() + foreach(ARG ${_APPLIED_PROFILES}) + set(_SETTINGS ${_SETTINGS} -pr=${ARG}) + endforeach() + foreach(ARG ${ARGUMENTS_PROFILE_BUILD}) + conan_check(VERSION 1.24.0 REQUIRED DETECT_QUIET) + set(_SETTINGS ${_SETTINGS} -pr:b=${ARG}) + endforeach() + + if(NOT _SETTINGS OR ARGUMENTS_PROFILE_AUTO STREQUAL "ALL") + set(ARGUMENTS_PROFILE_AUTO + arch + build_type + compiler + compiler.version + compiler.runtime + compiler.libcxx + compiler.toolset) + endif() - # add additional compiler options ala cmRulePlaceholderExpander::ExpandRuleVariable - set(EXPAND_CXX_COMPILER ${CMAKE_CXX_COMPILER}) - if(CMAKE_CXX_COMPILER_ARG1) - # CMake splits CXX="foo bar baz" into CMAKE_CXX_COMPILER="foo", CMAKE_CXX_COMPILER_ARG1="bar baz" - # without this, ccache, winegcc, or other wrappers might lose all their arguments - separate_arguments(SPLIT_CXX_COMPILER_ARG1 NATIVE_COMMAND ${CMAKE_CXX_COMPILER_ARG1}) - list(APPEND EXPAND_CXX_COMPILER ${SPLIT_CXX_COMPILER_ARG1}) + # remove any manually specified settings from the autodetected settings + foreach(ARG ${ARGUMENTS_SETTINGS}) + string(REGEX MATCH "[^=]*" MANUAL_SETTING "${ARG}") + message( + STATUS + "Conan: ${MANUAL_SETTING} was added as an argument. Not using the autodetected one." + ) + list(REMOVE_ITEM ARGUMENTS_PROFILE_AUTO "${MANUAL_SETTING}") + endforeach() + + # Automatic from CMake + foreach(ARG ${ARGUMENTS_PROFILE_AUTO}) + string(TOUPPER ${ARG} _arg_name) + string(REPLACE "." "_" _arg_name ${_arg_name}) + if(_CONAN_SETTING_${_arg_name}) + set(_SETTINGS ${_SETTINGS} -s ${ARG}=${_CONAN_SETTING_${_arg_name}}) endif() + endforeach() - if(CMAKE_CXX_COMPILE_OPTIONS_TARGET AND CMAKE_CXX_COMPILER_TARGET) - # without --target= we may be calling the wrong underlying GCC - list(APPEND EXPAND_CXX_COMPILER "${CMAKE_CXX_COMPILE_OPTIONS_TARGET}${CMAKE_CXX_COMPILER_TARGET}") - endif() + foreach(ARG ${ARGUMENTS_SETTINGS}) + set(_SETTINGS ${_SETTINGS} -s ${ARG}) + endforeach() - if(CMAKE_CXX_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN AND CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN) - list(APPEND EXPAND_CXX_COMPILER "${CMAKE_CXX_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN}${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}") - endif() + message(STATUS "Conan: Settings= ${_SETTINGS}") - if(CMAKE_CXX_COMPILE_OPTIONS_SYSROOT) - # without --sysroot= we may find the wrong #include - if(CMAKE_SYSROOT_COMPILE) - list(APPEND EXPAND_CXX_COMPILER "${CMAKE_CXX_COMPILE_OPTIONS_SYSROOT}${CMAKE_SYSROOT_COMPILE}") - elseif(CMAKE_SYSROOT) - list(APPEND EXPAND_CXX_COMPILER "${CMAKE_CXX_COMPILE_OPTIONS_SYSROOT}${CMAKE_SYSROOT}") - endif() + set(${result} + ${_SETTINGS} + PARENT_SCOPE) +endfunction() + +function(conan_cmake_detect_unix_libcxx result) + # Take into account any -stdlib in compile options + get_directory_property(compile_options DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMPILE_OPTIONS) + string(GENEX_STRIP "${compile_options}" compile_options) + + # Take into account any _GLIBCXX_USE_CXX11_ABI in compile definitions + get_directory_property(defines DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMPILE_DEFINITIONS) + string(GENEX_STRIP "${defines}" defines) + + foreach(define ${defines}) + if(define MATCHES "_GLIBCXX_USE_CXX11_ABI") + if(define MATCHES "^-D") + set(compile_options ${compile_options} "${define}") + else() + set(compile_options ${compile_options} "-D${define}") + endif() endif() + endforeach() + + # add additional compiler options ala + # cmRulePlaceholderExpander::ExpandRuleVariable + set(EXPAND_CXX_COMPILER ${CMAKE_CXX_COMPILER}) + if(CMAKE_CXX_COMPILER_ARG1) + # CMake splits CXX="foo bar baz" into CMAKE_CXX_COMPILER="foo", + # CMAKE_CXX_COMPILER_ARG1="bar baz" without this, ccache, winegcc, or other + # wrappers might lose all their arguments + separate_arguments(SPLIT_CXX_COMPILER_ARG1 NATIVE_COMMAND + ${CMAKE_CXX_COMPILER_ARG1}) + list(APPEND EXPAND_CXX_COMPILER ${SPLIT_CXX_COMPILER_ARG1}) + endif() - separate_arguments(SPLIT_CXX_FLAGS NATIVE_COMMAND ${CMAKE_CXX_FLAGS}) + if(CMAKE_CXX_COMPILE_OPTIONS_TARGET AND CMAKE_CXX_COMPILER_TARGET) + # without --target= we may be calling the wrong underlying GCC + list(APPEND EXPAND_CXX_COMPILER + "${CMAKE_CXX_COMPILE_OPTIONS_TARGET}${CMAKE_CXX_COMPILER_TARGET}") + endif() - if(CMAKE_OSX_SYSROOT) - set(xcode_sysroot_option "--sysroot=${CMAKE_OSX_SYSROOT}") + if(CMAKE_CXX_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN + AND CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN) + list( + APPEND + EXPAND_CXX_COMPILER + "${CMAKE_CXX_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN}${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}" + ) + endif() + + if(CMAKE_CXX_COMPILE_OPTIONS_SYSROOT) + # without --sysroot= we may find the wrong #include + if(CMAKE_SYSROOT_COMPILE) + list(APPEND EXPAND_CXX_COMPILER + "${CMAKE_CXX_COMPILE_OPTIONS_SYSROOT}${CMAKE_SYSROOT_COMPILE}") + elseif(CMAKE_SYSROOT) + list(APPEND EXPAND_CXX_COMPILER + "${CMAKE_CXX_COMPILE_OPTIONS_SYSROOT}${CMAKE_SYSROOT}") endif() + endif() - execute_process( - COMMAND ${CMAKE_COMMAND} -E echo "#include " - COMMAND ${EXPAND_CXX_COMPILER} ${SPLIT_CXX_FLAGS} -x c++ ${xcode_sysroot_option} ${compile_options} -E -dM - - OUTPUT_VARIABLE string_defines - ) + separate_arguments(SPLIT_CXX_FLAGS NATIVE_COMMAND ${CMAKE_CXX_FLAGS}) - if(string_defines MATCHES "#define __GLIBCXX__") - # Allow -D_GLIBCXX_USE_CXX11_ABI=ON/OFF as argument to cmake - if(DEFINED _GLIBCXX_USE_CXX11_ABI) - if(_GLIBCXX_USE_CXX11_ABI) - set(${result} libstdc++11 PARENT_SCOPE) - return() - else() - set(${result} libstdc++ PARENT_SCOPE) - return() - endif() - endif() + if(CMAKE_OSX_SYSROOT) + set(xcode_sysroot_option "--sysroot=${CMAKE_OSX_SYSROOT}") + endif() - if(string_defines MATCHES "#define _GLIBCXX_USE_CXX11_ABI 1\n") - set(${result} libstdc++11 PARENT_SCOPE) - else() - # Either the compiler is missing the define because it is old, and so - # it can't use the new abi, or the compiler was configured to use the - # old abi by the user or distro (e.g. devtoolset on RHEL/CentOS) - set(${result} libstdc++ PARENT_SCOPE) - endif() + execute_process( + COMMAND ${CMAKE_COMMAND} -E echo "#include " + COMMAND ${EXPAND_CXX_COMPILER} ${SPLIT_CXX_FLAGS} -x c++ + ${xcode_sysroot_option} ${compile_options} -E -dM - + OUTPUT_VARIABLE string_defines) + + if(string_defines MATCHES "#define __GLIBCXX__") + # Allow -D_GLIBCXX_USE_CXX11_ABI=ON/OFF as argument to cmake + if(DEFINED _GLIBCXX_USE_CXX11_ABI) + if(_GLIBCXX_USE_CXX11_ABI) + set(${result} + libstdc++11 + PARENT_SCOPE) + return() + else() + set(${result} + libstdc++ + PARENT_SCOPE) + return() + endif() + endif() + + if(string_defines MATCHES "#define _GLIBCXX_USE_CXX11_ABI 1\n") + set(${result} + libstdc++11 + PARENT_SCOPE) else() - set(${result} libc++ PARENT_SCOPE) + # Either the compiler is missing the define because it is old, and so it + # can't use the new abi, or the compiler was configured to use the old abi + # by the user or distro (e.g. devtoolset on RHEL/CentOS) + set(${result} + libstdc++ + PARENT_SCOPE) endif() + else() + set(${result} + libc++ + PARENT_SCOPE) + endif() endfunction() function(conan_cmake_detect_vs_runtime result) - conan_parse_arguments(${ARGV}) - if(ARGUMENTS_BUILD_TYPE) - set(build_type "${ARGUMENTS_BUILD_TYPE}") - elseif(CMAKE_BUILD_TYPE) - set(build_type "${CMAKE_BUILD_TYPE}") - else() - message(FATAL_ERROR "Please specify in command line CMAKE_BUILD_TYPE (-DCMAKE_BUILD_TYPE=Release)") - endif() + conan_parse_arguments(${ARGV}) + if(ARGUMENTS_BUILD_TYPE) + set(build_type "${ARGUMENTS_BUILD_TYPE}") + elseif(CMAKE_BUILD_TYPE) + set(build_type "${CMAKE_BUILD_TYPE}") + else() + message( + FATAL_ERROR + "Please specify in command line CMAKE_BUILD_TYPE (-DCMAKE_BUILD_TYPE=Release)" + ) + endif() - if(build_type) - string(TOUPPER "${build_type}" build_type) - endif() - set(variables CMAKE_CXX_FLAGS_${build_type} CMAKE_C_FLAGS_${build_type} CMAKE_CXX_FLAGS CMAKE_C_FLAGS) - foreach(variable ${variables}) - if(NOT "${${variable}}" STREQUAL "") - string(REPLACE " " ";" flags "${${variable}}") - foreach (flag ${flags}) - if("${flag}" STREQUAL "/MD" OR "${flag}" STREQUAL "/MDd" OR "${flag}" STREQUAL "/MT" OR "${flag}" STREQUAL "/MTd") - string(SUBSTRING "${flag}" 1 -1 runtime) - set(${result} "${runtime}" PARENT_SCOPE) - return() - endif() - endforeach() + if(build_type) + string(TOUPPER "${build_type}" build_type) + endif() + set(variables CMAKE_CXX_FLAGS_${build_type} CMAKE_C_FLAGS_${build_type} + CMAKE_CXX_FLAGS CMAKE_C_FLAGS) + foreach(variable ${variables}) + if(NOT "${${variable}}" STREQUAL "") + string(REPLACE " " ";" flags "${${variable}}") + foreach(flag ${flags}) + if("${flag}" STREQUAL "/MD" + OR "${flag}" STREQUAL "/MDd" + OR "${flag}" STREQUAL "/MT" + OR "${flag}" STREQUAL "/MTd") + string(SUBSTRING "${flag}" 1 -1 runtime) + set(${result} + "${runtime}" + PARENT_SCOPE) + return() endif() - endforeach() - if("${build_type}" STREQUAL "DEBUG") - set(${result} "MDd" PARENT_SCOPE) - else() - set(${result} "MD" PARENT_SCOPE) + endforeach() endif() + endforeach() + if("${build_type}" STREQUAL "DEBUG") + set(${result} + "MDd" + PARENT_SCOPE) + else() + set(${result} + "MD" + PARENT_SCOPE) + endif() endfunction() function(_collect_settings result) - set(ARGUMENTS_PROFILE_AUTO arch build_type compiler compiler.version - compiler.runtime compiler.libcxx compiler.toolset - compiler.cppstd) - foreach(ARG ${ARGUMENTS_PROFILE_AUTO}) - string(TOUPPER ${ARG} _arg_name) - string(REPLACE "." "_" _arg_name ${_arg_name}) - if(_CONAN_SETTING_${_arg_name}) - set(detected_setings ${detected_setings} ${ARG}=${_CONAN_SETTING_${_arg_name}}) - endif() - endforeach() - set(${result} ${detected_setings} PARENT_SCOPE) + set(ARGUMENTS_PROFILE_AUTO + arch + build_type + compiler + compiler.version + compiler.runtime + compiler.libcxx + compiler.toolset + compiler.cppstd) + foreach(ARG ${ARGUMENTS_PROFILE_AUTO}) + string(TOUPPER ${ARG} _arg_name) + string(REPLACE "." "_" _arg_name ${_arg_name}) + if(_CONAN_SETTING_${_arg_name}) + set(detected_setings ${detected_setings} + ${ARG}=${_CONAN_SETTING_${_arg_name}}) + endif() + endforeach() + set(${result} + ${detected_setings} + PARENT_SCOPE) endfunction() function(conan_cmake_autodetect detected_settings) - _conan_detect_build_type(${ARGV}) - _conan_check_system_name() - _conan_check_language() - _conan_detect_compiler(${ARGV}) - _collect_settings(collected_settings) - set(${detected_settings} ${collected_settings} PARENT_SCOPE) + _conan_detect_build_type(${ARGV}) + _conan_check_system_name() + _conan_check_language() + _conan_detect_compiler(${ARGV}) + _collect_settings(collected_settings) + set(${detected_settings} + ${collected_settings} + PARENT_SCOPE) endfunction() macro(conan_parse_arguments) - set(options BASIC_SETUP CMAKE_TARGETS UPDATE KEEP_RPATHS NO_LOAD NO_OUTPUT_DIRS OUTPUT_QUIET NO_IMPORTS SKIP_STD) - set(oneValueArgs CONANFILE ARCH BUILD_TYPE INSTALL_FOLDER CONAN_COMMAND) - set(multiValueArgs DEBUG_PROFILE RELEASE_PROFILE RELWITHDEBINFO_PROFILE MINSIZEREL_PROFILE - PROFILE REQUIRES OPTIONS IMPORTS SETTINGS BUILD ENV GENERATORS PROFILE_AUTO - INSTALL_ARGS CONFIGURATION_TYPES PROFILE_BUILD BUILD_REQUIRES) - cmake_parse_arguments(ARGUMENTS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + set(options + BASIC_SETUP + CMAKE_TARGETS + UPDATE + KEEP_RPATHS + NO_LOAD + NO_OUTPUT_DIRS + OUTPUT_QUIET + NO_IMPORTS + SKIP_STD) + set(oneValueArgs CONANFILE ARCH BUILD_TYPE INSTALL_FOLDER CONAN_COMMAND) + set(multiValueArgs + DEBUG_PROFILE + RELEASE_PROFILE + RELWITHDEBINFO_PROFILE + MINSIZEREL_PROFILE + PROFILE + REQUIRES + OPTIONS + IMPORTS + SETTINGS + BUILD + ENV + GENERATORS + PROFILE_AUTO + INSTALL_ARGS + CONFIGURATION_TYPES + PROFILE_BUILD + BUILD_REQUIRES) + cmake_parse_arguments(ARGUMENTS "${options}" "${oneValueArgs}" + "${multiValueArgs}" ${ARGN}) endmacro() function(old_conan_cmake_install) - # Calls "conan install" - # Argument BUILD is equivalant to --build={missing, PkgName,...} or - # --build when argument is 'BUILD all' (which builds all packages from source) - # Argument CONAN_COMMAND, to specify the conan path, e.g. in case of running from source - # cmake does not identify conan as command, even if it is +x and it is in the path - conan_parse_arguments(${ARGV}) + # Calls "conan install" Argument BUILD is equivalant to --build={missing, + # PkgName,...} or --build when argument is 'BUILD all' (which builds all + # packages from source) Argument CONAN_COMMAND, to specify the conan path, + # e.g. in case of running from source cmake does not identify conan as + # command, even if it is +x and it is in the path + conan_parse_arguments(${ARGV}) - if(CONAN_CMAKE_MULTI) - set(ARGUMENTS_GENERATORS ${ARGUMENTS_GENERATORS} cmake_multi) - else() - set(ARGUMENTS_GENERATORS ${ARGUMENTS_GENERATORS} cmake) - endif() + if(CONAN_CMAKE_MULTI) + set(ARGUMENTS_GENERATORS ${ARGUMENTS_GENERATORS} cmake_multi) + else() + set(ARGUMENTS_GENERATORS ${ARGUMENTS_GENERATORS} cmake) + endif() - set(CONAN_BUILD_POLICY "") - foreach(ARG ${ARGUMENTS_BUILD}) - if(${ARG} STREQUAL "all") - set(CONAN_BUILD_POLICY ${CONAN_BUILD_POLICY} --build) - break() - else() - set(CONAN_BUILD_POLICY ${CONAN_BUILD_POLICY} --build=${ARG}) - endif() - endforeach() - if(ARGUMENTS_CONAN_COMMAND) - set(CONAN_CMD ${ARGUMENTS_CONAN_COMMAND}) - else() - conan_check(REQUIRED) - endif() - set(CONAN_OPTIONS "") - if(ARGUMENTS_CONANFILE) - if(IS_ABSOLUTE ${ARGUMENTS_CONANFILE}) - set(CONANFILE ${ARGUMENTS_CONANFILE}) - else() - set(CONANFILE ${CMAKE_CURRENT_SOURCE_DIR}/${ARGUMENTS_CONANFILE}) - endif() + set(CONAN_BUILD_POLICY "") + foreach(ARG ${ARGUMENTS_BUILD}) + if(${ARG} STREQUAL "all") + set(CONAN_BUILD_POLICY ${CONAN_BUILD_POLICY} --build) + break() else() - set(CONANFILE ".") + set(CONAN_BUILD_POLICY ${CONAN_BUILD_POLICY} --build=${ARG}) endif() - foreach(ARG ${ARGUMENTS_OPTIONS}) - set(CONAN_OPTIONS ${CONAN_OPTIONS} -o=${ARG}) - endforeach() - if(ARGUMENTS_UPDATE) - set(CONAN_INSTALL_UPDATE --update) - endif() - if(ARGUMENTS_NO_IMPORTS) - set(CONAN_INSTALL_NO_IMPORTS --no-imports) - endif() - set(CONAN_INSTALL_FOLDER "") - if(ARGUMENTS_INSTALL_FOLDER) - set(CONAN_INSTALL_FOLDER -if=${ARGUMENTS_INSTALL_FOLDER}) - endif() - foreach(ARG ${ARGUMENTS_GENERATORS}) - set(CONAN_GENERATORS ${CONAN_GENERATORS} -g=${ARG}) - endforeach() - foreach(ARG ${ARGUMENTS_ENV}) - set(CONAN_ENV_VARS ${CONAN_ENV_VARS} -e=${ARG}) - endforeach() - set(conan_args install ${CONANFILE} ${settings} ${CONAN_ENV_VARS} ${CONAN_GENERATORS} ${CONAN_BUILD_POLICY} ${CONAN_INSTALL_UPDATE} ${CONAN_INSTALL_NO_IMPORTS} ${CONAN_OPTIONS} ${CONAN_INSTALL_FOLDER} ${ARGUMENTS_INSTALL_ARGS}) - - string (REPLACE ";" " " _conan_args "${conan_args}") - message(STATUS "Conan executing: ${CONAN_CMD} ${_conan_args}") - - if(ARGUMENTS_OUTPUT_QUIET) - execute_process(COMMAND ${CONAN_CMD} ${conan_args} - RESULT_VARIABLE return_code - OUTPUT_VARIABLE conan_output - ERROR_VARIABLE conan_output - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + endforeach() + if(ARGUMENTS_CONAN_COMMAND) + set(CONAN_CMD ${ARGUMENTS_CONAN_COMMAND}) + else() + conan_check(REQUIRED) + endif() + set(CONAN_OPTIONS "") + if(ARGUMENTS_CONANFILE) + if(IS_ABSOLUTE ${ARGUMENTS_CONANFILE}) + set(CONANFILE ${ARGUMENTS_CONANFILE}) else() - execute_process(COMMAND ${CONAN_CMD} ${conan_args} - RESULT_VARIABLE return_code - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set(CONANFILE ${CMAKE_CURRENT_SOURCE_DIR}/${ARGUMENTS_CONANFILE}) endif() + else() + set(CONANFILE ".") + endif() + foreach(ARG ${ARGUMENTS_OPTIONS}) + set(CONAN_OPTIONS ${CONAN_OPTIONS} -o=${ARG}) + endforeach() + if(ARGUMENTS_UPDATE) + set(CONAN_INSTALL_UPDATE --update) + endif() + if(ARGUMENTS_NO_IMPORTS) + set(CONAN_INSTALL_NO_IMPORTS --no-imports) + endif() + set(CONAN_INSTALL_FOLDER "") + if(ARGUMENTS_INSTALL_FOLDER) + set(CONAN_INSTALL_FOLDER -if=${ARGUMENTS_INSTALL_FOLDER}) + endif() + foreach(ARG ${ARGUMENTS_GENERATORS}) + set(CONAN_GENERATORS ${CONAN_GENERATORS} -g=${ARG}) + endforeach() + foreach(ARG ${ARGUMENTS_ENV}) + set(CONAN_ENV_VARS ${CONAN_ENV_VARS} -e=${ARG}) + endforeach() + set(conan_args + install + ${CONANFILE} + ${settings} + ${CONAN_ENV_VARS} + ${CONAN_GENERATORS} + ${CONAN_BUILD_POLICY} + ${CONAN_INSTALL_UPDATE} + ${CONAN_INSTALL_NO_IMPORTS} + ${CONAN_OPTIONS} + ${CONAN_INSTALL_FOLDER} + ${ARGUMENTS_INSTALL_ARGS}) + + string(REPLACE ";" " " _conan_args "${conan_args}") + message(STATUS "Conan executing: ${CONAN_CMD} ${_conan_args}") + + if(ARGUMENTS_OUTPUT_QUIET) + execute_process( + COMMAND ${CONAN_CMD} ${conan_args} + RESULT_VARIABLE return_code + OUTPUT_VARIABLE conan_output + ERROR_VARIABLE conan_output + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + else() + execute_process( + COMMAND ${CONAN_CMD} ${conan_args} + RESULT_VARIABLE return_code + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + endif() - if(NOT "${return_code}" STREQUAL "0") - message(FATAL_ERROR "Conan install failed='${return_code}'") - endif() + if(NOT "${return_code}" STREQUAL "0") + message(FATAL_ERROR "Conan install failed='${return_code}'") + endif() endfunction() function(conan_cmake_install) - if(DEFINED CONAN_COMMAND) - set(CONAN_CMD ${CONAN_COMMAND}) - else() - conan_check(REQUIRED) - endif() + if(DEFINED CONAN_COMMAND) + set(CONAN_CMD ${CONAN_COMMAND}) + else() + conan_check(REQUIRED) + endif() - set(installOptions UPDATE NO_IMPORTS OUTPUT_QUIET ERROR_QUIET) - set(installOneValueArgs PATH_OR_REFERENCE REFERENCE REMOTE LOCKFILE LOCKFILE_OUT LOCKFILE_NODE_ID INSTALL_FOLDER) - set(installMultiValueArgs GENERATOR BUILD ENV ENV_HOST ENV_BUILD OPTIONS_HOST OPTIONS OPTIONS_BUILD PROFILE - PROFILE_HOST PROFILE_BUILD SETTINGS SETTINGS_HOST SETTINGS_BUILD) - cmake_parse_arguments(ARGS "${installOptions}" "${installOneValueArgs}" "${installMultiValueArgs}" ${ARGN}) - foreach(arg ${installOptions}) - if(ARGS_${arg}) - set(${arg} ${${arg}} ${ARGS_${arg}}) - endif() - endforeach() - foreach(arg ${installOneValueArgs}) - if(DEFINED ARGS_${arg}) - if("${arg}" STREQUAL "REMOTE") - set(flag "--remote") - elseif("${arg}" STREQUAL "LOCKFILE") - set(flag "--lockfile") - elseif("${arg}" STREQUAL "LOCKFILE_OUT") - set(flag "--lockfile-out") - elseif("${arg}" STREQUAL "LOCKFILE_NODE_ID") - set(flag "--lockfile-node-id") - elseif("${arg}" STREQUAL "INSTALL_FOLDER") - set(flag "--install-folder") - endif() - set(${arg} ${${arg}} ${flag} ${ARGS_${arg}}) - endif() - endforeach() - foreach(arg ${installMultiValueArgs}) - if(DEFINED ARGS_${arg}) - if("${arg}" STREQUAL "GENERATOR") - set(flag "--generator") - elseif("${arg}" STREQUAL "BUILD") - set(flag "--build") - elseif("${arg}" STREQUAL "ENV") - set(flag "--env") - elseif("${arg}" STREQUAL "ENV_HOST") - set(flag "--env:host") - elseif("${arg}" STREQUAL "ENV_BUILD") - set(flag "--env:build") - elseif("${arg}" STREQUAL "OPTIONS") - set(flag "--options") - elseif("${arg}" STREQUAL "OPTIONS_HOST") - set(flag "--options:host") - elseif("${arg}" STREQUAL "OPTIONS_BUILD") - set(flag "--options:build") - elseif("${arg}" STREQUAL "PROFILE") - set(flag "--profile") - elseif("${arg}" STREQUAL "PROFILE_HOST") - set(flag "--profile:host") - elseif("${arg}" STREQUAL "PROFILE_BUILD") - set(flag "--profile:build") - elseif("${arg}" STREQUAL "SETTINGS") - set(flag "--settings") - elseif("${arg}" STREQUAL "SETTINGS_HOST") - set(flag "--settings:host") - elseif("${arg}" STREQUAL "SETTINGS_BUILD") - set(flag "--settings:build") - endif() - list(LENGTH ARGS_${arg} numargs) - foreach(item ${ARGS_${arg}}) - if(${item} STREQUAL "all" AND ${arg} STREQUAL "BUILD") - set(${arg} "--build") - break() - endif() - set(${arg} ${${arg}} ${flag} ${item}) - endforeach() - endif() - endforeach() - if(DEFINED UPDATE) - set(UPDATE --update) - endif() - if(DEFINED NO_IMPORTS) - set(NO_IMPORTS --no-imports) + set(installOptions UPDATE NO_IMPORTS OUTPUT_QUIET ERROR_QUIET) + set(installOneValueArgs + PATH_OR_REFERENCE + REFERENCE + REMOTE + LOCKFILE + LOCKFILE_OUT + LOCKFILE_NODE_ID + INSTALL_FOLDER) + set(installMultiValueArgs + GENERATOR + BUILD + ENV + ENV_HOST + ENV_BUILD + OPTIONS_HOST + OPTIONS + OPTIONS_BUILD + PROFILE + PROFILE_HOST + PROFILE_BUILD + SETTINGS + SETTINGS_HOST + SETTINGS_BUILD) + cmake_parse_arguments(ARGS "${installOptions}" "${installOneValueArgs}" + "${installMultiValueArgs}" ${ARGN}) + foreach(arg ${installOptions}) + if(ARGS_${arg}) + set(${arg} ${${arg}} ${ARGS_${arg}}) endif() - set(install_args install ${PATH_OR_REFERENCE} ${REFERENCE} ${UPDATE} ${NO_IMPORTS} ${REMOTE} ${LOCKFILE} ${LOCKFILE_OUT} ${LOCKFILE_NODE_ID} ${INSTALL_FOLDER} - ${GENERATOR} ${BUILD} ${ENV} ${ENV_HOST} ${ENV_BUILD} ${OPTIONS} ${OPTIONS_HOST} ${OPTIONS_BUILD} - ${PROFILE} ${PROFILE_HOST} ${PROFILE_BUILD} ${SETTINGS} ${SETTINGS_HOST} ${SETTINGS_BUILD}) - - string(REPLACE ";" " " _install_args "${install_args}") - message(STATUS "Conan executing: ${CONAN_CMD} ${_install_args}") - - if(ARGS_OUTPUT_QUIET) - set(OUTPUT_OPT OUTPUT_QUIET) + endforeach() + foreach(arg ${installOneValueArgs}) + if(DEFINED ARGS_${arg}) + if("${arg}" STREQUAL "REMOTE") + set(flag "--remote") + elseif("${arg}" STREQUAL "LOCKFILE") + set(flag "--lockfile") + elseif("${arg}" STREQUAL "LOCKFILE_OUT") + set(flag "--lockfile-out") + elseif("${arg}" STREQUAL "LOCKFILE_NODE_ID") + set(flag "--lockfile-node-id") + elseif("${arg}" STREQUAL "INSTALL_FOLDER") + set(flag "--install-folder") + endif() + set(${arg} ${${arg}} ${flag} ${ARGS_${arg}}) endif() - if(ARGS_ERROR_QUIET) - set(ERROR_OPT ERROR_QUIET) + endforeach() + foreach(arg ${installMultiValueArgs}) + if(DEFINED ARGS_${arg}) + if("${arg}" STREQUAL "GENERATOR") + set(flag "--generator") + elseif("${arg}" STREQUAL "BUILD") + set(flag "--build") + elseif("${arg}" STREQUAL "ENV") + set(flag "--env") + elseif("${arg}" STREQUAL "ENV_HOST") + set(flag "--env:host") + elseif("${arg}" STREQUAL "ENV_BUILD") + set(flag "--env:build") + elseif("${arg}" STREQUAL "OPTIONS") + set(flag "--options") + elseif("${arg}" STREQUAL "OPTIONS_HOST") + set(flag "--options:host") + elseif("${arg}" STREQUAL "OPTIONS_BUILD") + set(flag "--options:build") + elseif("${arg}" STREQUAL "PROFILE") + set(flag "--profile") + elseif("${arg}" STREQUAL "PROFILE_HOST") + set(flag "--profile:host") + elseif("${arg}" STREQUAL "PROFILE_BUILD") + set(flag "--profile:build") + elseif("${arg}" STREQUAL "SETTINGS") + set(flag "--settings") + elseif("${arg}" STREQUAL "SETTINGS_HOST") + set(flag "--settings:host") + elseif("${arg}" STREQUAL "SETTINGS_BUILD") + set(flag "--settings:build") + endif() + list(LENGTH ARGS_${arg} numargs) + foreach(item ${ARGS_${arg}}) + if(${item} STREQUAL "all" AND ${arg} STREQUAL "BUILD") + set(${arg} "--build") + break() + endif() + set(${arg} ${${arg}} ${flag} ${item}) + endforeach() endif() + endforeach() + if(DEFINED UPDATE) + set(UPDATE --update) + endif() + if(DEFINED NO_IMPORTS) + set(NO_IMPORTS --no-imports) + endif() + set(install_args + install + ${PATH_OR_REFERENCE} + ${REFERENCE} + ${UPDATE} + ${NO_IMPORTS} + ${REMOTE} + ${LOCKFILE} + ${LOCKFILE_OUT} + ${LOCKFILE_NODE_ID} + ${INSTALL_FOLDER} + ${GENERATOR} + ${BUILD} + ${ENV} + ${ENV_HOST} + ${ENV_BUILD} + ${OPTIONS} + ${OPTIONS_HOST} + ${OPTIONS_BUILD} + ${PROFILE} + ${PROFILE_HOST} + ${PROFILE_BUILD} + ${SETTINGS} + ${SETTINGS_HOST} + ${SETTINGS_BUILD}) + + string(REPLACE ";" " " _install_args "${install_args}") + message(STATUS "Conan executing: ${CONAN_CMD} ${_install_args}") + + if(ARGS_OUTPUT_QUIET) + set(OUTPUT_OPT OUTPUT_QUIET) + endif() + if(ARGS_ERROR_QUIET) + set(ERROR_OPT ERROR_QUIET) + endif() - execute_process(COMMAND ${CONAN_CMD} ${install_args} - RESULT_VARIABLE return_code - ${OUTPUT_OPT} - ${ERROR_OPT} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + execute_process( + COMMAND ${CONAN_CMD} ${install_args} + RESULT_VARIABLE return_code ${OUTPUT_OPT} ${ERROR_OPT} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - if(NOT "${return_code}" STREQUAL "0") - if (ARGS_ERROR_QUIET) - message(WARNING "Conan install failed='${return_code}'") - else() - message(FATAL_ERROR "Conan install failed='${return_code}'") - endif() + if(NOT "${return_code}" STREQUAL "0") + if(ARGS_ERROR_QUIET) + message(WARNING "Conan install failed='${return_code}'") + else() + message(FATAL_ERROR "Conan install failed='${return_code}'") endif() + endif() endfunction() @@ -646,7 +834,8 @@ function(conan_cmake_setup_conanfile) if(ARGUMENTS_CONANFILE) get_filename_component(_CONANFILE_NAME ${ARGUMENTS_CONANFILE} NAME) # configure_file will make sure cmake re-runs when conanfile is updated - configure_file(${ARGUMENTS_CONANFILE} ${CMAKE_CURRENT_BINARY_DIR}/${_CONANFILE_NAME}.junk COPYONLY) + configure_file(${ARGUMENTS_CONANFILE} + ${CMAKE_CURRENT_BINARY_DIR}/${_CONANFILE_NAME}.junk COPYONLY) file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/${_CONANFILE_NAME}.junk) else() conan_cmake_generate_conanfile(ON ${ARGV}) @@ -654,255 +843,265 @@ function(conan_cmake_setup_conanfile) endfunction() function(conan_cmake_configure) - conan_cmake_generate_conanfile(OFF ${ARGV}) + conan_cmake_generate_conanfile(OFF ${ARGV}) endfunction() -# Generate, writing in disk a conanfile.txt with the requires, options, and imports -# specified as arguments -# This will be considered as temporary file, generated in CMAKE_CURRENT_BINARY_DIR) +# Generate, writing in disk a conanfile.txt with the requires, options, and +# imports specified as arguments This will be considered as temporary file, +# generated in CMAKE_CURRENT_BINARY_DIR) function(conan_cmake_generate_conanfile DEFAULT_GENERATOR) - conan_parse_arguments(${ARGV}) + conan_parse_arguments(${ARGV}) - set(_FN "${CMAKE_CURRENT_BINARY_DIR}/conanfile.txt") - file(WRITE ${_FN} "") + set(_FN "${CMAKE_CURRENT_BINARY_DIR}/conanfile.txt") + file(WRITE ${_FN} "") - if(DEFINED ARGUMENTS_REQUIRES) - file(APPEND ${_FN} "[requires]\n") - foreach(REQUIRE ${ARGUMENTS_REQUIRES}) - file(APPEND ${_FN} ${REQUIRE} "\n") - endforeach() - endif() + if(DEFINED ARGUMENTS_REQUIRES) + file(APPEND ${_FN} "[requires]\n") + foreach(REQUIRE ${ARGUMENTS_REQUIRES}) + file(APPEND ${_FN} ${REQUIRE} "\n") + endforeach() + endif() - if (DEFAULT_GENERATOR OR DEFINED ARGUMENTS_GENERATORS) - file(APPEND ${_FN} "[generators]\n") - if (DEFAULT_GENERATOR) - file(APPEND ${_FN} "cmake\n") - endif() - if (DEFINED ARGUMENTS_GENERATORS) - foreach(GENERATOR ${ARGUMENTS_GENERATORS}) - file(APPEND ${_FN} ${GENERATOR} "\n") - endforeach() - endif() + if(DEFAULT_GENERATOR OR DEFINED ARGUMENTS_GENERATORS) + file(APPEND ${_FN} "[generators]\n") + if(DEFAULT_GENERATOR) + file(APPEND ${_FN} "cmake\n") endif() - - if(DEFINED ARGUMENTS_BUILD_REQUIRES) - file(APPEND ${_FN} "[build_requires]\n") - foreach(BUILD_REQUIRE ${ARGUMENTS_BUILD_REQUIRES}) - file(APPEND ${_FN} ${BUILD_REQUIRE} "\n") - endforeach() + if(DEFINED ARGUMENTS_GENERATORS) + foreach(GENERATOR ${ARGUMENTS_GENERATORS}) + file(APPEND ${_FN} ${GENERATOR} "\n") + endforeach() endif() + endif() - if(DEFINED ARGUMENTS_IMPORTS) - file(APPEND ${_FN} "[imports]\n") - foreach(IMPORTS ${ARGUMENTS_IMPORTS}) - file(APPEND ${_FN} ${IMPORTS} "\n") - endforeach() - endif() + if(DEFINED ARGUMENTS_BUILD_REQUIRES) + file(APPEND ${_FN} "[build_requires]\n") + foreach(BUILD_REQUIRE ${ARGUMENTS_BUILD_REQUIRES}) + file(APPEND ${_FN} ${BUILD_REQUIRE} "\n") + endforeach() + endif() - if(DEFINED ARGUMENTS_OPTIONS) - file(APPEND ${_FN} "[options]\n") - foreach(OPTION ${ARGUMENTS_OPTIONS}) - file(APPEND ${_FN} ${OPTION} "\n") - endforeach() - endif() + if(DEFINED ARGUMENTS_IMPORTS) + file(APPEND ${_FN} "[imports]\n") + foreach(IMPORTS ${ARGUMENTS_IMPORTS}) + file(APPEND ${_FN} ${IMPORTS} "\n") + endforeach() + endif() -endfunction() + if(DEFINED ARGUMENTS_OPTIONS) + file(APPEND ${_FN} "[options]\n") + foreach(OPTION ${ARGUMENTS_OPTIONS}) + file(APPEND ${_FN} ${OPTION} "\n") + endforeach() + endif() +endfunction() macro(conan_load_buildinfo) - if(CONAN_CMAKE_MULTI) - set(_CONANBUILDINFO conanbuildinfo_multi.cmake) - else() - set(_CONANBUILDINFO conanbuildinfo.cmake) - endif() - if(ARGUMENTS_INSTALL_FOLDER) - set(_CONANBUILDINFOFOLDER ${ARGUMENTS_INSTALL_FOLDER}) - else() - set(_CONANBUILDINFOFOLDER ${CMAKE_CURRENT_BINARY_DIR}) - endif() - # Checks for the existence of conanbuildinfo.cmake, and loads it - # important that it is macro, so variables defined at parent scope - if(EXISTS "${_CONANBUILDINFOFOLDER}/${_CONANBUILDINFO}") - message(STATUS "Conan: Loading ${_CONANBUILDINFO}") - include(${_CONANBUILDINFOFOLDER}/${_CONANBUILDINFO}) - else() - message(FATAL_ERROR "${_CONANBUILDINFO} doesn't exist in ${CMAKE_CURRENT_BINARY_DIR}") - endif() + if(CONAN_CMAKE_MULTI) + set(_CONANBUILDINFO conanbuildinfo_multi.cmake) + else() + set(_CONANBUILDINFO conanbuildinfo.cmake) + endif() + if(ARGUMENTS_INSTALL_FOLDER) + set(_CONANBUILDINFOFOLDER ${ARGUMENTS_INSTALL_FOLDER}) + else() + set(_CONANBUILDINFOFOLDER ${CMAKE_CURRENT_BINARY_DIR}) + endif() + # Checks for the existence of conanbuildinfo.cmake, and loads it important + # that it is macro, so variables defined at parent scope + if(EXISTS "${_CONANBUILDINFOFOLDER}/${_CONANBUILDINFO}") + message(STATUS "Conan: Loading ${_CONANBUILDINFO}") + include(${_CONANBUILDINFOFOLDER}/${_CONANBUILDINFO}) + else() + message( + FATAL_ERROR + "${_CONANBUILDINFO} doesn't exist in ${CMAKE_CURRENT_BINARY_DIR}") + endif() endmacro() - macro(conan_cmake_run) - conan_parse_arguments(${ARGV}) - - if(ARGUMENTS_CONFIGURATION_TYPES AND NOT CMAKE_CONFIGURATION_TYPES) - message(WARNING "CONFIGURATION_TYPES should only be specified for multi-configuration generators") - elseif(ARGUMENTS_CONFIGURATION_TYPES AND ARGUMENTS_BUILD_TYPE) - message(WARNING "CONFIGURATION_TYPES and BUILD_TYPE arguments should not be defined at the same time.") + conan_parse_arguments(${ARGV}) + + if(ARGUMENTS_CONFIGURATION_TYPES AND NOT CMAKE_CONFIGURATION_TYPES) + message( + WARNING + "CONFIGURATION_TYPES should only be specified for multi-configuration generators" + ) + elseif(ARGUMENTS_CONFIGURATION_TYPES AND ARGUMENTS_BUILD_TYPE) + message( + WARNING + "CONFIGURATION_TYPES and BUILD_TYPE arguments should not be defined at the same time." + ) + endif() + + if(CMAKE_CONFIGURATION_TYPES + AND NOT CMAKE_BUILD_TYPE + AND NOT CONAN_EXPORTED + AND NOT ARGUMENTS_BUILD_TYPE) + set(CONAN_CMAKE_MULTI ON) + if(NOT ARGUMENTS_CONFIGURATION_TYPES) + set(ARGUMENTS_CONFIGURATION_TYPES "Release;Debug") endif() + message(STATUS "Conan: Using cmake-multi generator") + else() + set(CONAN_CMAKE_MULTI OFF) + endif() - if(CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE AND NOT CONAN_EXPORTED - AND NOT ARGUMENTS_BUILD_TYPE) - set(CONAN_CMAKE_MULTI ON) - if (NOT ARGUMENTS_CONFIGURATION_TYPES) - set(ARGUMENTS_CONFIGURATION_TYPES "Release;Debug") - endif() - message(STATUS "Conan: Using cmake-multi generator") + if(NOT CONAN_EXPORTED) + conan_cmake_setup_conanfile(${ARGV}) + if(CONAN_CMAKE_MULTI) + foreach(CMAKE_BUILD_TYPE ${ARGUMENTS_CONFIGURATION_TYPES}) + set(ENV{CONAN_IMPORT_PATH} ${CMAKE_BUILD_TYPE}) + conan_cmake_settings(settings ${ARGV}) + old_conan_cmake_install(SETTINGS ${settings} ${ARGV}) + endforeach() + set(CMAKE_BUILD_TYPE) else() - set(CONAN_CMAKE_MULTI OFF) + conan_cmake_settings(settings ${ARGV}) + old_conan_cmake_install(SETTINGS ${settings} ${ARGV}) endif() + endif() + + if(NOT ARGUMENTS_NO_LOAD) + conan_load_buildinfo() + endif() - if(NOT CONAN_EXPORTED) - conan_cmake_setup_conanfile(${ARGV}) - if(CONAN_CMAKE_MULTI) - foreach(CMAKE_BUILD_TYPE ${ARGUMENTS_CONFIGURATION_TYPES}) - set(ENV{CONAN_IMPORT_PATH} ${CMAKE_BUILD_TYPE}) - conan_cmake_settings(settings ${ARGV}) - old_conan_cmake_install(SETTINGS ${settings} ${ARGV}) - endforeach() - set(CMAKE_BUILD_TYPE) + if(ARGUMENTS_BASIC_SETUP) + foreach(_option CMAKE_TARGETS KEEP_RPATHS NO_OUTPUT_DIRS SKIP_STD) + if(ARGUMENTS_${_option}) + if(${_option} STREQUAL "CMAKE_TARGETS") + list(APPEND _setup_options "TARGETS") else() - conan_cmake_settings(settings ${ARGV}) - old_conan_cmake_install(SETTINGS ${settings} ${ARGV}) + list(APPEND _setup_options ${_option}) endif() - endif() - - if (NOT ARGUMENTS_NO_LOAD) - conan_load_buildinfo() - endif() - - if(ARGUMENTS_BASIC_SETUP) - foreach(_option CMAKE_TARGETS KEEP_RPATHS NO_OUTPUT_DIRS SKIP_STD) - if(ARGUMENTS_${_option}) - if(${_option} STREQUAL "CMAKE_TARGETS") - list(APPEND _setup_options "TARGETS") - else() - list(APPEND _setup_options ${_option}) - endif() - endif() - endforeach() - conan_basic_setup(${_setup_options}) - endif() + endif() + endforeach() + conan_basic_setup(${_setup_options}) + endif() endmacro() macro(conan_check) - # Checks conan availability in PATH - # Arguments REQUIRED, DETECT_QUIET and VERSION are optional - # Example usage: - # conan_check(VERSION 1.0.0 REQUIRED) - set(options REQUIRED DETECT_QUIET) - set(oneValueArgs VERSION) - cmake_parse_arguments(CONAN "${options}" "${oneValueArgs}" "" ${ARGN}) - if(NOT CONAN_DETECT_QUIET) - message(STATUS "Conan: checking conan executable") - endif() + # Checks conan availability in PATH Arguments REQUIRED, DETECT_QUIET and + # VERSION are optional Example usage: conan_check(VERSION 1.0.0 REQUIRED) + set(options REQUIRED DETECT_QUIET) + set(oneValueArgs VERSION) + cmake_parse_arguments(CONAN "${options}" "${oneValueArgs}" "" ${ARGN}) + if(NOT CONAN_DETECT_QUIET) + message(STATUS "Conan: checking conan executable") + endif() - find_program(CONAN_CMD conan) - if(NOT CONAN_CMD AND CONAN_REQUIRED) - message(FATAL_ERROR "Conan executable not found! Please install conan.") - endif() - if(NOT CONAN_DETECT_QUIET) - message(STATUS "Conan: Found program ${CONAN_CMD}") - endif() - execute_process(COMMAND ${CONAN_CMD} --version - RESULT_VARIABLE return_code - OUTPUT_VARIABLE CONAN_VERSION_OUTPUT - ERROR_VARIABLE CONAN_VERSION_OUTPUT) + find_program(CONAN_CMD conan) + if(NOT CONAN_CMD AND CONAN_REQUIRED) + message(FATAL_ERROR "Conan executable not found! Please install conan.") + endif() + if(NOT CONAN_DETECT_QUIET) + message(STATUS "Conan: Found program ${CONAN_CMD}") + endif() + execute_process( + COMMAND ${CONAN_CMD} --version + RESULT_VARIABLE return_code + OUTPUT_VARIABLE CONAN_VERSION_OUTPUT + ERROR_VARIABLE CONAN_VERSION_OUTPUT) - if(NOT "${return_code}" STREQUAL "0") - message(FATAL_ERROR "Conan --version failed='${return_code}'") - endif() - - if(NOT CONAN_DETECT_QUIET) - string(STRIP "${CONAN_VERSION_OUTPUT}" _CONAN_VERSION_OUTPUT) - message(STATUS "Conan: Version found ${_CONAN_VERSION_OUTPUT}") - endif() + if(NOT "${return_code}" STREQUAL "0") + message(FATAL_ERROR "Conan --version failed='${return_code}'") + endif() + + if(NOT CONAN_DETECT_QUIET) + string(STRIP "${CONAN_VERSION_OUTPUT}" _CONAN_VERSION_OUTPUT) + message(STATUS "Conan: Version found ${_CONAN_VERSION_OUTPUT}") + endif() - if(DEFINED CONAN_VERSION) - string(REGEX MATCH ".*Conan version ([0-9]+\\.[0-9]+\\.[0-9]+)" FOO - "${CONAN_VERSION_OUTPUT}") - if(${CMAKE_MATCH_1} VERSION_LESS ${CONAN_VERSION}) - message(FATAL_ERROR "Conan outdated. Installed: ${CMAKE_MATCH_1}, \ + if(DEFINED CONAN_VERSION) + string(REGEX MATCH ".*Conan version ([0-9]+\\.[0-9]+\\.[0-9]+)" FOO + "${CONAN_VERSION_OUTPUT}") + if(${CMAKE_MATCH_1} VERSION_LESS ${CONAN_VERSION}) + message( + FATAL_ERROR + "Conan outdated. Installed: ${CMAKE_MATCH_1}, \ required: ${CONAN_VERSION}. Consider updating via 'pip \ install conan==${CONAN_VERSION}'.") - endif() endif() + endif() endmacro() function(conan_add_remote) - # Adds a remote - # Arguments URL and NAME are required, INDEX, COMMAND and VERIFY_SSL are optional - # Example usage: - # conan_add_remote(NAME bincrafters INDEX 1 - # URL https://api.bintray.com/conan/bincrafters/public-conan - # VERIFY_SSL True) - set(oneValueArgs URL NAME INDEX COMMAND VERIFY_SSL) - cmake_parse_arguments(CONAN "" "${oneValueArgs}" "" ${ARGN}) - - if(DEFINED CONAN_INDEX) - set(CONAN_INDEX_ARG "-i ${CONAN_INDEX}") - endif() - if(DEFINED CONAN_COMMAND) - set(CONAN_CMD ${CONAN_COMMAND}) - else() - conan_check(REQUIRED DETECT_QUIET) - endif() - set(CONAN_VERIFY_SSL_ARG "True") - if(DEFINED CONAN_VERIFY_SSL) - set(CONAN_VERIFY_SSL_ARG ${CONAN_VERIFY_SSL}) - endif() - message(STATUS "Conan: Adding ${CONAN_NAME} remote repository (${CONAN_URL}) verify ssl (${CONAN_VERIFY_SSL_ARG})") - execute_process(COMMAND ${CONAN_CMD} remote add ${CONAN_NAME} ${CONAN_INDEX_ARG} -f ${CONAN_URL} ${CONAN_VERIFY_SSL_ARG} - RESULT_VARIABLE return_code) - if(NOT "${return_code}" STREQUAL "0") - message(FATAL_ERROR "Conan remote failed='${return_code}'") - endif() + # Adds a remote Arguments URL and NAME are required, INDEX, COMMAND and + # VERIFY_SSL are optional Example usage: conan_add_remote(NAME bincrafters + # INDEX 1 URL https://api.bintray.com/conan/bincrafters/public-conan + # VERIFY_SSL True) + set(oneValueArgs URL NAME INDEX COMMAND VERIFY_SSL) + cmake_parse_arguments(CONAN "" "${oneValueArgs}" "" ${ARGN}) + + if(DEFINED CONAN_INDEX) + set(CONAN_INDEX_ARG "-i ${CONAN_INDEX}") + endif() + if(DEFINED CONAN_COMMAND) + set(CONAN_CMD ${CONAN_COMMAND}) + else() + conan_check(REQUIRED DETECT_QUIET) + endif() + set(CONAN_VERIFY_SSL_ARG "True") + if(DEFINED CONAN_VERIFY_SSL) + set(CONAN_VERIFY_SSL_ARG ${CONAN_VERIFY_SSL}) + endif() + message( + STATUS + "Conan: Adding ${CONAN_NAME} remote repository (${CONAN_URL}) verify ssl (${CONAN_VERIFY_SSL_ARG})" + ) + execute_process( + COMMAND ${CONAN_CMD} remote add ${CONAN_NAME} ${CONAN_INDEX_ARG} -f + ${CONAN_URL} ${CONAN_VERIFY_SSL_ARG} RESULT_VARIABLE return_code) + if(NOT "${return_code}" STREQUAL "0") + message(FATAL_ERROR "Conan remote failed='${return_code}'") + endif() endfunction() macro(conan_config_install) - # install a full configuration from a local or remote zip file - # Argument ITEM is required, arguments TYPE, SOURCE, TARGET and VERIFY_SSL are optional - # Example usage: - # conan_config_install(ITEM https://github.com/conan-io/cmake-conan.git - # TYPE git SOURCE source-folder TARGET target-folder VERIFY_SSL false) - set(oneValueArgs ITEM TYPE SOURCE TARGET VERIFY_SSL) - set(multiValueArgs ARGS) - cmake_parse_arguments(CONAN "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - - find_program(CONAN_CMD conan) - if(NOT CONAN_CMD AND CONAN_REQUIRED) - message(FATAL_ERROR "Conan executable not found!") - endif() + # install a full configuration from a local or remote zip file Argument ITEM + # is required, arguments TYPE, SOURCE, TARGET and VERIFY_SSL are optional + # Example usage: conan_config_install(ITEM + # https://github.com/conan-io/cmake-conan.git TYPE git SOURCE source-folder + # TARGET target-folder VERIFY_SSL false) + set(oneValueArgs ITEM TYPE SOURCE TARGET VERIFY_SSL) + set(multiValueArgs ARGS) + cmake_parse_arguments(CONAN "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + find_program(CONAN_CMD conan) + if(NOT CONAN_CMD AND CONAN_REQUIRED) + message(FATAL_ERROR "Conan executable not found!") + endif() - if(DEFINED CONAN_VERIFY_SSL) - set(CONAN_VERIFY_SSL_ARG "--verify-ssl=${CONAN_VERIFY_SSL}") - endif() + if(DEFINED CONAN_VERIFY_SSL) + set(CONAN_VERIFY_SSL_ARG "--verify-ssl=${CONAN_VERIFY_SSL}") + endif() - if(DEFINED CONAN_TYPE) - set(CONAN_TYPE_ARG "--type=${CONAN_TYPE}") - endif() + if(DEFINED CONAN_TYPE) + set(CONAN_TYPE_ARG "--type=${CONAN_TYPE}") + endif() - if(DEFINED CONAN_ARGS) - set(CONAN_ARGS_ARGS "--args=\"${CONAN_ARGS}\"") - endif() + if(DEFINED CONAN_ARGS) + set(CONAN_ARGS_ARGS "--args=\"${CONAN_ARGS}\"") + endif() - if(DEFINED CONAN_SOURCE) - set(CONAN_SOURCE_ARGS "--source-folder=${CONAN_SOURCE}") - endif() + if(DEFINED CONAN_SOURCE) + set(CONAN_SOURCE_ARGS "--source-folder=${CONAN_SOURCE}") + endif() - if(DEFINED CONAN_TARGET) - set(CONAN_TARGET_ARGS "--target-folder=${CONAN_TARGET}") - endif() + if(DEFINED CONAN_TARGET) + set(CONAN_TARGET_ARGS "--target-folder=${CONAN_TARGET}") + endif() - set (CONAN_CONFIG_INSTALL_ARGS ${CONAN_VERIFY_SSL_ARG} - ${CONAN_TYPE_ARG} - ${CONAN_ARGS_ARGS} - ${CONAN_SOURCE_ARGS} - ${CONAN_TARGET_ARGS}) + set(CONAN_CONFIG_INSTALL_ARGS + ${CONAN_VERIFY_SSL_ARG} ${CONAN_TYPE_ARG} ${CONAN_ARGS_ARGS} + ${CONAN_SOURCE_ARGS} ${CONAN_TARGET_ARGS}) - message(STATUS "Conan: Installing config from ${CONAN_ITEM}") - execute_process(COMMAND ${CONAN_CMD} config install ${CONAN_ITEM} ${CONAN_CONFIG_INSTALL_ARGS} - RESULT_VARIABLE return_code) + message(STATUS "Conan: Installing config from ${CONAN_ITEM}") + execute_process( + COMMAND ${CONAN_CMD} config install ${CONAN_ITEM} + ${CONAN_CONFIG_INSTALL_ARGS} RESULT_VARIABLE return_code) if(NOT "${return_code}" STREQUAL "0") message(FATAL_ERROR "Conan config failed='${return_code}'") endif()