This commit is contained in:
Andrei Astafev 2022-10-09 01:01:31 +03:00
parent 49b06f12cb
commit 120146f6ce
25 changed files with 264 additions and 24 deletions

View File

@ -16,6 +16,11 @@ set(MYX_CMAKE_LIB_DIR "${MYX_CMAKE_SOURCE_DIR}/lib")
include(${MYX_CMAKE_BACKPORTS_DIR}/IncludeGuard.cmake) include(${MYX_CMAKE_BACKPORTS_DIR}/IncludeGuard.cmake)
include(${MYX_CMAKE_BACKPORTS_DIR}/TopLevelProject.cmake) include(${MYX_CMAKE_BACKPORTS_DIR}/TopLevelProject.cmake)
if(${CMAKE_VERSION} VERSION_LESS "3.9.0")
include(${MYX_CMAKE_BACKPORTS_DIR}/CheckIPOSupported.cmake)
else()
include(CheckIPOSupported)
endif()
if(${CMAKE_VERSION} VERSION_LESS "3.11.0") if(${CMAKE_VERSION} VERSION_LESS "3.11.0")
include(${MYX_CMAKE_BACKPORTS_DIR}/FetchContent.cmake) include(${MYX_CMAKE_BACKPORTS_DIR}/FetchContent.cmake)
else() else()

View File

