From 6242b5a8901407cb238d666a0d0a4dde6e52b785 2013-07-30 22:22:27 From: Orochimarufan Date: 2013-07-30 22:22:27 Subject: [PATCH] Add PythonQt*Config.cmake --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 4324132..ad55cdd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,10 @@ else() remove_definitions(-DPYTHONQT_DEBUG) endif() +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) +endif() + #----------------------------------------------------------------------------- # Qt option(PythonQt_Qt5 "Use Qt 5.x (5.1+)" OFF) @@ -110,6 +114,12 @@ else() find_package(Python 2.6 REQUIRED) endif() +if(NOT ${PYTHON_VERSION} VERSION_LESS 3) + set(PythonQt_Python3 ON) +else() + set(PythonQt_Python3 OFF) +endif() + include_directories(${PYTHON_INCLUDE_DIRS}) add_definitions(-DPYTHONQT_USE_RELEASE_PYTHON_FALLBACK) @@ -124,11 +134,11 @@ if(PythonQt_Qt5) set(PythonQt_LibraryName ${PythonQt_LibraryName}5) endif() -if(NOT ${PYTHON_VERSION} VERSION_LESS 3) +if(PythonQt_Python3) set(PythonQt_LibraryName ${PythonQt_LibraryName}_3) endif() -if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") +if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") set(PythonQt_LibrarySuffix _d) endif() @@ -147,13 +157,23 @@ add_dependencies(test PythonQtTest) #----------------------------------------------------------------------------- # Extenseions (QtAll) -add_subdirectory(extensions EXCLUDE_FROM_ALL) +add_subdirectory(extensions) # QtAll alias add_custom_target(QtAll) -add_dependencies(QtAll PythonQt_QtAll) +add_dependencies(QtAll ${PythonQt_QtAll}) #----------------------------------------------------------------------------- # Examples include_directories(src) include_directories(extensions/PythonQt_QtAll) add_subdirectory(examples EXCLUDE_FROM_ALL) + +#----------------------------------------------------------------------------- +# uninstall target +configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" + IMMEDIATE @ONLY) + +add_custom_target(uninstall + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) diff --git a/cmake/cmake_uninstall.cmake.in b/cmake/cmake_uninstall.cmake.in new file mode 100644 index 0000000..ddd3c2b --- /dev/null +++ b/cmake/cmake_uninstall.cmake.in @@ -0,0 +1,24 @@ +cmake_policy(SET CMP0007 OLD) + +if (NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") + message(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"") +endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") + +file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) +string(REGEX REPLACE "\n" ";" files "${files}") +list(REVERSE files) +foreach (file ${files}) + message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"") + if (EXISTS "$ENV{DESTDIR}${file}") + execute_process( + COMMAND @CMAKE_COMMAND@ -E remove "$ENV{DESTDIR}${file}" + OUTPUT_VARIABLE rm_out + RESULT_VARIABLE rm_retval + ) + if(NOT ${rm_retval} EQUAL 0) + message(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"") + endif (NOT ${rm_retval} EQUAL 0) + else (EXISTS "$ENV{DESTDIR}${file}") + message(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.") + endif (EXISTS "$ENV{DESTDIR}${file}") +endforeach(file) diff --git a/examples/NicePyConsole/CMakeLists.txt b/examples/NicePyConsole/CMakeLists.txt index 0378c11..ced1dbb 100644 --- a/examples/NicePyConsole/CMakeLists.txt +++ b/examples/NicePyConsole/CMakeLists.txt @@ -27,6 +27,8 @@ SET(DIRS pygments ) +find_package(${PythonQt}) + qt_wrap_cpp(GEN_MOC ${HEADERS}) add_executable(NicePyConsole ${SOURCES} ${GEN_MOC}) @@ -36,9 +38,7 @@ else() qt_use_modules(NicePyConsole Core Gui) endif() -get_property(PythonQt_lib TARGET ${PythonQt} PROPERTY LOCATION) -get_property(PythonQt_QtAll_lib TARGET ${PythonQt_QtAll} PROPERTY LOCATION) -target_link_libraries(NicePyConsole ${PythonQt_lib} ${PythonQt_QtAll_lib} ${PYTHON_LIBRARIES}) +target_link_libraries(NicePyConsole ${PythonQt} ${PythonQt_QtAll} ${PYTHON_LIBRARIES}) foreach(FILE ${FILES}) SET(OUT "${CMAKE_CURRENT_BINARY_DIR}/${FILE}") diff --git a/extensions/PythonQt_QtAll/CMakeLists.txt b/extensions/PythonQt_QtAll/CMakeLists.txt index 0a411d9..236b5bf 100644 --- a/extensions/PythonQt_QtAll/CMakeLists.txt +++ b/extensions/PythonQt_QtAll/CMakeLists.txt @@ -138,6 +138,8 @@ endforeach() # Build set(PythonQt_QtAll ${PythonQt_LibraryName}_QtAll${PythonQt_LibrarySuffix} CACHE INTERNAL "") +find_package(${PythonQt}) + include_directories(../../src) add_definitions(-DPYTHONQT_QTALL_EXPORTS) qt_wrap_cpp(GEN_MOC ${HEADERS}) @@ -151,10 +153,36 @@ endif() add_library(${PythonQt_QtAll} SHARED ${SOURCES} ${GEN_MOC}) qt_use_modules(${PythonQt_QtAll} ${QT}) -get_property(PythonQt_lib TARGET ${PythonQt} PROPERTY LOCATION) -target_link_libraries(${PythonQt_QtAll} ${PythonQt_lib} ${PYTHON_LIBRARIES}) +target_link_libraries(${PythonQt_QtAll} ${PythonQt} ${PYTHON_LIBRARIES}) -install(TARGETS ${PythonQt_QtAll} +install(TARGETS ${PythonQt_QtAll} EXPORT ${PythonQt_QtAll}Targets COMPONENT QtAll RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) + +#----------------------------------------------------------------------------- +# Export CMake Config + +if(WIN32 AND NOT CYGWIN) + set(LIB_CMAKE_PATH "cmake") +else() + set(LIB_CMAKE_PATH "lib/cmake/${PythonQt_QtAll}") +endif() + +export(TARGETS ${PythonQt_QtAll} ${PythonQt} FILE "${PROJECT_BINARY_DIR}/${PythonQt_QtAll}Targets.cmake") +export(PACKAGE ${PythonQt_QtAll}) + +# build tree +set(INCLUDE_DIRS "${PROJECT_SOURCE_DIR}" "${PROJECT_BINARY_DIR}") +configure_file(PythonQt_QtAllConfig.cmake.in "${PROJECT_BINARY_DIR}/${PythonQt_QtAll}Config.cmake" @ONLY) +# install tree +set(INCLUDE_DIRS "${CMAKE_INSTALL_PREFIX}/include/PythonQt/QtAll") +configure_file(PythonQt_QtAllConfig.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${PythonQt_QtAll}Config.cmake" @ONLY) +# both +configure_file(PythonQt_QtAllConfigVersion.cmake.in "${PROJECT_BINARY_DIR}/${PythonQt_QtAll}ConfigVersion.cmake" @ONLY) + +install(EXPORT ${PythonQt_QtAll}Targets DESTINATION "${LIB_CMAKE_PATH}" COMPONENT QtAll-dev) +install(FILES ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${PythonQt_QtAll}Config.cmake + ${PROJECT_BINARY_DIR}/${PythonQt_QtAll}ConfigVersion.cmake + DESTINATION "${LIB_CMAKE_PATH}" COMPONENT QtAll-dev) + diff --git a/extensions/PythonQt_QtAll/PythonQt_QtAllConfig.cmake.in b/extensions/PythonQt_QtAll/PythonQt_QtAllConfig.cmake.in new file mode 100644 index 0000000..72c7dcb --- /dev/null +++ b/extensions/PythonQt_QtAll/PythonQt_QtAllConfig.cmake.in @@ -0,0 +1,21 @@ +# - Config file for the PythonQt package +# It defines the following variables +# PythonQt - the PythonQt core target (PythonQt PythonQt_3 PythonQt5 PythonQt5_3) +# PythonQt_QtAll - the PythonQt QtAll target +# PythonQt_QtAll_INCLUDE_DIRS - include directories for PythonQt +# PythonQt_QtAll_LIBRARIES - libraries to link against + +set(PythonQt @PythonQt@) +set(PythonQt_QtAll @PythonQt_QtAll@) + +# Compute paths +get_filename_component(PYTHONQT_QTALL_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +set(PythonQt_QtAll_INCLUDE_DIRS "@INCLUDE_DIRS@") + +# Our library dependencies (contains definitions for IMPORTED targets) +if(NOT TARGET @PythonQt_QtAll@) + include("${PYTHONQT_QTALL_CMAKE_DIR}/@PythonQt_QtAll@Targets.cmake") +endif() + +# These are IMPORTED targets created by @PythonQt_QtAll@Targets.cmake +set(PythonQt_QtAll_LIBRARIES @PythonQt_QtAll@) diff --git a/extensions/PythonQt_QtAll/PythonQt_QtAllConfigVersion.cmake.in b/extensions/PythonQt_QtAll/PythonQt_QtAllConfigVersion.cmake.in new file mode 100644 index 0000000..c3ef74a --- /dev/null +++ b/extensions/PythonQt_QtAll/PythonQt_QtAllConfigVersion.cmake.in @@ -0,0 +1,11 @@ +set(PACKAGE_VERSION "@PythonQt_VERSION@") + +# Check whether the requested PACKAGE_FIND_VERSION is compatible +if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") + set(PACKAGE_VERSION_COMPATIBLE FALSE) +else() + set(PACKAGE_VERSION_COMPATIBLE TRUE) + if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") + set(PACKAGE_VERSION_EXACT TRUE) + endif() +endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2a641f3..67b6375 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -86,7 +86,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}) qt_wrap_cpp(GEN_MOC ${SOURCES_MOC}) qt_add_resources(GEN_QRC ${SOURCES_QRC}) -add_library(${PythonQt} SHARED ${SOURCES} ${GEN_MOC} ${GEN_QRC} ${HEADERS}) +add_library(${PythonQt} SHARED ${SOURCES} ${GEN_MOC} ${GEN_QRC}) if(PythonQt_Qt5) qt_use_modules(${PythonQt} Core Gui Widgets) else() @@ -103,8 +103,37 @@ set_target_properties(${PythonQt} PROPERTIES INSTALL_NAME_DIR "${CMAKE_INSTALL_P #----------------------------------------------------------------------------- # Install library (on windows, put the dll in 'bin' and the archive in 'lib') -install(TARGETS ${PythonQt} - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib) -install(FILES ${headers} DESTINATION include/PythonQt) +set_target_properties(${PythonQt} PROPERTIES PUBLIC_HEADER "${HEADERS}") + +install(TARGETS ${PythonQt} EXPORT ${PythonQt}Targets COMPONENT core-dev + RUNTIME DESTINATION bin COMPONENT core + LIBRARY DESTINATION lib COMPONENT core + ARCHIVE DESTINATION lib COMPONENT core + PUBLIC_HEADER DESTINATION include/PythonQt) + +#----------------------------------------------------------------------------- +# Export CMake Config + +if(WIN32 AND NOT CYGWIN) + set(LIB_CMAKE_PATH "cmake") +else() + set(LIB_CMAKE_PATH "lib/cmake/${PythonQt}") +endif() + +export(TARGETS ${PythonQt} FILE "${PROJECT_BINARY_DIR}/${PythonQt}Targets.cmake") +export(PACKAGE ${PythonQt}) + +# build tree +set(INCLUDE_DIRS "${PROJECT_SOURCE_DIR}" "${PROJECT_BINARY_DIR}") +configure_file(PythonQtConfig.cmake.in "${PROJECT_BINARY_DIR}/${PythonQt}Config.cmake" @ONLY) +# install tree +set(INCLUDE_DIRS "${CMAKE_INSTALL_PREFIX}/include/PythonQt") +configure_file(PythonQtConfig.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${PythonQt}Config.cmake" @ONLY) +# both +configure_file(PythonQtConfigVersion.cmake.in "${PROJECT_BINARY_DIR}/${PythonQt}ConfigVersion.cmake" @ONLY) + +install(EXPORT ${PythonQt}Targets DESTINATION "${LIB_CMAKE_PATH}" COMPONENT core-dev) +install(FILES ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${PythonQt}Config.cmake + ${PROJECT_BINARY_DIR}/${PythonQt}ConfigVersion.cmake + DESTINATION "${LIB_CMAKE_PATH}" COMPONENT core-dev) + diff --git a/src/PythonQtConfig.cmake.in b/src/PythonQtConfig.cmake.in new file mode 100644 index 0000000..86c55b0 --- /dev/null +++ b/src/PythonQtConfig.cmake.in @@ -0,0 +1,22 @@ +# - Config file for the PythonQt package +# It defines the following variables +# PythonQt - the PythonQt core target (PythonQt PythonQt_3 PythonQt5 PythonQt5_3) +# PythonQt_INCLUDE_DIRS - include directories for PythonQt +# PythonQt_LIBRARIES - libraries to link against + +set(PythonQt @PythonQt@) +set(PythonQt_Qt5 @PythonQt_Qt5@) +set(PythonQt_Python3 @PythonQt_Python3@) +set(PythonQt_Python @PYTHON_VERSION@) + +# Compute paths +get_filename_component(PYTHONQT_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +set(PythonQt_INCLUDE_DIRS "@INCLUDE_DIRS@") + +# Our library dependencies (contains definitions for IMPORTED targets) +if(NOT TARGET @PythonQt@) + include("${PYTHONQT_CMAKE_DIR}/@PythonQt@Targets.cmake") +endif() + +# These are IMPORTED targets created by @PythonQt@Targets.cmake +set(PythonQt_LIBRARIES @PythonQt@) diff --git a/src/PythonQtConfigVersion.cmake.in b/src/PythonQtConfigVersion.cmake.in new file mode 100644 index 0000000..c3ef74a --- /dev/null +++ b/src/PythonQtConfigVersion.cmake.in @@ -0,0 +1,11 @@ +set(PACKAGE_VERSION "@PythonQt_VERSION@") + +# Check whether the requested PACKAGE_FIND_VERSION is compatible +if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") + set(PACKAGE_VERSION_COMPATIBLE FALSE) +else() + set(PACKAGE_VERSION_COMPATIBLE TRUE) + if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") + set(PACKAGE_VERSION_EXACT TRUE) + endif() +endif()