CMakeLists.txt 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. cmake_minimum_required(VERSION 3.0.2)
  2. set(CMAKE_DISABLE_SOURCE_CHANGES ON) # Must go before project() below
  3. set(CMAKE_DISABLE_IN_SOURCE_BUILD ON) # Must go before project() below
  4. if(CMAKE_VERSION VERSION_GREATER "3.11" OR POLICY CMP0072)
  5. # Prefer GLVND over libGL when available; this will be enabled by default
  6. # once the minimum CMake version is at least 3.11.
  7. cmake_policy(SET CMP0072 NEW)
  8. endif()
  9. if(CMAKE_VERSION VERSION_GREATER "3.12" OR POLICY CMP0074)
  10. # Needed for THIRDPARTY_DIRECTORY support; this will be enabled by default
  11. # once the minimum CMake version is at least 3.12.
  12. cmake_policy(SET CMP0074 NEW)
  13. endif()
  14. if(POLICY CMP0091)
  15. # Needed for CMake to pass /MD flag properly with non-VC generators.
  16. cmake_policy(SET CMP0091 NEW)
  17. endif()
  18. # Determine whether we are using a multi-config generator.
  19. if(CMAKE_VERSION VERSION_GREATER "3.8")
  20. get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  21. else()
  22. message(WARNING "Multi-configuration builds may not work properly when using
  23. a CMake < 3.9. Making a guess if this is a multi-config generator.")
  24. if(DEFINED CMAKE_CONFIGURATION_TYPES)
  25. set(IS_MULTICONFIG ON)
  26. else()
  27. set(IS_MULTICONFIG OFF)
  28. endif()
  29. endif()
  30. # Define the type of build we are setting up.
  31. set(_configs Standard Release RelWithDebInfo Debug MinSizeRel)
  32. if(CMAKE_CXX_COMPILER_ID MATCHES "(AppleClang|Clang|GCC)")
  33. list(APPEND _configs Coverage)
  34. endif()
  35. if(IS_MULTICONFIG)
  36. message(STATUS "Using multi-configuration generator")
  37. else()
  38. # Set the default CMAKE_BUILD_TYPE before calling project().
  39. if(NOT CMAKE_BUILD_TYPE)
  40. set(CMAKE_BUILD_TYPE Standard CACHE STRING "Choose the type of build." FORCE)
  41. message(STATUS "Using default build type ${CMAKE_BUILD_TYPE}")
  42. else()
  43. message(STATUS "Using build type ${CMAKE_BUILD_TYPE}")
  44. endif()
  45. set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${_configs})
  46. endif()
  47. # Figure out the version
  48. set(_s "[\\t ]*") # CMake doesn't support \s*
  49. file(STRINGS "setup.cfg" _version REGEX "^version${_s}=${_s}")
  50. string(REGEX REPLACE "^.*=${_s}" "" _version "${_version}")
  51. project(Panda3D VERSION ${_version})
  52. unset(_version)
  53. unset(_s)
  54. enable_testing()
  55. string(REPLACE "$(EFFECTIVE_PLATFORM_NAME)" "" PANDA_CFG_INTDIR "${CMAKE_CFG_INTDIR}")
  56. # Add generic modules to cmake module path,
  57. # and add Panda3D specific modules to cmake module path
  58. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/")
  59. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/macros/")
  60. if(CMAKE_VERSION VERSION_GREATER "3.8")
  61. # When using the Xcode generator, don't append the platform name to the
  62. # intermediate configuration directory.
  63. set_property(GLOBAL PROPERTY XCODE_EMIT_EFFECTIVE_PLATFORM_NAME OFF)
  64. endif()
  65. # Include modules builtin to CMake
  66. include(GNUInstallDirs) # Defines CMAKE_INSTALL_<dir> variables
  67. # Include global modules needed for configure scripts
  68. include(PackageConfig) # Defines package_option
  69. include(PerConfigOption) # Defines per_config_option
  70. # Configure Panda3D
  71. include(dtool/CompilerFlags.cmake)
  72. include(dtool/PandaVersion.cmake)
  73. include(dtool/Package.cmake)
  74. include(dtool/Config.cmake)
  75. # Include global modules
  76. include(AddBisonTarget) # Defines add_bison_target function
  77. include(AddFlexTarget) # Defines add_flex_target function
  78. include(BuildMetalib) # Defines add_component_library AND add_metalib
  79. include(CompositeSources) # Defines composite_sources function
  80. include(Python) # Defines add_python_target AND install_python_package
  81. include(Interrogate) # Defines target_interrogate AND add_python_module
  82. include(RunPzip) # Defines run_pzip function
  83. include(Versioning) # Hooks 'add_library' to apply VERSION/SOVERSION
  84. # Determine which trees to build.
  85. option(BUILD_DTOOL "Build the dtool source tree." ON)
  86. option(BUILD_PANDA "Build the panda source tree." ON)
  87. option(BUILD_DIRECT "Build the direct source tree." ON)
  88. option(BUILD_PANDATOOL "Build the pandatool source tree." ON)
  89. option(BUILD_CONTRIB "Build the contrib source tree." ON)
  90. option(BUILD_MODELS "Build/install the built-in models." ON)
  91. # Include Panda3D packages
  92. if(BUILD_DTOOL)
  93. add_subdirectory(dtool "${CMAKE_BINARY_DIR}/dtool")
  94. endif()
  95. if(BUILD_PANDA)
  96. add_subdirectory(panda "${CMAKE_BINARY_DIR}/panda")
  97. endif()
  98. if(BUILD_DIRECT)
  99. add_subdirectory(direct "${CMAKE_BINARY_DIR}/direct")
  100. endif()
  101. if(BUILD_PANDATOOL)
  102. add_subdirectory(pandatool "${CMAKE_BINARY_DIR}/pandatool")
  103. endif()
  104. if(BUILD_CONTRIB)
  105. add_subdirectory(contrib "${CMAKE_BINARY_DIR}/contrib")
  106. endif()
  107. if(BUILD_MODELS)
  108. run_pzip(models
  109. "${CMAKE_CURRENT_SOURCE_DIR}/models/"
  110. "${PROJECT_BINARY_DIR}/${PANDA_CFG_INTDIR}/models"
  111. *.egg)
  112. run_pzip(dmodels
  113. "${CMAKE_CURRENT_SOURCE_DIR}/dmodels/src/"
  114. "${PROJECT_BINARY_DIR}/${PANDA_CFG_INTDIR}/models"
  115. *.egg)
  116. add_custom_command(TARGET models
  117. POST_BUILD
  118. COMMAND ${CMAKE_COMMAND}
  119. -DSOURCE="${CMAKE_CURRENT_SOURCE_DIR}/models/maps/"
  120. -DDESTINATION="${PANDA_OUTPUT_DIR}/models/maps"
  121. -P ${PROJECT_SOURCE_DIR}/cmake/scripts/CopyPattern.cmake
  122. COMMENT "Copying models/maps")
  123. add_custom_command(TARGET dmodels
  124. POST_BUILD
  125. COMMAND ${CMAKE_COMMAND}
  126. -DSOURCE="${CMAKE_CURRENT_SOURCE_DIR}/dmodels/src/"
  127. -DDESTINATION="${PANDA_OUTPUT_DIR}/models"
  128. -DFILES_MATCHING="PATTERN;*.rgb;PATTERN;*.png;PATTERN;*.jpg;PATTERN;*.wav"
  129. -P ${PROJECT_SOURCE_DIR}/cmake/scripts/CopyPattern.cmake
  130. COMMENT "Copying dmodels' assets")
  131. install(DIRECTORY "${PANDA_OUTPUT_DIR}/models"
  132. COMPONENT Models DESTINATION ${CMAKE_INSTALL_DATADIR}/panda3d)
  133. endif()
  134. if(INTERROGATE_PYTHON_INTERFACE)
  135. # If we built the Python interface, run the test suite. Note, we do NOT test
  136. # for pytest before adding this test. If the user doesn't have pytest, we'd
  137. # like for the tests to fail.
  138. # In the Coverage configuration, we also require pytest-cov
  139. add_test(NAME pytest
  140. COMMAND "${PYTHON_EXECUTABLE}" -m pytest "${PROJECT_SOURCE_DIR}/tests"
  141. $<$<CONFIG:Coverage>:--cov=.>
  142. WORKING_DIRECTORY "${PANDA_OUTPUT_DIR}")
  143. endif()
  144. # Generate the Panda3DConfig.cmake file so find_package(Panda3D) works, and
  145. # also register the build directory with CMake's package registry.
  146. file(COPY "${PROJECT_SOURCE_DIR}/cmake/install/Panda3DConfig.cmake"
  147. DESTINATION "${PROJECT_BINARY_DIR}")
  148. install(FILES "${PROJECT_SOURCE_DIR}/cmake/install/Panda3DConfig.cmake"
  149. DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Panda3D")
  150. include(CMakePackageConfigHelpers)
  151. write_basic_package_version_file(
  152. "${PROJECT_BINARY_DIR}/Panda3DConfigVersion.cmake"
  153. VERSION "${PROJECT_VERSION}"
  154. COMPATIBILITY AnyNewerVersion)
  155. install(FILES "${PROJECT_BINARY_DIR}/Panda3DConfigVersion.cmake"
  156. DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Panda3D")
  157. if(NOT CMAKE_CROSSCOMPILING)
  158. export(PACKAGE Panda3D)
  159. endif()