Warning, /education/gcompris/cmake/box2d.cmake is written in an unsupported language. File is not indexed.
0001 #============================================================================= 0002 # SPDX-FileCopyrightText: 2018 Johnny Jazeix <jazeix@gmail.com> 0003 # 0004 # SPDX-License-Identifier: BSD-3-Clause 0005 #============================================================================= 0006 0007 set(QML_BOX2D_MODULE "auto" CACHE STRING "Policy for qml-box2d module [auto|submodule|system|disabled]") 0008 0009 if(NOT ${QML_BOX2D_MODULE} STREQUAL "disabled") 0010 include(qt_helper) 0011 0012 getQtQmlPath(_qt_qml_system_path) 0013 set(_box2d_system_dir "${_qt_qml_system_path}/Box2D.2.0") 0014 0015 if(${QML_BOX2D_MODULE} STREQUAL "submodule") 0016 message(STATUS "Building qml-box2d module from submodule") 0017 set(_need_box2d_submodule "TRUE") 0018 else() 0019 # try to find module in system scope 0020 find_library(QML_BOX2D_LIBRARY NAMES Box2D libBox2D PATHS ${_box2d_system_dir} NO_DEFAULT_PATH) 0021 # Look in default path if not found 0022 if(NOT QML_BOX2D_LIBRARY AND NOT "${CMAKE_FIND_ROOT_PATH}" STREQUAL "") 0023 # Remove the root path to look for the library 0024 set(_box2d_without_cmake_find_root_path) 0025 string(REPLACE "${CMAKE_FIND_ROOT_PATH}" "" _box2d_without_cmake_find_root_path ${_box2d_system_dir}) 0026 find_library(QML_BOX2D_LIBRARY NAMES Box2D libBox2D PATHS ${_box2d_without_cmake_find_root_path}) 0027 endif() 0028 0029 if(QML_BOX2D_LIBRARY) 0030 message(STATUS "Using system qml-box2d plugin at ${QML_BOX2D_LIBRARY}") 0031 # for packaging builds, copy the module manually to the correct location 0032 if(ANDROID) 0033 file(COPY ${_box2d_system_dir}/qmldir ${QML_BOX2D_LIBRARY} DESTINATION lib/qml/Box2D.2.0) 0034 endif() 0035 # FIXME: add others as needed 0036 else() 0037 if(${QML_BOX2D_MODULE} STREQUAL "auto") 0038 message(STATUS "Did not find the qml-box2d module in system scope, falling back to submodule build ...") 0039 set(_need_box2d_submodule "TRUE") 0040 else() 0041 message(FATAL_ERROR "Did not find the qml-box2d module in system scope and submodule build was not requested. Can't continue!") 0042 endif() 0043 endif() 0044 endif() 0045 0046 if(_need_box2d_submodule) 0047 # build qml-box2d ourselves from submodule 0048 include(ExternalProject) 0049 0050 get_property(_qmake_program TARGET Qt5::qmake PROPERTY IMPORT_LOCATION) 0051 0052 set(_box2d_source_dir ${CMAKE_CURRENT_SOURCE_DIR}/external/qml-box2d) 0053 if(WIN32) 0054 set(_box2d_library_dir "release/") 0055 set(_box2d_library_file "Box2D.dll") 0056 elseif(CMAKE_HOST_APPLE) 0057 set(_box2d_library_dir "") 0058 set(_box2d_library_file "libBox2D.dylib") 0059 elseif(ANDROID AND Qt5Widgets_VERSION VERSION_GREATER_EQUAL "5.14.0") 0060 set(_box2d_library_dir "") 0061 set(_box2d_library_file "libBox2D_${ANDROID_ABI}.so") 0062 else() 0063 set(_box2d_library_dir "") 0064 set(_box2d_library_file "libBox2D.so") 0065 endif() 0066 set(_box2d_install_dir ${CMAKE_CURRENT_BINARY_DIR}/lib/qml/Box2D.2.0) 0067 # make sure submodule is up2date 0068 find_package(Git) 0069 if(GIT_FOUND) 0070 execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) 0071 endif() 0072 0073 # for visual studio, we need to create a vcxproj 0074 if(WIN32 AND NOT MINGW) 0075 set(_qmake_options -spec win32-msvc -tp vc) 0076 else() 0077 set(_qmake_options "") 0078 endif() 0079 set(BOX2D_MAKE_PROGRAM ${CMAKE_MAKE_PROGRAM}) 0080 # Ninja is not supported by qmake. 0081 # In case Ninja is set as generator, use make on Linux, nmake on Windows 0082 if(${CMAKE_GENERATOR} MATCHES "Ninja") 0083 if(WIN32) 0084 set(BOX2D_MAKE_PROGRAM "nmake") 0085 else() 0086 set(BOX2D_MAKE_PROGRAM "make") 0087 endif() 0088 endif() 0089 0090 if(ANDROID AND Qt5Widgets_VERSION VERSION_GREATER_EQUAL "5.14.0") 0091 # Only build the necessary architecture for box2d 0092 # Capitalize first letter of the abi... 0093 string(SUBSTRING ${ANDROID_ABI} 0 1 FIRST_LETTER) 0094 string(TOUPPER ${FIRST_LETTER} FIRST_LETTER) 0095 string(REGEX REPLACE "^.(.*)" "${FIRST_LETTER}\\1" ANDROID_ABI_CAP "${ANDROID_ABI}") 0096 set(BOX2D_MAKE_PROGRAM ${BOX2D_MAKE_PROGRAM} -f Makefile.${ANDROID_ABI_CAP}) 0097 # I didn't find a better way to copy the libraries to the lib folder only on Android when doing an aab package... 0098 set(EXTRA_INSTALL_ANDROID_BOX2D ${CMAKE_COMMAND} -E make_directory ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} && ${CMAKE_COMMAND} -E copy ${_box2d_library_dir}${_box2d_library_file} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} && ) 0099 endif() 0100 0101 ExternalProject_Add(qml_box2d 0102 DOWNLOAD_COMMAND "" 0103 SOURCE_DIR ${_box2d_source_dir} 0104 CONFIGURE_COMMAND ${_qmake_program} ${_qmake_options} ${_box2d_source_dir}/box2d.pro 0105 BUILD_COMMAND ${BOX2D_MAKE_PROGRAM} 0106 INSTALL_DIR ${_box2d_install_dir} 0107 INSTALL_COMMAND ${EXTRA_INSTALL_ANDROID_BOX2D} ${CMAKE_COMMAND} -E copy ${_box2d_library_dir}${_box2d_library_file} ${_box2d_source_dir}/qmldir ${_box2d_install_dir} 0108 ) 0109 0110 add_library(qml-box2d SHARED IMPORTED) 0111 set_target_properties(qml-box2d PROPERTIES IMPORTED_LOCATION ${_box2d_install_dir}/${_box2d_library_file}) 0112 0113 if(APPLE) 0114 install(DIRECTORY ${_box2d_install_dir} DESTINATION gcompris-qt.app/Contents/lib/qml) 0115 else() 0116 install(DIRECTORY ${_box2d_install_dir} DESTINATION lib/qml) 0117 endif() 0118 endif() 0119 endif()