@ -1,4 +1,4 @@
set(MYX_CMAKE_PACKAGE_VERSION "2.0.12") set(MYX_CMAKE_PACKAGE_VERSION "2.0.14")
if(MYX_CMAKE_PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) if(MYX_CMAKE_PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
set(PACKAGE_VERSION_COMPATIBLE FALSE) set(PACKAGE_VERSION_COMPATIBLE FALSE)
else() else()

View File

@ -0,0 +1,186 @@
# X_RESULT - name of the final result variable
# X_OUTPUT - name of the variable with information about error
macro(_ipo_not_supported output)
if(NOT X_RESULT)
message(FATAL_ERROR "IPO is not supported (${output}).")
endif()
set("${X_RESULT}" NO PARENT_SCOPE)
if(X_OUTPUT)
set("${X_OUTPUT}" "${output}" PARENT_SCOPE)
endif()
endmacro()
# Run IPO/LTO test
macro(_ipo_run_language_check language)
set(testdir "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/_CMakeLTOTest-${language}")
file(REMOVE_RECURSE "${testdir}")
file(MAKE_DIRECTORY "${testdir}")
set(bindir "${testdir}/bin")
set(srcdir "${testdir}/src")
file(MAKE_DIRECTORY "${bindir}")
file(MAKE_DIRECTORY "${srcdir}")
set(TRY_COMPILE_PROJECT_NAME "lto-test")
set(try_compile_src "${CMAKE_ROOT}/Modules/CheckIPOSupported")
# Use:
# * TRY_COMPILE_PROJECT_NAME
# * CMAKE_VERSION
configure_file(
"${try_compile_src}/CMakeLists-${language}.txt.in"
"${srcdir}/CMakeLists.txt"
@ONLY
)
string(COMPARE EQUAL "${language}" "C" is_c)
string(COMPARE EQUAL "${language}" "CXX" is_cxx)
string(COMPARE EQUAL "${language}" "Fortran" is_fortran)
if(is_c)
set(copy_sources foo.c main.c)
elseif(is_cxx)
set(copy_sources foo.cpp main.cpp)
elseif(is_fortran)
set(copy_sources foo.f main.f)
else()
message(FATAL_ERROR "Language not supported")
endif()
foreach(x ${copy_sources})
configure_file(
"${try_compile_src}/${x}"
"${srcdir}/${x}"
COPYONLY
)
endforeach()
try_compile(
_IPO_LANGUAGE_CHECK_RESULT
"${bindir}"
"${srcdir}"
"${TRY_COMPILE_PROJECT_NAME}"
CMAKE_FLAGS
"-DCMAKE_VERBOSE_MAKEFILE=ON"
"-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON"
OUTPUT_VARIABLE output
)
set(_IPO_LANGUAGE_CHECK_RESULT "${_IPO_LANGUAGE_CHECK_RESULT}")
unset(_IPO_LANGUAGE_CHECK_RESULT CACHE)
if(NOT _IPO_LANGUAGE_CHECK_RESULT)
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"${language} compiler IPO check failed with the following output:\n"
"${output}\n")
_ipo_not_supported("check failed to compile")
if(X_OUTPUT)
set("${X_OUTPUT}" "${output}" PARENT_SCOPE)
endif()
return()
endif()
endmacro()
function(check_ipo_supported)
cmake_policy(GET CMP0069 x)
string(COMPARE EQUAL "${x}" "" not_set)
if(not_set)
message(FATAL_ERROR "Policy CMP0069 is not set")
endif()
string(COMPARE EQUAL "${x}" "OLD" is_old)
if(is_old)
message(FATAL_ERROR "Policy CMP0069 set to OLD")
endif()
set(optional)
set(one RESULT OUTPUT)
set(multiple LANGUAGES)
# Introduce:
# * X_RESULT
# * X_OUTPUT
# * X_LANGUAGES
cmake_parse_arguments(X "${optional}" "${one}" "${multiple}" "${ARGV}")
string(COMPARE NOTEQUAL "${X_UNPARSED_ARGUMENTS}" "" has_unparsed)
if(has_unparsed)
message(FATAL_ERROR "Unparsed arguments: ${X_UNPARSED_ARGUMENTS}")
endif()
string(COMPARE EQUAL "${X_LANGUAGES}" "" no_languages)
if(no_languages)
# User did not set any languages, use defaults
get_property(enabled_languages GLOBAL PROPERTY ENABLED_LANGUAGES)
string(COMPARE EQUAL "${enabled_languages}" "" no_languages)
if(no_languages)
_ipo_not_supported(
"no languages found in ENABLED_LANGUAGES global property"
)
return()
endif()
set(languages "")
list(FIND enabled_languages "CXX" result)
if(NOT result EQUAL -1)
list(APPEND languages "CXX")
endif()
list(FIND enabled_languages "C" result)
if(NOT result EQUAL -1)
list(APPEND languages "C")
endif()
list(FIND enabled_languages "Fortran" result)
if(NOT result EQUAL -1)
list(APPEND languages "Fortran")
endif()
string(COMPARE EQUAL "${languages}" "" no_languages)
if(no_languages)
_ipo_not_supported(
"no C/CXX/Fortran languages found in ENABLED_LANGUAGES global property"
)
return()
endif()
else()
set(languages "${X_LANGUAGES}")
set(unsupported_languages "${languages}")
list(REMOVE_ITEM unsupported_languages "C" "CXX" "Fortran")
string(COMPARE NOTEQUAL "${unsupported_languages}" "" has_unsupported)
if(has_unsupported)
_ipo_not_supported(
"language(s) '${unsupported_languages}' not supported"
)
return()
endif()
endif()
foreach(lang ${languages})
if(NOT _CMAKE_${lang}_IPO_SUPPORTED_BY_CMAKE)
_ipo_not_supported("CMake doesn't support IPO for current ${lang} compiler")
return()
endif()
if(NOT _CMAKE_${lang}_IPO_MAY_BE_SUPPORTED_BY_COMPILER)
_ipo_not_supported("${lang} compiler doesn't support IPO")
return()
endif()
endforeach()
if(CMAKE_GENERATOR MATCHES "^Visual Studio 9 ")
_ipo_not_supported("CMake doesn't support IPO for current generator")
return()
endif()
foreach(x ${languages})
_ipo_run_language_check(${x})
endforeach()
set("${X_RESULT}" YES PARENT_SCOPE)
endfunction()

View File

