Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(config): add config/cmut__config__option_no_autodetect so that conan profile can be fully applied if needed #10

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
35 changes: 35 additions & 0 deletions build/cmut__build__asan.cmake
Original file line number Diff line number Diff line change
@@ -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()
1 change: 1 addition & 0 deletions cmut__build.cmake
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
1 change: 1 addition & 0 deletions cmut__config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
12 changes: 9 additions & 3 deletions conan/build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}
"
Expand All @@ -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}
Expand All @@ -168,7 +174,7 @@ conan_cmake_install(
${settings_opt}
${options_opt}
${build_type_opt}
SETTINGS ${autodetected_settings}
${extra_settings_opt}
)

endfunction()
15 changes: 15 additions & 0 deletions config/cmut__config__option_no_autodetect.cmake
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 1 addition & 1 deletion find/FindStdFilesystem.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions project/cmut__project__setup_library.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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} )
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion qtcreator/cmut__qtcreator__import_qml.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 15 additions & 3 deletions target/cmut__target__generate_export_header.cmake
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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}
Expand Down