chore: baseline usable version
This commit is contained in:
68
libs/qwindowkit/qmsetup/cmake/modules/private/Generate.cmake
Normal file
68
libs/qwindowkit/qmsetup/cmake/modules/private/Generate.cmake
Normal file
@@ -0,0 +1,68 @@
|
||||
#[[
|
||||
Warning: This module is private, may be modified or removed in the future, please use with caution.
|
||||
]] #
|
||||
|
||||
include_guard(DIRECTORY)
|
||||
|
||||
#[[
|
||||
Create the names of output files preserving relative dirs. (Ported from MOC command)
|
||||
|
||||
qm_make_output_file(<infile> <prefix> <ext> <OUT>)
|
||||
|
||||
OUT: output source file paths
|
||||
#]]
|
||||
function(qm_make_output_file _infile _prefix _ext _out)
|
||||
string(LENGTH ${CMAKE_CURRENT_BINARY_DIR} _binlength)
|
||||
string(LENGTH ${_infile} _infileLength)
|
||||
set(_checkinfile ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
if(_infileLength GREATER _binlength)
|
||||
string(SUBSTRING "${_infile}" 0 ${_binlength} _checkinfile)
|
||||
|
||||
if(_checkinfile STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
file(RELATIVE_PATH _name ${CMAKE_CURRENT_BINARY_DIR} ${_infile})
|
||||
else()
|
||||
file(RELATIVE_PATH _name ${CMAKE_CURRENT_SOURCE_DIR} ${_infile})
|
||||
endif()
|
||||
else()
|
||||
file(RELATIVE_PATH _name ${CMAKE_CURRENT_SOURCE_DIR} ${_infile})
|
||||
endif()
|
||||
|
||||
if(CMAKE_HOST_WIN32 AND _name MATCHES "^([a-zA-Z]):(.*)$") # absolute path
|
||||
set(_name "${CMAKE_MATCH_1}_${CMAKE_MATCH_2}")
|
||||
endif()
|
||||
|
||||
set(_outfile "${CMAKE_CURRENT_BINARY_DIR}/${_name}")
|
||||
string(REPLACE ".." "__" _outfile ${_outfile})
|
||||
get_filename_component(_outpath ${_outfile} PATH)
|
||||
get_filename_component(_outfile ${_outfile} NAME_WLE)
|
||||
|
||||
file(MAKE_DIRECTORY ${_outpath})
|
||||
set(${_out} ${_outpath}/${_prefix}${_outfile}.${_ext} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
#[[
|
||||
Create a custom command to run `xxd`.
|
||||
|
||||
qm_add_binary_resource(<input> <output>)
|
||||
#]]
|
||||
function(qm_add_binary_resource _input _output)
|
||||
find_program(_xxd "xxd")
|
||||
if(NOT _xxd)
|
||||
get_filename_component(_name ${_output} NAME)
|
||||
string(MAKE_C_IDENTIFIER ${_name} _name)
|
||||
set(_cmd "${CMAKE_COMMAND}"
|
||||
-D "input=${_input}"
|
||||
-D "output=${_output}"
|
||||
-D "name=${_name}"
|
||||
-P "${QMSETUP_MODULES_DIR}/scripts/xxd.cmake")
|
||||
else()
|
||||
set(_cmd "${_xxd}" "-i" "${_input}" "${_output}")
|
||||
endif()
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${_output}
|
||||
COMMAND ${_cmd}
|
||||
DEPENDS ${_input}
|
||||
)
|
||||
endfunction()
|
||||
@@ -0,0 +1,158 @@
|
||||
#[[
|
||||
Warning: This module is private, may be modified or removed in the future, please use with caution.
|
||||
]] #
|
||||
|
||||
if(NOT DEFINED QMSETUP_PACKAGE_BUILD_TYPE)
|
||||
set(QMSETUP_PACKAGE_BUILD_TYPE "Release")
|
||||
endif()
|
||||
|
||||
include_guard(DIRECTORY)
|
||||
|
||||
#[[
|
||||
Install external package at configuration phase.
|
||||
|
||||
qm_install_package(<name>
|
||||
[SOURCE_DIR <dir>]
|
||||
[BUILD_TREE_DIR <dir>]
|
||||
[INSTALL_DIR <dir>]
|
||||
[CMAKE_PACKAGE_SUBDIR <subdir>]
|
||||
|
||||
[BUILD_TYPE <type>]
|
||||
[CONFIGURE_ARGS <arg...>]
|
||||
|
||||
[RESULT_PATH <VAR>]
|
||||
)
|
||||
]] #
|
||||
function(qm_install_package _name)
|
||||
set(options)
|
||||
set(oneValueArgs SOURCE_DIR BUILD_TREE_DIR INSTALL_DIR CMAKE_PACKAGE_SUBDIR BUILD_TYPE RESULT_PATH)
|
||||
set(multiValueArgs CONFIGURE_ARGS)
|
||||
cmake_parse_arguments(FUNC "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||
|
||||
# Directories
|
||||
if(NOT FUNC_SOURCE_DIR)
|
||||
message(FATAL_ERROR "pre_install_package: SOURCE_DIR is not spefified")
|
||||
endif()
|
||||
|
||||
set(_src_dir ${FUNC_SOURCE_DIR})
|
||||
|
||||
if(FUNC_BUILD_TREE_DIR)
|
||||
set(_build_tree_dir ${FUNC_BUILD_TREE_DIR})
|
||||
else()
|
||||
set(_build_tree_dir ${CMAKE_BINARY_DIR}/_build)
|
||||
endif()
|
||||
|
||||
if(FUNC_INSTALL_DIR)
|
||||
set(_install_dir ${FUNC_INSTALL_DIR})
|
||||
else()
|
||||
set(_install_dir ${CMAKE_BINARY_DIR}/_install)
|
||||
endif()
|
||||
|
||||
if(FUNC_CMAKE_PACKAGE_SUBDIR)
|
||||
set(_cmake_subdir ${FUNC_CMAKE_PACKAGE_SUBDIR})
|
||||
else()
|
||||
include(GNUInstallDirs)
|
||||
set(_cmake_subdir "${CMAKE_INSTALL_LIBDIR}/cmake/${_name}")
|
||||
endif()
|
||||
|
||||
# Build types
|
||||
if(FUNC_BUILD_TYPE)
|
||||
set(_build_type -DCMAKE_BUILD_TYPE=${FUNC_BUILD_TYPE})
|
||||
elseif(CMAKE_BUILD_TYPE)
|
||||
set(_build_type -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})
|
||||
elseif(NOT CMAKE_CONFIGURATION_TYPES)
|
||||
set(_build_type -DCMAKE_BUILD_TYPE=${QMSETUP_PACKAGE_BUILD_TYPE})
|
||||
else()
|
||||
set(_build_type)
|
||||
endif()
|
||||
|
||||
if(FUNC_BUILD_TYPE)
|
||||
set(_build_types ${FUNC_BUILD_TYPE})
|
||||
else()
|
||||
set(_build_types ${QMSETUP_PACKAGE_BUILD_TYPE})
|
||||
endif()
|
||||
|
||||
# Do it
|
||||
set(_install_cmake_dir ${_install_dir}/${_cmake_subdir})
|
||||
set(_build_dir ${_build_tree_dir}/${_name})
|
||||
|
||||
if(NOT IS_DIRECTORY ${_install_cmake_dir})
|
||||
# Determine generator
|
||||
set(_extra_args)
|
||||
|
||||
if(CMAKE_GENERATOR)
|
||||
set(_extra_args -G "${CMAKE_GENERATOR}")
|
||||
endif()
|
||||
|
||||
if(CMAKE_GENERATOR_PLATFORM)
|
||||
set(_extra_args -A "${CMAKE_GENERATOR_PLATFORM}")
|
||||
endif()
|
||||
|
||||
# Remove old build directory
|
||||
if(IS_DIRECTORY ${_build_dir})
|
||||
file(REMOVE_RECURSE ${_build_dir})
|
||||
endif()
|
||||
|
||||
file(MAKE_DIRECTORY ${_build_tree_dir})
|
||||
|
||||
# Configure
|
||||
message(STATUS "Configuring ${_name}...")
|
||||
set(_log_file ${_build_tree_dir}/${_name}_configure.log)
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND} -S ${_src_dir} -B ${_build_dir}
|
||||
${_extra_args} ${_build_type}
|
||||
# Pass through CMAKE_INSTALL_LIBDIR to ensure the package uses the same
|
||||
# lib directory convention (e.g., lib vs lib64) as the parent project.
|
||||
# Without this, packages using GNUInstallDirs may default to a different
|
||||
# directory structure than expected.
|
||||
"-DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR}"
|
||||
"-DCMAKE_INSTALL_PREFIX=${_install_dir}" ${FUNC_CONFIGURE_ARGS}
|
||||
OUTPUT_FILE ${_log_file}
|
||||
ERROR_FILE ${_log_file}
|
||||
RESULT_VARIABLE _code
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
if(NOT ${_code} EQUAL 0)
|
||||
message(FATAL_ERROR "Configure failed, check \"${_log_file}\"")
|
||||
endif()
|
||||
|
||||
# Build
|
||||
foreach(_item IN LISTS _build_types)
|
||||
message(STATUS "Building ${_name} (${_item})...")
|
||||
set(_log_file ${_build_tree_dir}/${_name}_build-${_item}.log)
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND} --build ${_build_dir} --config ${_item} --parallel
|
||||
OUTPUT_FILE ${_log_file}
|
||||
ERROR_FILE ${_log_file}
|
||||
RESULT_VARIABLE _code
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
if(NOT ${_code} EQUAL 0)
|
||||
message(FATAL_ERROR "Build failed, check \"${_log_file}\"")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# Install
|
||||
foreach(_item IN LISTS _build_types)
|
||||
message(STATUS "Installing ${_name} (${_item})...")
|
||||
set(_log_file ${_build_tree_dir}/${_name}_install-${_item}.log)
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND} --build ${_build_dir} --config ${_item} --target install
|
||||
OUTPUT_FILE ${_log_file}
|
||||
ERROR_FILE ${_log_file}
|
||||
RESULT_VARIABLE _code
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
if(NOT ${_code} EQUAL 0)
|
||||
message(FATAL_ERROR "Install failed, check \"${_log_file}\"")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
if(FUNC_RESULT_PATH)
|
||||
set(${FUNC_RESULT_PATH} ${_install_cmake_dir} PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
@@ -0,0 +1,37 @@
|
||||
include_guard(DIRECTORY)
|
||||
|
||||
function(qm_get_windows_proxy _out)
|
||||
if(NOT WIN32)
|
||||
return()
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
COMMAND reg query "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings" /v ProxyEnable
|
||||
OUTPUT_VARIABLE _proxy_enable_output
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
ERROR_QUIET
|
||||
)
|
||||
|
||||
if(NOT _proxy_enable_output MATCHES "ProxyEnable[ \t\r\n]+REG_DWORD[ \t\r\n]+0x1")
|
||||
return()
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
COMMAND reg query "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings" /v ProxyServer
|
||||
OUTPUT_VARIABLE _proxy_server_output
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
ERROR_QUIET
|
||||
)
|
||||
|
||||
if(NOT _proxy_server_output MATCHES "ProxyServer[ \t\r\n]+REG_SZ[ \t\r\n]+(.*)")
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(${_out} ${CMAKE_MATCH_1} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
macro(qm_set_proxy_env _proxy)
|
||||
set(ENV{HTTP_PROXY} "http://${_proxy}")
|
||||
set(ENV{HTTPS_PROXY} "http://${_proxy}")
|
||||
set(ENV{ALL_PROXY} "http://${_proxy}")
|
||||
endmacro()
|
||||
Reference in New Issue
Block a user