From 4cdf30b90119ed0a12bda919d3bc885cda15592b Mon Sep 17 00:00:00 2001 From: Adrien LENGLET Date: Mon, 6 Mar 2023 12:13:13 +0100 Subject: [PATCH 1/6] fix(config): add config/cmut__config__option_no_autodetect so that conan profile can be fully applied if needed --- cmut__config.cmake | 1 + conan/build.cmake | 12 +++++++++--- config/cmut__config__option_no_autodetect.cmake | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 config/cmut__config__option_no_autodetect.cmake diff --git a/cmut__config.cmake b/cmut__config.cmake index 17c6108..9f71628 100644 --- a/cmut__config.cmake +++ b/cmut__config.cmake @@ -11,5 +11,6 @@ include("${CMAKE_CURRENT_LIST_DIR}/config/cmut__config__option_clang_tidy.cmake" include("${CMAKE_CURRENT_LIST_DIR}/config/cmut__config__option_cppcheck.cmake") include("${CMAKE_CURRENT_LIST_DIR}/config/cmut__config__option_developer_mode.cmake") include("${CMAKE_CURRENT_LIST_DIR}/config/cmut__config__option_include_what_you_use.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/config/cmut__config__option_no_autodetect.cmake") include("${CMAKE_CURRENT_LIST_DIR}/config/cmut__config__print_info.cmake") include("${CMAKE_CURRENT_LIST_DIR}/config/cmut__config__resolve_install_prefix.cmake") diff --git a/conan/build.cmake b/conan/build.cmake index 1b48adb..dfdb96a 100644 --- a/conan/build.cmake +++ b/conan/build.cmake @@ -148,7 +148,12 @@ function( cmut__conan__build ) __cmut__conan__select_opt(settings_opt "${settings_opt}" "${settings_build_opt}" "${settings_host_opt}") __cmut__conan__select_opt(options_opt "${options_opt}" "${options_build_opt}" "${options_host_opt}") - conan_cmake_autodetect(autodetected_settings) + if (DEFINED CMUT__CONFIG__OPTION_NO_AUTODETECT AND CMUT__CONFIG__OPTION_NO_AUTODETECT) + set(extra_settings_opt "") + else () + conan_cmake_autodetect(autodetected_settings) + set(extra_settings_opt SETTINGS ${autodetected_settings}) + endif () cmut__log__debug(${CMAKE_CURRENT_FUNCTION} " @@ -159,7 +164,8 @@ conan_cmake_install( ${settings_opt} ${options_opt} ${build_type_opt} - SETTINGS ${autodetected_settings})" + ${extra_settings_opt} + )" ) conan_cmake_install( PATH_OR_REFERENCE ${ARG_CONANFILE} @@ -168,7 +174,7 @@ conan_cmake_install( ${settings_opt} ${options_opt} ${build_type_opt} - SETTINGS ${autodetected_settings} + ${extra_settings_opt} ) endfunction() diff --git a/config/cmut__config__option_no_autodetect.cmake b/config/cmut__config__option_no_autodetect.cmake new file mode 100644 index 0000000..7e1429e --- /dev/null +++ b/config/cmut__config__option_no_autodetect.cmake @@ -0,0 +1,15 @@ + + +include(${CMAKE_CURRENT_LIST_DIR}/../utils/cmut__utils__header_guard.cmake) +cmut__utils__define_header_guard() + +# This option controls the autodetect override. +# When ON, conan_cmake_autodetect doesn't get run. +# While using conan it does guarantee only the configuration from the current profile is being used. +function(cmut__config__option_no_autodetect defaultValue) + + option(CMUT__CONFIG__NO_AUTODETECT "Set to ON not to run conan_cmake_autodetect (potentially overriding profile)" ${defaultValue}) + cmut__log__info("cmut__config" "No autodetect is ${CMUT__CONFIG__NO_AUTODETECT}") + set(CMUT__CONFIG__OPTION_NO_AUTODETECT ${CMUT__CONFIG__NO_AUTODETECT} PARENT_SCOPE) + +endfunction() From 88e1c243bfe95ea6021fccac381f2ec7c9569f75 Mon Sep 17 00:00:00 2001 From: Adrien LENGLET Date: Thu, 13 Apr 2023 11:32:05 +0200 Subject: [PATCH 2/6] fix(find): use C++20 when looking for std::filesystem --- find/FindStdFilesystem.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/find/FindStdFilesystem.cmake b/find/FindStdFilesystem.cmake index 6c1065b..caf8501 100644 --- a/find/FindStdFilesystem.cmake +++ b/find/FindStdFilesystem.cmake @@ -2,7 +2,7 @@ set(_find_std_filesystem_src ${CMAKE_CURRENT_LIST_DIR}/FindStdFilesystem.cpp) function(try_compile_std_filesystem result library) - set(compile_arg CXX_STANDARD 17) + set(compile_arg CXX_STANDARD 20) if(library) list( APPEND From 0e0400c1be8f8b6f617851d48dffed388ae90a28 Mon Sep 17 00:00:00 2001 From: Adrien LENGLET Date: Thu, 27 Apr 2023 10:51:38 +0200 Subject: [PATCH 3/6] -Add Asan profile --- build/cmut__build__asan.cmake | 35 +++++++++++++++++++++ cmut__build.cmake | 1 + qtcreator/cmut__qtcreator__import_qml.cmake | 2 +- 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 build/cmut__build__asan.cmake diff --git a/build/cmut__build__asan.cmake b/build/cmut__build__asan.cmake new file mode 100644 index 0000000..a4f9751 --- /dev/null +++ b/build/cmut__build__asan.cmake @@ -0,0 +1,35 @@ + +function(cmut__build__add_asan_profile) + + get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + + if(isMultiConfig) + if(NOT "Asan" IN_LIST CMAKE_CONFIGURATION_TYPES) + list(APPEND CMAKE_CONFIGURATION_TYPES Asan) + endif() + else() + set(allowedBuildTypes Asan Debug Release RelWithDebInfo MinSizeRel) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${allowedBuildTypes}") + + if(CMAKE_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE IN_LIST allowedBuildTypes) + message(FATAL_ERROR "Invalid build type: ${CMAKE_BUILD_TYPE}") + endif() + endif() + + set(CMAKE_C_FLAGS_ASAN + "${CMAKE_C_FLAGS_DEBUG} -g -fsanitize=address -fno-omit-frame-pointer" CACHE STRING + "Flags used by the C compiler for Asan build type or configuration." FORCE) + + set(CMAKE_CXX_FLAGS_ASAN + "${CMAKE_CXX_FLAGS_DEBUG} -g -fsanitize=address -fno-omit-frame-pointer" CACHE STRING + "Flags used by the C++ compiler for Asan build type or configuration." FORCE) + + set(CMAKE_EXE_LINKER_FLAGS_ASAN + "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -g -fsanitize=address" CACHE STRING + "Linker flags to be used to create executables for Asan build type." FORCE) + + set(CMAKE_SHARED_LINKER_FLAGS_ASAN + "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -g -fsanitize=address" CACHE STRING + "Linker lags to be used to create shared libraries for Asan build type." FORCE) + +endfunction() diff --git a/cmut__build.cmake b/cmut__build.cmake index 54bc143..8effe26 100644 --- a/cmut__build.cmake +++ b/cmut__build.cmake @@ -1,4 +1,5 @@ +include("${CMAKE_CURRENT_LIST_DIR}/build/cmut__build__asan.cmake") include("${CMAKE_CURRENT_LIST_DIR}/build/cmut__build__coverage.cmake") include("${CMAKE_CURRENT_LIST_DIR}/build/cmut__build__define_output_dir.cmake") include("${CMAKE_CURRENT_LIST_DIR}/build/cmut__build__enable_color_with_ninja.cmake") diff --git a/qtcreator/cmut__qtcreator__import_qml.cmake b/qtcreator/cmut__qtcreator__import_qml.cmake index 6eee3e2..61655ac 100644 --- a/qtcreator/cmut__qtcreator__import_qml.cmake +++ b/qtcreator/cmut__qtcreator__import_qml.cmake @@ -65,7 +65,7 @@ function(__cmut__qtcreator__get_dependency_install_directory dependency_install_ if( NOT _dependency_location ) cmut_error("[cmut][qtcreator][import_qml] - We can't find your dependency location. - Verify your build type (Release, Debug, Coverage)") + Verify your build type (Release, Debug, Asan, Coverage)") endif() get_filename_component(_dependency_directory ${_dependency_location} DIRECTORY) From e03370a152f18fc15ca777521ce81201b4f8b958 Mon Sep 17 00:00:00 2001 From: Adrien LENGLET Date: Fri, 28 Apr 2023 13:55:39 +0200 Subject: [PATCH 4/6] -Allow build type Coverage for asan helper --- build/cmut__build__asan.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/cmut__build__asan.cmake b/build/cmut__build__asan.cmake index a4f9751..cf4d093 100644 --- a/build/cmut__build__asan.cmake +++ b/build/cmut__build__asan.cmake @@ -8,7 +8,7 @@ function(cmut__build__add_asan_profile) list(APPEND CMAKE_CONFIGURATION_TYPES Asan) endif() else() - set(allowedBuildTypes Asan Debug Release RelWithDebInfo MinSizeRel) + set(allowedBuildTypes Asan Debug Release Coverage) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${allowedBuildTypes}") if(CMAKE_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE IN_LIST allowedBuildTypes) From 6d54330c42a5d6d6626a5eec4cff046742d51804 Mon Sep 17 00:00:00 2001 From: Adrien LENGLET Date: Thu, 4 May 2023 11:47:25 +0200 Subject: [PATCH 5/6] -Allow for target export header located with a different name --- project/cmut__project__setup_library.cmake | 5 +++-- .../cmut__target__generate_export_header.cmake | 18 +++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/project/cmut__project__setup_library.cmake b/project/cmut__project__setup_library.cmake index 7131b1b..cb6fdfd 100644 --- a/project/cmut__project__setup_library.cmake +++ b/project/cmut__project__setup_library.cmake @@ -24,12 +24,13 @@ function(cmut__project__setup_library target) cmut__project__setup_library ARG "CXX_EXTENSIONS;CXX_STANDARD_REQUIRED" - "DEBUG_POSTFIX;OUTPUT_PREFIX;VERSION;WINNT_VERSION" + "NAMESPACE;DEBUG_POSTFIX;OUTPUT_PREFIX;VERSION;WINNT_VERSION" "CXX_FEATURES" ${ARGN} ) + cmut__utils__set_default_argument( ARG_NAMESPACE "${target}" ) cmut__utils__set_default_argument( ARG_DEBUG_POSTFIX "d" ) cmut__utils__set_default_argument( ARG_OUTPUT_PREFIX "${PROJECT_BINARY_DIR}" ) cmut__utils__set_default_argument( ARG_VERSION ${PROJECT_VERSION} ) @@ -47,7 +48,7 @@ function(cmut__project__setup_library target) cmut__target__define_debug_postfix( ${target} ${ARG_DEBUG_POSTFIX} ) cmut__target__define_output_directory( ${target} PREFIX "${ARG_OUTPUT_PREFIX}" ) if( target_type MATCHES "^(SHARED|STATIC)_LIBRARY$") - cmut__target__generate_export_header( ${target} "${target}/export.h" ) + cmut__target__generate_export_header( ${target} "${ARG_NAMESPACE}/export.h" ${ARG_NAMESPACE} ) cmut__target__set_library_version( ${target} ${ARG_VERSION} ) endif() endif() diff --git a/target/cmut__target__generate_export_header.cmake b/target/cmut__target__generate_export_header.cmake index 0b77b1a..7171785 100644 --- a/target/cmut__target__generate_export_header.cmake +++ b/target/cmut__target__generate_export_header.cmake @@ -1,6 +1,11 @@ function(cmut__target__generate_export_header target) + if (ARGC GREATER 1) + set(export_macro_name "${ARGV2}_export") + string(TOUPPER "${export_macro_name}" export_macro_name) + endif() + if(ARGC GREATER 0) set(export_filename "${ARGV1}") else() @@ -12,9 +17,16 @@ function(cmut__target__generate_export_header target) cmut__target__get_generated_header_output_directory( output_dir ) include(GenerateExportHeader) - generate_export_header( ${target} - EXPORT_FILE_NAME "${output_dir}/${export_filename}" - ) + if (DEFINED export_macro_name) + generate_export_header( ${target} + EXPORT_FILE_NAME "${output_dir}/${export_filename}" + EXPORT_MACRO_NAME ${export_macro_name} + ) + else() + generate_export_header( ${target} + EXPORT_FILE_NAME "${output_dir}/${export_filename}" + ) + endif() cmut__target__get_property_prefix(prefix ${target}) set_target_properties( ${target} From 60670753e9268754edeb2749050a933487771ca0 Mon Sep 17 00:00:00 2001 From: Adrien LENGLET Date: Thu, 22 Jun 2023 15:15:40 +0200 Subject: [PATCH 6/6] Bump CMake required version and extend project setup to OBJECT libraries --- CMakeLists.txt | 4 ++-- project/cmut__project__setup_library.cmake | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 51d6803..5635f75 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,8 @@ ##--------------------------------------------------------------------------------------------------------------------## # define minimum cmake version ##--------------------------------------------------------------------------------------------------------------------## -cmake_minimum_required(VERSION 3.12.0) -cmake_policy(VERSION 3.12) +cmake_minimum_required(VERSION 3.22.1) +cmake_policy(VERSION 3.22.1) include(cmut.cmake) diff --git a/project/cmut__project__setup_library.cmake b/project/cmut__project__setup_library.cmake index cb6fdfd..b94d86d 100644 --- a/project/cmut__project__setup_library.cmake +++ b/project/cmut__project__setup_library.cmake @@ -47,7 +47,7 @@ function(cmut__project__setup_library target) if( NOT target_type STREQUAL INTERFACE_LIBRARY ) cmut__target__define_debug_postfix( ${target} ${ARG_DEBUG_POSTFIX} ) cmut__target__define_output_directory( ${target} PREFIX "${ARG_OUTPUT_PREFIX}" ) - if( target_type MATCHES "^(SHARED|STATIC)_LIBRARY$") + if( target_type MATCHES "^(SHARED|STATIC|OBJECT)_LIBRARY$") cmut__target__generate_export_header( ${target} "${ARG_NAMESPACE}/export.h" ${ARG_NAMESPACE} ) cmut__target__set_library_version( ${target} ${ARG_VERSION} ) endif()