@ -0,0 +1,8 @@
cmake_minimum_required(VERSION "@CMAKE_VERSION@")
project("@TRY_COMPILE_PROJECT_NAME@" LANGUAGES C)
cmake_policy(SET CMP0069 NEW)
add_library(foo foo.c)
add_executable(boo main.c)
target_link_libraries(boo PUBLIC foo)

View File

@ -0,0 +1,8 @@
cmake_minimum_required(VERSION "@CMAKE_VERSION@")
project("@TRY_COMPILE_PROJECT_NAME@" LANGUAGES CXX)
cmake_policy(SET CMP0069 NEW)
add_library(foo foo.cpp)
add_executable(boo main.cpp)
target_link_libraries(boo PUBLIC foo)

View File

@ -0,0 +1,8 @@
cmake_minimum_required(VERSION "@CMAKE_VERSION@")
project("@TRY_COMPILE_PROJECT_NAME@" LANGUAGES Fortran)
cmake_policy(SET CMP0069 NEW)
add_library(foo foo.f)
add_executable(boo main.f)
target_link_libraries(boo PUBLIC foo)

View File

@ -0,0 +1,4 @@
int foo()
{
return 0x42;
}

View File

@ -0,0 +1,4 @@
int foo()
{
return 0x42;
}

View File

@ -0,0 +1,2 @@
SUBROUTINE FOO
END

View File

@ -0,0 +1,6 @@
int foo();
int main()
{
return foo();
}

View File

@ -0,0 +1,6 @@
int foo();
int main()
{
return foo();
}

View File

@ -0,0 +1,3 @@
PROGRAM BOO
CALL FOO()
END

View File

@ -46,7 +46,7 @@ function(myx_add_library NAME TYPE)
if(TYPE STREQUAL "INTERFACE") if(TYPE STREQUAL "INTERFACE")
# Библиотека, состоящая только из заголовочных файлов не требует сборки. # Библиотека, состоящая только из заголовочных файлов не требует сборки.
# Стандартные пути к заголовочным файлам # Стандартные пути к заголовочным файлам
target_include_directories(${NAME} SYSTEM INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>) target_include_directories(${NAME} INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>)
else() else()
string(TOUPPER ${NAME} PROJECT_NAME_UPPER) string(TOUPPER ${NAME} PROJECT_NAME_UPPER)
# Опция для разрешения сборки динамической библиотеки # Опция для разрешения сборки динамической библиотеки

View File

@ -9,7 +9,7 @@ file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/include) file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/include)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/lib) file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
create_symlink("${CMAKE_SOURCE_DIR}/files/etc" "${CMAKE_BINARY_DIR}/etc") myx_create_symlink("${CMAKE_SOURCE_DIR}/files/etc" "${CMAKE_BINARY_DIR}/etc")
create_symlink("${CMAKE_SOURCE_DIR}/files/log" "${CMAKE_BINARY_DIR}/log") myx_create_symlink("${CMAKE_SOURCE_DIR}/files/log" "${CMAKE_BINARY_DIR}/log")
create_symlink("${CMAKE_SOURCE_DIR}/files/share" "${CMAKE_BINARY_DIR}/share") myx_create_symlink("${CMAKE_SOURCE_DIR}/files/share" "${CMAKE_BINARY_DIR}/share")
create_symlink("${CMAKE_SOURCE_DIR}/files/var" "${CMAKE_BINARY_DIR}/var") myx_create_symlink("${CMAKE_SOURCE_DIR}/files/var" "${CMAKE_BINARY_DIR}/var")

View File

