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/build/cmut__build__asan.cmake b/build/cmut__build__asan.cmake new file mode 100644 index 0000000..cf4d093 --- /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 Coverage) + 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/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() 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 diff --git a/project/cmut__project__setup_library.cmake b/project/cmut__project__setup_library.cmake index 7131b1b..b94d86d 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} ) @@ -46,8 +47,8 @@ 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$") - cmut__target__generate_export_header( ${target} "${target}/export.h" ) + 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() endif() 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) 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}