Skip to content

Commit

Permalink
add custom targets to automatically run generated commands
Browse files Browse the repository at this point in the history
  • Loading branch information
feihong committed Dec 5, 2024
1 parent 5ac1eca commit d1c8d34
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Expand Down
33 changes: 21 additions & 12 deletions generator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<TARGET_FILE:${PROJECT_NAME}>
# WORKING_DIRECTORY $<TARGET_FILE_DIR:${PROJECT_NAME}>
# )
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:$<TARGET_FILE_DIR:Qt${QT_VERSION_MAJOR}::Widgets> $<TARGET_FILE:${PROJECT_NAME}>
WORKING_DIRECTORY $<TARGET_FILE_DIR:${PROJECT_NAME}>
VERBATIM USES_TERMINAL
)
endif()

4 changes: 4 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ add_test(NAME ${PROJECT_NAME}
COMMAND $<TARGET_FILE:${PROJECT_NAME}>
WORKING_DIRECTORY $<TARGET_FILE_DIR:${PROJECT_NAME}>
)

set_tests_properties(${PROJECT_NAME} PROPERTIES
ENVIRONMENT_MODIFICATION "Path=path_list_append:$<TARGET_FILE_DIR:Qt${QT_VERSION_MAJOR}::Widgets>"
)

0 comments on commit d1c8d34

Please sign in to comment.