2022-06-11 01:06:08 +02:00
|
|
|
cmake_minimum_required(VERSION 3.20)
|
2022-06-10 20:13:29 +02:00
|
|
|
|
2020-01-21 10:11:08 +01:00
|
|
|
set(CLANG_PATH "" CACHE PATH "Path to Clang Toolset (if not in environment)")
|
|
|
|
|
|
2022-06-11 01:06:08 +02:00
|
|
|
function(json_escape_string)
|
2020-04-18 16:17:15 +02:00
|
|
|
cmake_parse_arguments(
|
|
|
|
|
PARSE_ARGV 0
|
|
|
|
|
_ARGS
|
|
|
|
|
""
|
|
|
|
|
"OUTPUT;INPUT"
|
|
|
|
|
""
|
|
|
|
|
)
|
|
|
|
|
|
2022-06-11 01:06:08 +02:00
|
|
|
set(_tmp "${_ARGS_INPUT}")
|
|
|
|
|
string(REPLACE "\\" "\\\\" _tmp "${_tmp}")
|
|
|
|
|
string(REPLACE "\"" "\\\"" _tmp "${_tmp}")
|
|
|
|
|
set(${_ARGS_OUTPUT} "${_tmp}" PARENT_SCOPE)
|
2020-04-18 16:17:15 +02:00
|
|
|
endfunction()
|
|
|
|
|
|
2022-06-11 01:06:08 +02:00
|
|
|
function(get_target_include_directories)
|
|
|
|
|
unset(_ARGS)
|
2020-04-18 16:17:15 +02:00
|
|
|
cmake_parse_arguments(
|
|
|
|
|
PARSE_ARGV 0
|
|
|
|
|
_ARGS
|
2022-06-11 01:06:08 +02:00
|
|
|
"INTERFACE"
|
|
|
|
|
"TARGET;OUTPUT"
|
|
|
|
|
"IGNORE"
|
2020-04-18 16:17:15 +02:00
|
|
|
)
|
|
|
|
|
|
2022-06-11 01:06:08 +02:00
|
|
|
# FIXME: For some reason, CMake claims that the target we depend on depends on the target we are.
|
|
|
|
|
# Might be something broken with LINK_LIBRARIES or similar?
|
|
|
|
|
|
|
|
|
|
set(out "")
|
|
|
|
|
set(ignore "${_ARGS_IGNORE}")
|
|
|
|
|
list(APPEND ignore "${_ARGS_TARGET}")
|
|
|
|
|
|
|
|
|
|
set(gtid "")
|
|
|
|
|
if(_ARGS_INTERFACE)
|
|
|
|
|
get_property(gtid TARGET ${current_target} PROPERTY INTERFACE_LINK_LIBRARIES)
|
|
|
|
|
else()
|
|
|
|
|
get_property(gtid TARGET ${current_target} PROPERTY LINK_LIBRARIES)
|
2020-04-18 16:17:15 +02:00
|
|
|
endif()
|
2022-06-11 01:06:08 +02:00
|
|
|
foreach(_tmp ${gtid})
|
|
|
|
|
list(APPEND ignore "${_tmp}")
|
|
|
|
|
if((NOT "${_tmp}" IN_LIST _ARGS_IGNORE) AND (NOT "${_tmp}" STREQUAL "${_ARGS_TARGET}") AND (TARGET "${_tmp}"))
|
|
|
|
|
get_target_include_directories(INTERFACE OUTPUT _tmp2 TARGET "${_tmp}" IGNORE ${ignore})
|
|
|
|
|
foreach(_tmp3 ${_tmp2})
|
|
|
|
|
list(APPEND out "${_tmp3}")
|
|
|
|
|
endforeach()
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
|
|
set(gtid_source_dir "")
|
|
|
|
|
get_property(gtid_source_dir TARGET ${_ARGS_TARGET} PROPERTY SOURCE_DIR)
|
|
|
|
|
|
|
|
|
|
set(gtid "")
|
|
|
|
|
if(_ARGS_INTERFACE)
|
|
|
|
|
get_property(gtid TARGET ${_ARGS_TARGET} PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
|
|
|
|
|
else()
|
|
|
|
|
get_property(gtid TARGET ${_ARGS_TARGET} PROPERTY INCLUDE_DIRECTORIES)
|
|
|
|
|
endif()
|
|
|
|
|
foreach(_tmp ${gtid})
|
|
|
|
|
cmake_path(ABSOLUTE_PATH _tmp BASE_DIRECTORY "${gtid_source_dir}")
|
|
|
|
|
list(APPEND out "${_tmp}")
|
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
|
|
if(_ARGS_INTERFACE)
|
|
|
|
|
set(gtid "")
|
|
|
|
|
get_property(gtid TARGET ${_ARGS_TARGET} PROPERTY INTERFACE_SYSTEM_INCLUDE_DIRECTORIES)
|
|
|
|
|
foreach(_tmp ${gtid})
|
|
|
|
|
cmake_path(ABSOLUTE_PATH _tmp BASE_DIRECTORY "${gtid_source_dir}")
|
|
|
|
|
list(APPEND out "${_tmp}")
|
|
|
|
|
endforeach()
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
set(${_ARGS_OUTPUT} "${out}" PARENT_SCOPE)
|
2020-04-18 16:17:15 +02:00
|
|
|
endfunction()
|
|
|
|
|
|
2022-06-11 01:06:08 +02:00
|
|
|
function(get_target_definitions)
|
|
|
|
|
unset(_ARGS)
|
2020-04-18 16:17:15 +02:00
|
|
|
cmake_parse_arguments(
|
|
|
|
|
PARSE_ARGV 0
|
|
|
|
|
_ARGS
|
2022-06-11 01:06:08 +02:00
|
|
|
"INTERFACE"
|
|
|
|
|
"TARGET;OUTPUT"
|
|
|
|
|
"IGNORE"
|
2020-04-18 16:17:15 +02:00
|
|
|
)
|
|
|
|
|
|
2022-06-11 01:06:08 +02:00
|
|
|
# FIXME: For some reason, CMake claims that the target we depend on depends on the target we are.
|
|
|
|
|
# Might be something broken with LINK_LIBRARIES or similar?
|
|
|
|
|
|
|
|
|
|
set(out "")
|
|
|
|
|
set(ignore "${_ARGS_IGNORE}")
|
|
|
|
|
list(APPEND ignore "${_ARGS_TARGET}")
|
|
|
|
|
|
|
|
|
|
set(gtd "")
|
|
|
|
|
if(_ARGS_INTERFACE)
|
|
|
|
|
get_property(gtd TARGET ${current_target} PROPERTY INTERFACE_LINK_LIBRARIES)
|
|
|
|
|
else()
|
|
|
|
|
get_property(gtd TARGET ${current_target} PROPERTY LINK_LIBRARIES)
|
|
|
|
|
endif()
|
|
|
|
|
foreach(_tmp ${gtd})
|
|
|
|
|
list(APPEND ignore "${_tmp}")
|
|
|
|
|
if((NOT "${_tmp}" IN_LIST _ARGS_IGNORE) AND (NOT "${_tmp}" STREQUAL "${_ARGS_TARGET}") AND (TARGET "${_tmp}"))
|
|
|
|
|
get_target_definitions(INTERFACE OUTPUT _tmp2 TARGET "${_tmp}" IGNORE ${ignore})
|
|
|
|
|
foreach(_tmp3 ${_tmp2})
|
|
|
|
|
list(APPEND out "${_tmp3}")
|
|
|
|
|
endforeach()
|
2020-04-18 16:17:15 +02:00
|
|
|
endif()
|
2022-06-11 01:06:08 +02:00
|
|
|
endforeach()
|
|
|
|
|
|
|
|
|
|
set(gtid "")
|
|
|
|
|
if(_ARGS_INTERFACES)
|
|
|
|
|
get_property(gtid TARGET ${_ARGS_TARGET} PROPERTY INTERFACE_COMPILE_DEFINITIONS)
|
|
|
|
|
else()
|
|
|
|
|
get_property(gtid TARGET ${_ARGS_TARGET} PROPERTY COMPILE_DEFINITIONS)
|
2020-04-18 16:17:15 +02:00
|
|
|
endif()
|
2022-06-11 01:06:08 +02:00
|
|
|
foreach(_tmp ${gtid})
|
|
|
|
|
list(APPEND out "${_tmp}")
|
|
|
|
|
endforeach()
|
2020-04-18 16:17:15 +02:00
|
|
|
|
2022-06-11 01:06:08 +02:00
|
|
|
set(${_ARGS_OUTPUT} "${out}" PARENT_SCOPE)
|
2020-04-18 16:17:15 +02:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
|
|
function(generate_compile_commands_json)
|
|
|
|
|
cmake_parse_arguments(
|
|
|
|
|
PARSE_ARGV 0
|
|
|
|
|
_ARGS
|
|
|
|
|
""
|
|
|
|
|
"REGEX"
|
|
|
|
|
"TARGETS"
|
|
|
|
|
)
|
2022-06-11 01:06:08 +02:00
|
|
|
if(NOT _ARGS_REGEX)
|
|
|
|
|
set(_ARGS_REGEX "\.(h|hpp|c|cpp)$")
|
|
|
|
|
endif()
|
2020-04-18 16:17:15 +02:00
|
|
|
|
2022-06-11 01:06:08 +02:00
|
|
|
# If the generator itself can create the compile_commands.json file, don't create our own.
|
|
|
|
|
set(cc_generators
|
|
|
|
|
"Borland Makefiles"
|
|
|
|
|
"MSYS Makefiles"
|
|
|
|
|
"MinGW Makefiles"
|
|
|
|
|
"NMake Makefiles"
|
|
|
|
|
"NMake Makefiles JOM"
|
|
|
|
|
"Unix Makefiles"
|
|
|
|
|
"Watcom WMake"
|
|
|
|
|
"Ninja"
|
|
|
|
|
"Ninja Multi-Config"
|
|
|
|
|
)
|
|
|
|
|
if(CMAKE_GENERATOR IN_LIST cc_generators)
|
2022-06-11 04:09:33 +02:00
|
|
|
foreach(current_target ${_ARGS_TARGETS})
|
2022-06-11 02:38:18 +02:00
|
|
|
set_target_properties(${current_target} PROPERTIES
|
2022-06-11 01:06:08 +02:00
|
|
|
CMAKE_EXPORT_COMPILE_COMMANDS ON
|
|
|
|
|
)
|
|
|
|
|
endforeach()
|
|
|
|
|
return()
|
2020-04-18 16:17:15 +02:00
|
|
|
endif()
|
|
|
|
|
|
2022-06-11 01:06:08 +02:00
|
|
|
# Is this generator able to have multiple configurations?
|
|
|
|
|
get_property(cc_multiconfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
|
|
|
|
|
if(NOT cc_multiconfig)
|
|
|
|
|
set(cc_configurations ${CMAKE_BUILD_TYPE})
|
|
|
|
|
else()
|
|
|
|
|
set(cc_configurations ${CMAKE_CONFIGURATION_TYPES})
|
2020-04-18 16:17:15 +02:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
|
2022-06-11 01:06:08 +02:00
|
|
|
foreach(current_target ${_ARGS_TARGETS})
|
|
|
|
|
# For each target, generate a compile_commands.json file with all files.
|
|
|
|
|
|
|
|
|
|
# Get source and binary directory.
|
|
|
|
|
get_property(cc_tgt_source_dir TARGET ${current_target} PROPERTY SOURCE_DIR)
|
|
|
|
|
get_filename_component(cc_tgt_source_dir "${cc_tgt_source_dir}" ABSOLUTE)
|
|
|
|
|
get_property(cc_tgt_binary_dir TARGET ${current_target} PROPERTY BINARY_DIR)
|
|
|
|
|
get_filename_component(cc_tgt_binary_dir "${cc_tgt_binary_dir}" ABSOLUTE)
|
|
|
|
|
|
|
|
|
|
# C++ Standard
|
|
|
|
|
get_property(cc_tgt_std_CXX TARGET ${current_target} PROPERTY CXX_STANDARD)
|
|
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
|
|
|
|
if(cc_tgt_std_CXX EQUAL 23)
|
|
|
|
|
set(cc_tgt_std_CXX "/std:c++latest")
|
|
|
|
|
elseif(cc_tgt_std_CXX EQUAL 20)
|
|
|
|
|
set(cc_tgt_std_CXX "/std:c++20")
|
|
|
|
|
elseif(cc_tgt_std_CXX EQUAL 17)
|
|
|
|
|
set(cc_tgt_std_CXX "/std:c++17")
|
|
|
|
|
elseif(cc_tgt_std_CXX EQUAL 14)
|
|
|
|
|
set(cc_tgt_std_CXX "/std:c++14")
|
|
|
|
|
else()
|
|
|
|
|
set(cc_tgt_std_CXX "")
|
|
|
|
|
endif()
|
|
|
|
|
else()
|
|
|
|
|
if(cc_tgt_std_CXX EQUAL 23)
|
|
|
|
|
set(cc_tgt_std_CXX "-std=c++23")
|
|
|
|
|
elseif(cc_tgt_std_CXX EQUAL 20)
|
|
|
|
|
set(cc_tgt_std_CXX "-std=c++20")
|
|
|
|
|
elseif(cc_tgt_std_CXX EQUAL 17)
|
|
|
|
|
set(cc_tgt_std_CXX "-std=c++17")
|
|
|
|
|
elseif(cc_tgt_std_CXX EQUAL 14)
|
|
|
|
|
set(cc_tgt_std_CXX "-std=c++14")
|
|
|
|
|
elseif(cc_tgt_std_CXX EQUAL 11)
|
|
|
|
|
set(cc_tgt_std_CXX "-std=c++11")
|
|
|
|
|
elseif(cc_tgt_std_CXX EQUAL 98)
|
|
|
|
|
set(cc_tgt_std_CXX "-std=c++98")
|
|
|
|
|
else()
|
|
|
|
|
set(cc_tgt_std_CXX "")
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
2020-04-18 16:17:15 +02:00
|
|
|
|
2022-06-11 01:06:08 +02:00
|
|
|
# C standard
|
|
|
|
|
get_property(cc_tgt_std_C TARGET ${current_target} PROPERTY C_STANDARD)
|
|
|
|
|
if(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
|
|
|
|
|
if(cc_tgt_std_C EQUAL 17)
|
|
|
|
|
set(cc_tgt_std_C "/std:c17")
|
|
|
|
|
elseif(cc_tgt_std_C EQUAL 11)
|
|
|
|
|
set(cc_tgt_std_C "/std:c11")
|
|
|
|
|
else()
|
|
|
|
|
set(cc_tgt_std_C "")
|
|
|
|
|
endif()
|
|
|
|
|
else()
|
|
|
|
|
if(cc_tgt_std_C EQUAL 23)
|
|
|
|
|
set(cc_tgt_std_C "-std=c2x")
|
|
|
|
|
elseif(cc_tgt_std_C EQUAL 17)
|
|
|
|
|
set(cc_tgt_std_C "-std=c17")
|
|
|
|
|
elseif(cc_tgt_std_C EQUAL 11)
|
|
|
|
|
set(cc_tgt_std_C "-std=c11")
|
|
|
|
|
elseif(cc_tgt_std_C EQUAL 99)
|
|
|
|
|
set(cc_tgt_std_C "-std=c99")
|
|
|
|
|
elseif(cc_tgt_std_C EQUAL 90)
|
|
|
|
|
set(cc_tgt_std_C "-std=c90")
|
|
|
|
|
else()
|
|
|
|
|
set(cc_tgt_std_C "")
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
2020-04-18 16:17:15 +02:00
|
|
|
|
2022-06-11 01:06:08 +02:00
|
|
|
# Include Directories
|
|
|
|
|
get_property(_tmp TARGET ${current_target} PROPERTY INCLUDE_DIRECTORIES)
|
|
|
|
|
foreach(_tmp2 ${_tmp})
|
|
|
|
|
cmake_path(ABSOLUTE_PATH _tmp2 BASE_DIRECTORY "${cc_tgt_source_dir}")
|
|
|
|
|
list(APPEND cc_tgt_includes "${_tmp2}")
|
2020-04-18 16:17:15 +02:00
|
|
|
endforeach()
|
2022-06-11 01:06:08 +02:00
|
|
|
get_target_include_directories(OUTPUT _tmp TARGET ${current_target})
|
|
|
|
|
|
|
|
|
|
# Definitions, Options
|
|
|
|
|
get_target_definitions(OUTPUT cc_tgt_definitions TARGET ${current_target})
|
|
|
|
|
get_property(cc_tgt_options TARGET ${current_target} PROPERTY COMPILE_OPTIONS)
|
|
|
|
|
|
|
|
|
|
# Interface stuff from link dependencies
|
|
|
|
|
get_property(cc_tgt_depends TARGET ${current_target} PROPERTY LINK_LIBRARIES)
|
|
|
|
|
foreach(_tmp3 ${cc_tgt_depends})
|
|
|
|
|
if(TARGET ${_tmp3})
|
|
|
|
|
# - Interface Include Directories
|
|
|
|
|
get_property(_tmp TARGET ${_tmp3} PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
|
|
|
|
|
foreach(_tmp2 ${_tmp})
|
|
|
|
|
cmake_path(ABSOLUTE_PATH _tmp2 BASE_DIRECTORY "${cc_tgt_source_dir}")
|
|
|
|
|
list(APPEND cc_tgt_includes "${_tmp2}")
|
|
|
|
|
endforeach()
|
|
|
|
|
get_property(_tmp TARGET ${_tmp3} PROPERTY INTERFACE_SYSTEM_INCLUDE_DIRECTORIES)
|
|
|
|
|
foreach(_tmp2 ${_tmp})
|
|
|
|
|
cmake_path(ABSOLUTE_PATH _tmp2 BASE_DIRECTORY "${cc_tgt_source_dir}")
|
|
|
|
|
list(APPEND cc_tgt_includes "${_tmp2}")
|
|
|
|
|
endforeach()
|
2020-04-18 16:17:15 +02:00
|
|
|
|
2022-06-11 01:06:08 +02:00
|
|
|
# - Interface Defines, Options
|
|
|
|
|
get_property(_tmp TARGET ${current_target} PROPERTY INTERFACE_COMPILE_DEFINITIONS)
|
|
|
|
|
foreach(_tmp2 ${_tmp})
|
|
|
|
|
list(APPEND cc_tgt_definitions "${_tmp2}")
|
|
|
|
|
endforeach()
|
|
|
|
|
get_property(_tmp TARGET ${current_target} PROPERTY INTERFACE_COMPILE_OPTIONS)
|
|
|
|
|
foreach(_tmp2 ${_tmp})
|
|
|
|
|
list(APPEND cc_tgt_options "${_tmp2}")
|
|
|
|
|
endforeach()
|
|
|
|
|
endif()
|
2020-04-18 16:17:15 +02:00
|
|
|
endforeach()
|
2022-06-11 01:06:08 +02:00
|
|
|
|
|
|
|
|
# Figure out source files for this target.
|
|
|
|
|
set(cc_tgt_sources "")
|
|
|
|
|
get_target_property(_tmp ${current_target} SOURCES)
|
|
|
|
|
foreach(_tmp2 ${_tmp})
|
|
|
|
|
cmake_path(ABSOLUTE_PATH _tmp2 BASE_DIRECTORY "${cc_tgt_source_dir}")
|
|
|
|
|
list(APPEND cc_tgt_sources "${_tmp2}")
|
|
|
|
|
endforeach()
|
|
|
|
|
list(FILTER cc_tgt_sources INCLUDE REGEX "${_ARGS_REGEX}")
|
|
|
|
|
|
|
|
|
|
# Generate a unique compile_commands.json.
|
|
|
|
|
set(cc_json_content "")
|
|
|
|
|
string(APPEND cc_json_content "[\n")
|
|
|
|
|
|
|
|
|
|
# Write entries for each file.
|
|
|
|
|
foreach(current_source ${cc_tgt_sources})
|
|
|
|
|
# Find the real location of the source file.
|
|
|
|
|
get_property(cc_src_location SOURCE ${current_source} TARGET_DIRECTORY ${current_target} PROPERTY LOCATION)
|
|
|
|
|
cmake_path(ABSOLUTE_PATH cc_src_location BASE_DIRECTORY "${cc_tgt_source_dir}")
|
|
|
|
|
|
|
|
|
|
# Try and figure out the language used.
|
|
|
|
|
get_property(cc_src_language SOURCE ${current_source} TARGET_DIRECTORY ${current_target} PROPERTY LANGUAGE)
|
|
|
|
|
if("${cc_src_language}" STREQUAL "")
|
|
|
|
|
get_filename_component(_tmp "${current_source}" EXT)
|
|
|
|
|
if((_tmp STREQUAL ".hpp") OR (_tmp STREQUAL ".cpp"))
|
|
|
|
|
set(cc_src_language "CXX")
|
|
|
|
|
else()
|
|
|
|
|
set(cc_src_language "C")
|
2020-04-18 16:38:31 +02:00
|
|
|
endif()
|
2020-04-18 16:17:15 +02:00
|
|
|
endif()
|
2022-06-11 01:06:08 +02:00
|
|
|
if(CMAKE_${cc_src_language}_COMPILER_ID STREQUAL "MSVC")
|
|
|
|
|
set(_define_prefix "/D")
|
|
|
|
|
set(_include_prefix "/I")
|
|
|
|
|
else()
|
|
|
|
|
set(_define_prefix "-D")
|
|
|
|
|
set(_include_prefix "-I")
|
2020-04-18 16:17:15 +02:00
|
|
|
endif()
|
2022-06-11 01:06:08 +02:00
|
|
|
|
|
|
|
|
if(cc_src_language STREQUAL "CXX")
|
|
|
|
|
# C++ Standard
|
|
|
|
|
get_property(cc_src_std_CXX SOURCE ${current_source} TARGET_DIRECTORY ${current_target} PROPERTY CXX_STANDARD)
|
|
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
|
|
|
|
if(cc_src_std_CXX EQUAL 23)
|
|
|
|
|
set(cc_src_std "/std:c++latest")
|
|
|
|
|
elseif(cc_src_std_CXX EQUAL 20)
|
|
|
|
|
set(cc_src_std "/std:c++20")
|
|
|
|
|
elseif(cc_src_std_CXX EQUAL 17)
|
|
|
|
|
set(cc_src_std "/std:c++17")
|
|
|
|
|
elseif(cc_src_std_CXX EQUAL 14)
|
|
|
|
|
set(cc_src_std "/std:c++14")
|
|
|
|
|
else()
|
|
|
|
|
set(cc_src_std "${cc_tgt_std_CXX}")
|
|
|
|
|
endif()
|
|
|
|
|
else()
|
|
|
|
|
if(cc_src_std_CXX EQUAL 23)
|
|
|
|
|
set(cc_src_std "-std=c++23")
|
|
|
|
|
elseif(cc_src_std_CXX EQUAL 20)
|
|
|
|
|
set(cc_src_std "-std=c++20")
|
|
|
|
|
elseif(cc_src_std_CXX EQUAL 17)
|
|
|
|
|
set(cc_src_std "-std=c++17")
|
|
|
|
|
elseif(cc_src_std_CXX EQUAL 14)
|
|
|
|
|
set(cc_src_std "-std=c++14")
|
|
|
|
|
elseif(cc_src_std_CXX EQUAL 11)
|
|
|
|
|
set(cc_src_std "-std=c++11")
|
|
|
|
|
elseif(cc_src_std_CXX EQUAL 98)
|
|
|
|
|
set(cc_src_std "-std=c++98")
|
|
|
|
|
else()
|
|
|
|
|
set(cc_src_std "${cc_tgt_std_CXX}")
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
2020-04-18 16:17:15 +02:00
|
|
|
else()
|
2022-06-11 01:06:08 +02:00
|
|
|
# C standard
|
|
|
|
|
get_property(cc_src_std_C SOURCE ${current_source} TARGET_DIRECTORY ${current_target} PROPERTY C_STANDARD)
|
|
|
|
|
if(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
|
|
|
|
|
if(cc_src_std_C EQUAL 17)
|
|
|
|
|
set(cc_src_std "/std:c17")
|
|
|
|
|
elseif(cc_src_std_C EQUAL 11)
|
|
|
|
|
set(cc_src_std "/std:c11")
|
|
|
|
|
else()
|
|
|
|
|
set(cc_src_std "${cc_tgt_std_C}")
|
|
|
|
|
endif()
|
|
|
|
|
else()
|
|
|
|
|
if(cc_src_std_C EQUAL 23)
|
|
|
|
|
set(cc_src_std "-std=c2x")
|
|
|
|
|
elseif(cc_src_std_C EQUAL 17)
|
|
|
|
|
set(cc_src_std "-std=c17")
|
|
|
|
|
elseif(cc_src_std_C EQUAL 11)
|
|
|
|
|
set(cc_src_std "-std=c11")
|
|
|
|
|
elseif(cc_src_std_C EQUAL 99)
|
|
|
|
|
set(cc_src_std "-std=c99")
|
|
|
|
|
elseif(cc_src_std_C EQUAL 90)
|
|
|
|
|
set(cc_src_std "-std=c90")
|
|
|
|
|
else()
|
|
|
|
|
set(cc_src_std "${cc_tgt_std_C}")
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
2020-04-18 16:17:15 +02:00
|
|
|
endif()
|
|
|
|
|
|
2022-06-11 01:06:08 +02:00
|
|
|
# Includes
|
|
|
|
|
set(cc_src_includex "${cc_tgt_includes}")
|
|
|
|
|
get_property(_tmp SOURCE ${current_source} TARGET_DIRECTORY ${current_target} PROPERTY INCLUDE_DIRECTORIES)
|
|
|
|
|
foreach(_tmp2 ${_tmp})
|
|
|
|
|
cmake_path(ABSOLUTE_PATH _tmp2 BASE_DIRECTORY "${cc_tgt_source_dir}")
|
|
|
|
|
list(APPEND cc_src_includex "${_tmp2}")
|
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
|
|
# Defines
|
|
|
|
|
set(cc_src_defines "${cc_tgt_defines}")
|
|
|
|
|
get_property(_tmp SOURCE ${current_source} TARGET_DIRECTORY ${current_target} PROPERTY COMPILE_DEFINITIONS)
|
|
|
|
|
foreach(_tmp2 ${_tmp})
|
|
|
|
|
list(APPEND cc_src_defines "${_tmp2}")
|
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
|
|
# Compile Options
|
|
|
|
|
set(cc_src_options "${cc_tgt_options}")
|
|
|
|
|
get_property(_tmp SOURCE ${current_source} TARGET_DIRECTORY ${current_target} PROPERTY COMPILE_OPTIONS)
|
|
|
|
|
foreach(_tmp2 ${_tmp})
|
|
|
|
|
list(APPEND cc_src_options "${_tmp2}")
|
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
|
|
#get_property(_ SOURCE ${current_source} TARGET_DIRECTORY ${current_target} PROPERTY _)
|
|
|
|
|
|
|
|
|
|
# Generate JSON content.
|
|
|
|
|
string(APPEND cc_json_content "\t{\n")
|
|
|
|
|
|
|
|
|
|
# Working Directory
|
|
|
|
|
json_escape_string(OUTPUT _tmp INPUT "${cc_tgt_source_dir}")
|
|
|
|
|
file(TO_CMAKE_PATH "${_tmp}" _tmp)
|
|
|
|
|
string(APPEND cc_json_content "\t\t\"directory\": \"${_tmp}\",\n")
|
|
|
|
|
|
|
|
|
|
# Target File
|
|
|
|
|
json_escape_string(OUTPUT _tmp INPUT "${cc_src_location}")
|
|
|
|
|
file(TO_CMAKE_PATH "${_tmp}" _tmp)
|
|
|
|
|
string(APPEND cc_json_content "\t\t\"file\": \"${_tmp}\",\n")
|
|
|
|
|
|
|
|
|
|
if(ON) # Command
|
|
|
|
|
set(_tmp2 "")
|
|
|
|
|
|
|
|
|
|
# cl/cc difference
|
|
|
|
|
if(CMAKE_${cc_src_language}_COMPILER_ID STREQUAL "MSVC")
|
|
|
|
|
string(APPEND _tmp2 "cl ")
|
|
|
|
|
else()
|
|
|
|
|
string(APPEND _tmp2 "cc ")
|
|
|
|
|
endif()
|
2020-04-18 16:17:15 +02:00
|
|
|
|
2022-06-11 01:06:08 +02:00
|
|
|
# C/CXX Standard
|
|
|
|
|
string(APPEND _tmp2 "${cc_src_std} ")
|
|
|
|
|
|
|
|
|
|
# Global Flags
|
|
|
|
|
string(APPEND _tmp2 "${CMAKE_${cc_src_language}_FLAGS} ")
|
|
|
|
|
foreach(current_config ${cc_configurations})
|
|
|
|
|
string(TOUPPER "${current_config}" _tmp)
|
|
|
|
|
string(APPEND _tmp2 "$<$<CONFIG:${current_config}>:${CMAKE_${cc_src_language}_FLAGS_${_tmp}}> ")
|
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
|
|
# Include Directories
|
|
|
|
|
foreach(_tmp ${cc_src_includex})
|
|
|
|
|
file(TO_CMAKE_PATH "${_tmp}" _tmp)
|
|
|
|
|
json_escape_string(OUTPUT _tmp INPUT "${_tmp}")
|
|
|
|
|
string(APPEND _tmp2 "\"${_include_prefix}${_tmp}\" ")
|
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
|
|
# Definitions
|
|
|
|
|
foreach(_tmp ${cc_src_defines})
|
|
|
|
|
json_escape_string(OUTPUT _tmp INPUT "${_tmp}")
|
|
|
|
|
string(APPEND _tmp2 "\"${_define_prefix}${_tmp}\" ")
|
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
|
|
# Other Options
|
|
|
|
|
foreach(_tmp ${cc_src_options})
|
|
|
|
|
json_escape_string(OUTPUT _tmp INPUT "${_tmp}")
|
|
|
|
|
string(APPEND _tmp2 "\"${_tmp}\" ")
|
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
|
|
# File to compile
|
|
|
|
|
json_escape_string(OUTPUT _tmp INPUT "${cc_src_location}")
|
|
|
|
|
if(CMAKE_${cc_src_language}_COMPILER_ID STREQUAL "MSVC")
|
|
|
|
|
string(APPEND _tmp2 "\"${_tmp}\"")
|
|
|
|
|
else()
|
|
|
|
|
string(APPEND _tmp2 "-c \"${_tmp}\"")
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Command
|
|
|
|
|
json_escape_string(OUTPUT _tmp INPUT "${_tmp2}")
|
|
|
|
|
string(APPEND cc_json_content "\t\t\"command\": \"${_tmp}\"\n")
|
2020-04-18 16:17:15 +02:00
|
|
|
endif()
|
2022-06-11 01:06:08 +02:00
|
|
|
|
|
|
|
|
string(APPEND cc_json_content "\t},\n")
|
2020-04-18 16:17:15 +02:00
|
|
|
endforeach()
|
|
|
|
|
|
2022-06-11 01:06:08 +02:00
|
|
|
# Close the array.
|
|
|
|
|
string(APPEND cc_json_content "]\n")
|
|
|
|
|
|
|
|
|
|
# Generate file
|
2022-06-10 20:27:10 +02:00
|
|
|
file(GENERATE
|
2022-06-11 01:06:08 +02:00
|
|
|
OUTPUT "$<TARGET_PROPERTY:${current_target},BINARY_DIR>/$<CONFIG>/compile_commands.json"
|
|
|
|
|
CONTENT "${cc_json_content}"
|
|
|
|
|
TARGET ${current_target}
|
|
|
|
|
FILE_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_READ GROUP_EXECUTE
|
2022-06-10 20:27:10 +02:00
|
|
|
)
|
2020-04-18 16:17:15 +02:00
|
|
|
endforeach()
|
2022-06-11 01:06:08 +02:00
|
|
|
|
|
|
|
|
unset(_tmp)
|
|
|
|
|
unset(_tmp2)
|
|
|
|
|
unset(current_target)
|
|
|
|
|
unset(current_source)
|
|
|
|
|
unset(current_config)
|
2020-04-18 16:17:15 +02:00
|
|
|
endfunction()
|
|
|
|
|
|
2020-01-19 11:41:12 +01:00
|
|
|
function(clang_format)
|
2022-06-11 01:06:08 +02:00
|
|
|
list(APPEND CMAKE_MESSAGE_INDENT "[clang-format] ")
|
2020-01-19 11:41:12 +01:00
|
|
|
cmake_parse_arguments(
|
|
|
|
|
PARSE_ARGV 0
|
2020-04-18 16:17:15 +02:00
|
|
|
_ARGS
|
2020-01-19 11:41:12 +01:00
|
|
|
"DEPENDENCY;GLOBAL"
|
2020-01-22 11:02:51 +01:00
|
|
|
"REGEX;VERSION"
|
2020-01-19 11:41:12 +01:00
|
|
|
"TARGETS"
|
|
|
|
|
)
|
|
|
|
|
|
2020-01-21 10:11:08 +01:00
|
|
|
find_program(CLANG_FORMAT_BIN
|
2020-07-30 07:04:28 +02:00
|
|
|
NAMES
|
|
|
|
|
"clang-format"
|
2020-01-21 10:11:08 +01:00
|
|
|
HINTS
|
2020-04-18 16:17:15 +02:00
|
|
|
"${CLANG_PATH}"
|
2020-01-21 10:11:08 +01:00
|
|
|
PATHS
|
|
|
|
|
/bin
|
|
|
|
|
/sbin
|
|
|
|
|
/usr/bin
|
|
|
|
|
/usr/local/bin
|
|
|
|
|
PATH_SUFFIXES
|
|
|
|
|
bin
|
|
|
|
|
bin64
|
|
|
|
|
bin32
|
2020-07-30 07:04:28 +02:00
|
|
|
DOC "Path (or name) of the clang-format binary"
|
2020-01-21 10:11:08 +01:00
|
|
|
)
|
2020-01-19 11:41:12 +01:00
|
|
|
if(NOT CLANG_FORMAT_BIN)
|
2020-04-18 16:38:31 +02:00
|
|
|
message(WARNING "Clang for CMake: Could not find clang-format at path '${CLANG_FORMAT_BIN}', disabling clang-format...")
|
2022-06-11 01:06:08 +02:00
|
|
|
list(POP_BACK CMAKE_MESSAGE_INDENT)
|
2020-01-19 11:41:12 +01:00
|
|
|
return()
|
|
|
|
|
endif()
|
|
|
|
|
|
2020-01-22 11:02:51 +01:00
|
|
|
# Validate Version
|
2020-04-18 16:17:15 +02:00
|
|
|
if (_ARGS_VERSION)
|
2020-01-22 11:02:51 +01:00
|
|
|
set(_VERSION_RESULT "")
|
|
|
|
|
set(_VERSION_OUTPUT "")
|
|
|
|
|
execute_process(
|
|
|
|
|
COMMAND "${CLANG_FORMAT_BIN}" --version
|
2020-04-18 16:17:15 +02:00
|
|
|
WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}"
|
2020-01-22 11:02:51 +01:00
|
|
|
RESULT_VARIABLE _VERSION_RESULT
|
|
|
|
|
OUTPUT_VARIABLE _VERSION_OUTPUT
|
2020-04-18 16:17:15 +02:00
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE
|
|
|
|
|
ERROR_QUIET
|
2020-01-22 11:02:51 +01:00
|
|
|
)
|
|
|
|
|
if(NOT _VERSION_RESULT EQUAL 0)
|
2020-04-18 16:38:31 +02:00
|
|
|
message(WARNING "Clang for CMake: Could not discover version, disabling clang-format...")
|
2022-06-11 01:06:08 +02:00
|
|
|
list(POP_BACK CMAKE_MESSAGE_INDENT)
|
2020-01-22 11:02:51 +01:00
|
|
|
return()
|
|
|
|
|
endif()
|
|
|
|
|
string(REGEX MATCH "([0-9]+\.[0-9]+\.[0-9]+)" _VERSION_MATCH ${_VERSION_OUTPUT})
|
2020-04-18 16:17:15 +02:00
|
|
|
if(NOT ${_VERSION_MATCH} VERSION_GREATER_EQUAL ${_ARGS_VERSION})
|
2020-04-18 16:38:31 +02:00
|
|
|
message(WARNING "Clang for CMake: Old version discovered, disabling clang-format...")
|
2022-06-11 01:06:08 +02:00
|
|
|
list(POP_BACK CMAKE_MESSAGE_INDENT)
|
2020-01-22 11:02:51 +01:00
|
|
|
return()
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Default Filter
|
2020-04-18 16:17:15 +02:00
|
|
|
if(NOT _ARGS_REGEX)
|
|
|
|
|
set(_ARGS_REGEX "\.(h|hpp|c|cpp)$")
|
2020-01-19 11:41:12 +01:00
|
|
|
endif()
|
|
|
|
|
|
2020-01-22 11:02:51 +01:00
|
|
|
# Go through each target
|
2022-06-11 01:06:08 +02:00
|
|
|
foreach(current_target ${_ARGS_TARGETS})
|
|
|
|
|
get_target_property(target_sources_rel ${current_target} SOURCES)
|
2020-01-19 11:41:12 +01:00
|
|
|
set(target_sources "")
|
2022-06-11 01:06:08 +02:00
|
|
|
foreach(_tmp ${target_sources_rel})
|
|
|
|
|
get_filename_component(_tmp "${_tmp}" ABSOLUTE)
|
|
|
|
|
file(TO_CMAKE_PATH "${_tmp}" _tmp)
|
|
|
|
|
list(APPEND target_sources "${_tmp}")
|
2020-01-19 11:41:12 +01:00
|
|
|
endforeach()
|
2020-04-18 16:17:15 +02:00
|
|
|
list(FILTER target_sources INCLUDE REGEX "${_ARGS_REGEX}")
|
2020-01-19 11:41:12 +01:00
|
|
|
unset(target_sources_rel)
|
2022-06-11 01:06:08 +02:00
|
|
|
|
|
|
|
|
get_target_property(target_source_dir_rel ${current_target} SOURCE_DIR)
|
2020-01-19 11:41:12 +01:00
|
|
|
get_filename_component(target_source_dir ${target_source_dir_rel} ABSOLUTE)
|
|
|
|
|
unset(target_source_dir_rel)
|
|
|
|
|
|
2022-06-11 01:06:08 +02:00
|
|
|
add_custom_target(${current_target}_clang-format
|
2020-04-18 16:17:15 +02:00
|
|
|
COMMAND "${CLANG_FORMAT_BIN}" -style=file -i ${target_sources}
|
2022-06-11 01:06:08 +02:00
|
|
|
COMMENT "clang-format: Formatting ${current_target}..."
|
2020-04-18 16:17:15 +02:00
|
|
|
WORKING_DIRECTORY "${target_source_dir}"
|
2020-01-19 11:41:12 +01:00
|
|
|
)
|
|
|
|
|
|
2022-06-11 01:06:08 +02:00
|
|
|
# IDE Folder
|
|
|
|
|
get_property(folder TARGET ${current_target} PROPERTY FOLDER)
|
|
|
|
|
set_target_properties(${current_target} PROPERTIES FOLDER "${folder}")
|
|
|
|
|
|
2020-04-18 16:17:15 +02:00
|
|
|
if(_ARGS_DEPENDENCY)
|
2022-06-11 01:06:08 +02:00
|
|
|
add_dependencies(${current_target} ${current_target}_clang-format)
|
2020-01-19 11:41:12 +01:00
|
|
|
endif()
|
|
|
|
|
|
2020-04-18 16:17:15 +02:00
|
|
|
if(_ARGS_GLOBAL)
|
2022-06-11 01:06:08 +02:00
|
|
|
if(TARGET clang-format)
|
|
|
|
|
add_dependencies(clang-format ${current_target}_clang-format)
|
2020-01-19 11:41:12 +01:00
|
|
|
else()
|
2022-06-11 01:06:08 +02:00
|
|
|
add_custom_target(clang-format
|
2020-01-19 11:41:12 +01:00
|
|
|
DEPENDS
|
2022-06-11 01:06:08 +02:00
|
|
|
${current_target}_clang-format
|
2020-01-19 11:41:12 +01:00
|
|
|
COMMENT
|
|
|
|
|
"clang-format: Formatting..."
|
|
|
|
|
)
|
2022-06-11 01:06:08 +02:00
|
|
|
set_target_properties(clang-format PROPERTIES
|
|
|
|
|
FOLDER Clang
|
|
|
|
|
)
|
2020-01-19 11:41:12 +01:00
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
2022-06-11 01:06:08 +02:00
|
|
|
list(POP_BACK CMAKE_MESSAGE_INDENT)
|
2020-01-19 11:41:12 +01:00
|
|
|
endfunction()
|
2020-04-18 16:17:15 +02:00
|
|
|
|
|
|
|
|
function(clang_tidy)
|
2022-06-11 01:06:08 +02:00
|
|
|
list(APPEND CMAKE_MESSAGE_INDENT "[clang-tidy] ")
|
2020-04-18 16:17:15 +02:00
|
|
|
cmake_parse_arguments(
|
|
|
|
|
PARSE_ARGV 0
|
|
|
|
|
_ARGS
|
|
|
|
|
"DEPENDENCY;GLOBAL"
|
|
|
|
|
"REGEX;VERSION"
|
|
|
|
|
"TARGETS"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
find_program(CLANG_TIDY_BIN
|
2020-07-30 07:04:28 +02:00
|
|
|
NAMES
|
|
|
|
|
"clang-tidy"
|
2020-04-18 16:17:15 +02:00
|
|
|
HINTS
|
|
|
|
|
"${CLANG_PATH}"
|
|
|
|
|
PATHS
|
|
|
|
|
/bin
|
|
|
|
|
/sbin
|
|
|
|
|
/usr/bin
|
|
|
|
|
/usr/local/bin
|
|
|
|
|
PATH_SUFFIXES
|
|
|
|
|
bin
|
|
|
|
|
bin64
|
|
|
|
|
bin32
|
2020-07-30 07:04:28 +02:00
|
|
|
DOC "Path (or name) of the clang-tidy binary"
|
2020-04-18 16:17:15 +02:00
|
|
|
)
|
|
|
|
|
if(NOT CLANG_TIDY_BIN)
|
2020-04-18 16:38:31 +02:00
|
|
|
message(WARNING "Clang for CMake: Could not find clang-tidy at path '${CLANG_TIDY_BIN}', disabling clang-tidy...")
|
2022-06-11 01:06:08 +02:00
|
|
|
list(POP_BACK CMAKE_MESSAGE_INDENT)
|
2020-04-18 16:17:15 +02:00
|
|
|
return()
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Validate Version
|
|
|
|
|
if (_ARGS_VERSION)
|
|
|
|
|
set(_VERSION_RESULT "")
|
|
|
|
|
set(_VERSION_OUTPUT "")
|
|
|
|
|
execute_process(
|
|
|
|
|
COMMAND "${CLANG_TIDY_BIN}" --version
|
|
|
|
|
WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}"
|
|
|
|
|
RESULT_VARIABLE _VERSION_RESULT
|
|
|
|
|
OUTPUT_VARIABLE _VERSION_OUTPUT
|
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE
|
|
|
|
|
ERROR_QUIET
|
|
|
|
|
)
|
|
|
|
|
if(NOT _VERSION_RESULT EQUAL 0)
|
2020-04-18 16:38:31 +02:00
|
|
|
message(WARNING "Clang for CMake: Could not discover version, disabling clang-tidy...")
|
2022-06-11 01:06:08 +02:00
|
|
|
list(POP_BACK CMAKE_MESSAGE_INDENT)
|
2020-04-18 16:17:15 +02:00
|
|
|
return()
|
|
|
|
|
endif()
|
|
|
|
|
string(REGEX MATCH "([0-9]+\.[0-9]+\.[0-9]+)" _VERSION_MATCH ${_VERSION_OUTPUT})
|
|
|
|
|
if(NOT ${_VERSION_MATCH} VERSION_GREATER_EQUAL ${_ARGS_VERSION})
|
2020-04-18 16:38:31 +02:00
|
|
|
message(WARNING "Clang for CMake: Old version discovered, disabling clang-tidy...")
|
2022-06-11 01:06:08 +02:00
|
|
|
list(POP_BACK CMAKE_MESSAGE_INDENT)
|
2020-04-18 16:17:15 +02:00
|
|
|
return()
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Default Filter
|
|
|
|
|
if(NOT _ARGS_REGEX)
|
|
|
|
|
set(_ARGS_REGEX "\.(h|hpp|c|cpp)$")
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Go through each target
|
2022-06-11 01:06:08 +02:00
|
|
|
foreach(current_target ${_ARGS_TARGETS})
|
2020-04-18 16:17:15 +02:00
|
|
|
# Source Directory
|
2022-06-11 01:06:08 +02:00
|
|
|
get_target_property(_tmp2 ${current_target} SOURCE_DIR)
|
|
|
|
|
get_filename_component(target_source_dir ${_tmp2} ABSOLUTE)
|
|
|
|
|
file(TO_CMAKE_PATH "${target_source_dir}" target_source_dir_nat)
|
|
|
|
|
unset(_tmp2)
|
2020-04-18 16:17:15 +02:00
|
|
|
|
|
|
|
|
# Binary Directory
|
2022-06-11 01:06:08 +02:00
|
|
|
get_target_property(_tmp2 ${current_target} BINARY_DIR)
|
|
|
|
|
get_filename_component(target_binary_dir ${_tmp2} ABSOLUTE)
|
|
|
|
|
file(TO_CMAKE_PATH "${target_binary_dir}" target_binary_dir_nat)
|
|
|
|
|
unset(_tmp2)
|
2020-04-18 16:17:15 +02:00
|
|
|
|
|
|
|
|
# Sources
|
2022-06-11 01:06:08 +02:00
|
|
|
get_target_property(_tmp2 ${current_target} SOURCES)
|
2020-04-18 16:17:15 +02:00
|
|
|
set(target_sources "")
|
2022-06-11 01:06:08 +02:00
|
|
|
foreach(_tmp ${_tmp2})
|
|
|
|
|
get_filename_component(_tmp ${_tmp} ABSOLUTE)
|
|
|
|
|
file(TO_CMAKE_PATH "${_tmp}" _tmp)
|
|
|
|
|
list(APPEND target_sources "${_tmp}")
|
2020-04-18 16:17:15 +02:00
|
|
|
endforeach()
|
|
|
|
|
list(FILTER target_sources INCLUDE REGEX "${_ARGS_REGEX}")
|
2022-06-11 01:06:08 +02:00
|
|
|
unset(_tmp2)
|
2020-04-18 16:17:15 +02:00
|
|
|
|
2022-06-11 01:06:08 +02:00
|
|
|
add_custom_target(${current_target}_clang-tidy
|
|
|
|
|
COMMENT "clang-tiy: Tidying ${current_target}..."
|
2020-04-18 16:17:15 +02:00
|
|
|
WORKING_DIRECTORY "${target_binary_dir}"
|
|
|
|
|
VERBATIM
|
|
|
|
|
)
|
2022-06-11 01:06:08 +02:00
|
|
|
foreach(_tmp ${target_sources})
|
2020-04-18 16:17:15 +02:00
|
|
|
add_custom_command(
|
2022-06-11 01:06:08 +02:00
|
|
|
TARGET ${current_target}_clang-tidy
|
2020-04-18 16:17:15 +02:00
|
|
|
POST_BUILD
|
|
|
|
|
COMMAND "${CLANG_TIDY_BIN}"
|
2022-06-11 01:06:08 +02:00
|
|
|
ARGS --quiet -p="$<TARGET_PROPERTY:${current_target},BINARY_DIR>/$<CONFIG>" "${_tmp}"
|
2020-04-18 16:17:15 +02:00
|
|
|
WORKING_DIRECTORY "${target_binary_dir}"
|
|
|
|
|
COMMAND_EXPAND_LISTS
|
|
|
|
|
)
|
|
|
|
|
endforeach()
|
|
|
|
|
|
2022-06-11 01:06:08 +02:00
|
|
|
# IDE Folder
|
|
|
|
|
get_property(folder TARGET ${current_target} PROPERTY FOLDER)
|
|
|
|
|
set_target_properties(${current_target} PROPERTIES FOLDER "${folder}")
|
|
|
|
|
|
2020-04-18 16:17:15 +02:00
|
|
|
if(_ARGS_DEPENDENCY)
|
2022-06-11 01:06:08 +02:00
|
|
|
add_dependencies(${current_target} ${current_target}_clang-tidy)
|
2020-04-18 16:17:15 +02:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(_ARGS_GLOBAL)
|
2022-06-11 01:06:08 +02:00
|
|
|
if(TARGET clang-tidy)
|
|
|
|
|
add_dependencies(clang-tidy ${current_target}_clang-format)
|
2020-04-18 16:17:15 +02:00
|
|
|
else()
|
2022-06-11 01:06:08 +02:00
|
|
|
add_custom_target(clang-tidy
|
2020-04-18 16:17:15 +02:00
|
|
|
DEPENDS
|
2022-06-11 01:06:08 +02:00
|
|
|
${current_target}_clang-tidy
|
2020-04-18 16:17:15 +02:00
|
|
|
COMMENT
|
|
|
|
|
"clang-tiy: Tidying..."
|
|
|
|
|
)
|
2022-06-11 01:06:08 +02:00
|
|
|
set_target_properties(clang-tidy PROPERTIES
|
|
|
|
|
FOLDER Clang
|
|
|
|
|
)
|
2020-04-18 16:17:15 +02:00
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
2022-06-11 01:06:08 +02:00
|
|
|
list(POP_BACK CMAKE_MESSAGE_INDENT)
|
2020-04-18 16:17:15 +02:00
|
|
|
endfunction()
|