From d1c8d34d9c8eab11e267890e91c295b2a0ee67c9 Mon Sep 17 00:00:00 2001 From: feihong Date: Thu, 5 Dec 2024 17:05:13 +0800 Subject: [PATCH] add custom targets to automatically run generated commands --- CMakeLists.txt | 5 +++-- generator/CMakeLists.txt | 33 +++++++++++++++++++++------------ tests/CMakeLists.txt | 4 ++++ 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6acb828f4..e0fc19f6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,7 @@ cmake_minimum_required(VERSION 3.27) +enable_testing() + project(PythonQt LANGUAGES CXX VERSION 3.5.6) set(CMAKE_CXX_STANDARD 11) @@ -12,8 +14,7 @@ set(PYTHONQT_SUFFIX Qt${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}-Python${Python3_VE add_subdirectory(generator) -set(PYTHONQT_GENERATED_PATH ${CMAKE_CURRENT_LIST_DIR}/generated_cpp) -if(NOT EXISTS ${PYTHONQT_GENERATED_PATH}) +if(NOT EXISTS "${PYTHONQT_GENERATED_PATH}") if(${QT_VERSION_MAJOR} VERSION_EQUAL 5) if(${QT_VERSION_MINOR} VERSION_LESS 3) set(PYTHONQT_GENERATED_PATH ${CMAKE_CURRENT_LIST_DIR}/generated_cpp_50) diff --git a/generator/CMakeLists.txt b/generator/CMakeLists.txt index 26d900a0d..23f2c39bf 100644 --- a/generator/CMakeLists.txt +++ b/generator/CMakeLists.txt @@ -24,15 +24,24 @@ target_link_libraries(${PROJECT_NAME} PUBLIC target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}) -# file(GLOB resources_files *.txt *.xml) -# foreach(resources_file IN LISTS resources_files) -# configure_file(${resources_file} ${CMAKE_CURRENT_BINARY_DIR} COPYONLY) -# endforeach() - -# file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/generated_cpp") - -# add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD -# COMMAND set Path="%Path%;" -# COMMAND $ -# WORKING_DIRECTORY $ -# ) +set(PYTHONQT_GENERATED_PATH ${CMAKE_CURRENT_BINARY_DIR}/../generated_cpp PARENT_SCOPE) + +if(NOT EXISTS ${PYTHONQT_GENERATED_PATH}) + file(GLOB resources_files *.txt *.xml qtscript_masterinclude.h) + foreach(resources_file IN LISTS resources_files) + configure_file(${resources_file} ${CMAKE_CURRENT_BINARY_DIR} COPYONLY) + endforeach() + + if(WIN32) + set(LIBRARY_SEARCH_PATH PATH) + else() + set(LIBRARY_SEARCH_PATH LD_LIBRARY_PATH) + endif() + + add_custom_target(GenerateCpp + COMMAND ${CMAKE_COMMAND} -E env --modify ${LIBRARY_SEARCH_PATH}=path_list_prepend:$ $ + WORKING_DIRECTORY $ + VERBATIM USES_TERMINAL + ) +endif() + diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 35a5c8252..8d9ad75fb 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -23,3 +23,7 @@ add_test(NAME ${PROJECT_NAME} COMMAND $ WORKING_DIRECTORY $ ) + +set_tests_properties(${PROJECT_NAME} PROPERTIES + ENVIRONMENT_MODIFICATION "Path=path_list_append:$" +)