@ -91,7 +91,7 @@ function(myx_qt5_target_setup NAME)
# Установка публичных заголовочных файлов # Установка публичных заголовочных файлов
if(PROJECT_IS_TOP_LEVEL) if(PROJECT_IS_TOP_LEVEL)
install_relative(${PROJECT_SOURCE_DIR} myx_install_relative(${PROJECT_SOURCE_DIR}
FILES ${ARG_PUBLIC_MOC} FILES ${ARG_PUBLIC_MOC}
DESTINATION ${CMAKE_INSTALL_PREFIX} DESTINATION ${CMAKE_INSTALL_PREFIX}
COMPONENT dev COMPONENT dev

View File

@ -74,7 +74,7 @@ function(myx_target_setup NAME)
endif() endif()
if(${target_type} STREQUAL "INTERFACE_LIBRARY") if(${target_type} STREQUAL "INTERFACE_LIBRARY")
target_sources(${NAME} INTERFACE ${ARG_INTERFACE_HEADERS}) target_sources(${NAME} INTERFACE $<BUILD_INTERFACE:${ARG_INTERFACE_HEADERS}>)
else() else()
target_sources(${NAME} PUBLIC $<BUILD_INTERFACE:${ARG_INTERFACE_HEADERS}>) target_sources(${NAME} PUBLIC $<BUILD_INTERFACE:${ARG_INTERFACE_HEADERS}>)
target_sources(${NAME} PUBLIC ${ARG_PUBLIC_HEADERS}) target_sources(${NAME} PUBLIC ${ARG_PUBLIC_HEADERS})
@ -120,7 +120,7 @@ function(myx_target_setup NAME)
# Установка публичных заголовочных файлов # Установка публичных заголовочных файлов
if(PROJECT_IS_TOP_LEVEL) if(PROJECT_IS_TOP_LEVEL)
install_relative(${PROJECT_SOURCE_DIR} myx_install_relative(${PROJECT_SOURCE_DIR}
FILES ${ARG_PUBLIC_HEADERS} ${ARG_INTERFACE_HEADERS} FILES ${ARG_PUBLIC_HEADERS} ${ARG_INTERFACE_HEADERS}
DESTINATION ${CMAKE_INSTALL_PREFIX} DESTINATION ${CMAKE_INSTALL_PREFIX}
COMPONENT dev COMPONENT dev

View File

@ -1,11 +1,11 @@
include_guard(GLOBAL) include_guard(GLOBAL)
macro(create_symlink original linkname) macro(myx_create_symlink original linkname)
if(NOT EXISTS ${linkname}) if(NOT EXISTS ${linkname})
if(${CMAKE_VERSION} VERSION_LESS "3.14.0") if(${CMAKE_VERSION} VERSION_LESS "3.14.0")
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${original} ${linkname}) execute_process(COMMAND ${CMAKE_COMMAND} -E myx_create_symlink ${original} ${linkname})
else() else()
file(CREATE_LINK ${original} ${linkname} SYMBOLIC) file(CREATE_LINK ${original} ${linkname} SYMBOLIC)
endif() endif()
endif() endif()
endmacro(create_symlink original linkname) endmacro(myx_create_symlink original linkname)

View File

@ -1,6 +1,6 @@
include_guard(GLOBAL) include_guard(GLOBAL)
macro(myx_find_packages) macro(myx_find_requred_packages)
set(options) set(options)
set(oneValueArgs) set(oneValueArgs)
set(multiValueArgs PACKAGES Boost Qt5 Qt5Private) set(multiValueArgs PACKAGES Boost Qt5 Qt5Private)

View File

@ -1,10 +1,10 @@
#[=======================================================================[.rst: #[=======================================================================[.rst:
install_relative myx_install_relative
---------------- --------------------
#]=======================================================================] #]=======================================================================]
macro(install_relative STRIP_DIRECTORY) macro(myx_install_relative STRIP_DIRECTORY)
set(options) set(options)
set(oneValueArgs DESTINATION) set(oneValueArgs DESTINATION)
set(multiValueArgs FILES) set(multiValueArgs FILES)
@ -16,4 +16,4 @@ macro(install_relative STRIP_DIRECTORY)
string(REPLACE ${STRIP_DIRECTORY} "" RELATIVE_DIR ${DIR}) string(REPLACE ${STRIP_DIRECTORY} "" RELATIVE_DIR ${DIR})
INSTALL(FILES ${FILE} DESTINATION ${ARG_DESTINATION}/${RELATIVE_DIR} ${ARG_UNPARSED_ARGUMENTS}) INSTALL(FILES ${FILE} DESTINATION ${ARG_DESTINATION}/${RELATIVE_DIR} ${ARG_UNPARSED_ARGUMENTS})
endforeach() endforeach()
endmacro(install_relative STRIP_DIRECTORY) endmacro(myx_install_relative STRIP_DIRECTORY)

View File

@ -7,7 +7,7 @@ macro(myx_skip_external_target NAME)
get_target_property(__sources ${NAME} INTERFACE_SOURCES) get_target_property(__sources ${NAME} INTERFACE_SOURCES)
foreach(iter ${__sources}) foreach(iter ${__sources})
string(FIND ${iter} ${CMAKE_BINARY_DIR} __pos) string(FIND ${iter} ${CMAKE_BINARY_DIR} __pos)
if(__pos EQUAL 0) if(__pos GREATER -1)
unset(__type) unset(__type)
unset(__pos) unset(__pos)
unset(__sources) unset(__sources)

View File

@ -3,7 +3,7 @@
## Установка ## Установка
В корневом каталоге проекта создать каталог `cmake` и распаковать в него В корневом каталоге проекта создать каталог `cmake` и распаковать в него
[архив](../../../releases/download/2.0.12/myx-cmake-local-2.0.12.tar.xz ). [архив](../../../releases/download/2.0.14/myx-cmake-local-2.0.14.tar.xz ).
## Использование ## Использование

View File

@ -1 +1 @@
2.0.12 2.0.14

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.6 FATAL_ERROR) cmake_minimum_required(VERSION 3.6 FATAL_ERROR)
project(myx-cmake VERSION 2.0.12 LANGUAGES) project(myx-cmake VERSION 2.0.14 LANGUAGES)
include(GNUInstallDirs) include(GNUInstallDirs)
file(WRITE ${CMAKE_SOURCE_DIR}/MyxCMake/MyxCMakeConfigVersion.cmake file(WRITE ${CMAKE_SOURCE_DIR}/MyxCMake/MyxCMakeConfigVersion.cmake

2
debian/changelog vendored
View File

@ -1,4 +1,4 @@
myx-cmake (2.0.12) unstable; urgency=medium myx-cmake (2.0.14) unstable; urgency=medium
* New version. * New version.

View File

@ -20,11 +20,11 @@ if(ENV{MYX_CMAKE_DIR})
set(MYX_CMAKE_DIR $ENV{MYX_CMAKE_DIR}) set(MYX_CMAKE_DIR $ENV{MYX_CMAKE_DIR})
endif() endif()
if(MYX_CMAKE_DIR) if(MYX_CMAKE_DIR)
find_package(MyxCMake 2.0.12 REQUIRED CONFIG PATHS ${MYX_CMAKE_DIR} NO_DEFAULT_PATH) find_package(MyxCMake 2.0.14 REQUIRED CONFIG PATHS ${MYX_CMAKE_DIR} NO_DEFAULT_PATH)
myx_message_notice("=== MyxCMake directory: ${MyxCMake_CONFIG} ===") myx_message_notice("=== MyxCMake directory: ${MyxCMake_CONFIG} ===")
else() else()
if(MYX_CMAKE_USE_SYSTEM) if(MYX_CMAKE_USE_SYSTEM)
find_package(MyxCMake 2.0.12 REQUIRED) find_package(MyxCMake 2.0.14 REQUIRED)
myx_message_notice("=== MyxCMake directory: ${MyxCMake_CONFIG} ===") myx_message_notice("=== MyxCMake directory: ${MyxCMake_CONFIG} ===")
else() else()
include(${PROJECT_SOURCE_DIR}/cmake/myx/MyxCMakeConfig.cmake) include(${PROJECT_SOURCE_DIR}/cmake/myx/MyxCMakeConfig.cmake)