LocalSetup.cmake 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. #
  2. # LocalSetup.cmake
  3. #
  4. # This file contains further instructions to set up the DTOOL package
  5. # when using CMake. In particular, it creates the dtool_config.h
  6. # file based on the user's selected configure variables.
  7. #
  8. include(CheckCXXCompilerFlag)
  9. include(CheckCXXSourceCompiles)
  10. include(CheckCSourceRuns)
  11. include(CheckIncludeFileCXX)
  12. include(CheckFunctionExists)
  13. include(CheckTypeSize)
  14. include(TestBigEndian)
  15. include(TestForSTDNamespace)
  16. # Check if this is a big-endian system.
  17. test_big_endian(WORDS_BIGENDIAN)
  18. # Define if we have lockf().
  19. check_cxx_source_compiles("
  20. #include <unistd.h>
  21. int main(int argc, char *argv[]) { lockf(0, F_LOCK, 0); return 0; }
  22. " PHAVE_LOCKF)
  23. # Define if we can trust the compiler not to insert extra bytes in
  24. # structs between base structs and derived structs.
  25. check_c_source_runs("
  26. struct A { int a; };
  27. struct B : public A { int b; };
  28. int main(int argc, char *argv[]) {
  29. struct B i;
  30. if ((size_t) &(i.b) == ((size_t) &(i.a)) + sizeof(struct A)) {
  31. return 0;
  32. } else {
  33. return 1;
  34. }
  35. }" SIMPLE_STRUCT_POINTERS)
  36. # Define if we have STL hash_map etc. available.
  37. # We're not using this functionality at the moment, it seems.
  38. set(HAVE_STL_HASH OFF)
  39. # Check if we have a gettimeofday() function.
  40. check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
  41. # Define if gettimeofday() takes only one parameter.
  42. check_cxx_source_compiles("
  43. #include <sys/time.h>
  44. int main(int argc, char *argv[]) {
  45. struct timeval tv;
  46. int result;
  47. result = gettimeofday(&tv);
  48. return 0;
  49. }" GETTIMEOFDAY_ONE_PARAM)
  50. # Check if we have getopt.
  51. check_function_exists(getopt HAVE_GETOPT)
  52. check_function_exists(getopt_long_only HAVE_GETOPT_LONG_ONLY)
  53. check_include_file_cxx(getopt.h PHAVE_GETOPT_H)
  54. # Define if you have ioctl(TIOCGWINSZ) to determine terminal width.
  55. #XXX can we make a test case for this that isn't dependent on
  56. # the current terminal? It might also be useful for Cygwin users.
  57. if(UNIX)
  58. set(IOCTL_TERMINAL_WIDTH 1)
  59. endif()
  60. # Do the system headers define key ios typedefs like ios::openmode
  61. # and ios::fmtflags?
  62. check_cxx_source_compiles("
  63. #include <ios>
  64. std::ios::openmode foo;
  65. std::ios::fmtflags bar;
  66. int main(int argc, char *argv[]) { return 0; }
  67. " HAVE_IOS_TYPEDEFS)
  68. # Define if the C++ iostream library defines ios::binary.
  69. check_cxx_source_compiles("
  70. #include <ios>
  71. std::ios::openmode binary = std::ios::binary;
  72. int main(int argc, char *argv[]) { return 0; }
  73. " HAVE_IOS_BINARY)
  74. # Can we safely call getenv() at static init time?
  75. if(WIN32 OR UNIX)
  76. set(STATIC_INIT_GETENV 1)
  77. endif()
  78. # Can we read the file /proc/self/[*] to determine our
  79. # environment variables at static init time?
  80. if(IS_LINUX)
  81. set(HAVE_PROC_SELF_EXE 1)
  82. set(HAVE_PROC_SELF_MAPS 1)
  83. set(HAVE_PROC_SELF_ENVIRON 1)
  84. set(HAVE_PROC_SELF_CMDLINE 1)
  85. endif()
  86. if(IS_FREEBSD)
  87. set(HAVE_PROC_CURPROC_FILE 1)
  88. set(HAVE_PROC_CURPROC_MAP 1)
  89. set(HAVE_PROC_CURPROC_CMDLINE 1)
  90. endif()
  91. # Do we have a global pair of argc/argv variables that we can read at
  92. # static init time? Should we prototype them? What are they called?
  93. if(WIN32)
  94. set(HAVE_GLOBAL_ARGV ON)
  95. set(PROTOTYPE_GLOBAL_ARGV OFF)
  96. set(GLOBAL_ARGV __argv)
  97. set(GLOBAL_ARGC __argc)
  98. endif()
  99. # Do we have all these header files?
  100. check_include_file_cxx(io.h PHAVE_IO_H)
  101. check_include_file_cxx(iostream PHAVE_IOSTREAM)
  102. check_include_file_cxx(malloc.h PHAVE_MALLOC_H)
  103. check_include_file_cxx(sys/malloc.h PHAVE_SYS_MALLOC_H)
  104. check_include_file_cxx(alloca.h PHAVE_ALLOCA_H)
  105. check_include_file_cxx(locale.h PHAVE_LOCALE_H)
  106. check_include_file_cxx(string.h PHAVE_STRING_H)
  107. check_include_file_cxx(stdlib.h PHAVE_STDLIB_H)
  108. check_include_file_cxx(limits.h PHAVE_LIMITS_H)
  109. check_include_file_cxx(sstream PHAVE_SSTREAM)
  110. check_include_file_cxx(new PHAVE_NEW)
  111. check_include_file_cxx(sys/types.h PHAVE_SYS_TYPES_H)
  112. check_include_file_cxx(sys/time.h PHAVE_SYS_TIME_H)
  113. check_include_file_cxx(unistd.h PHAVE_UNISTD_H)
  114. check_include_file_cxx(utime.h PHAVE_UTIME_H)
  115. check_include_file_cxx(glob.h PHAVE_GLOB_H)
  116. check_include_file_cxx(dirent.h PHAVE_DIRENT_H)
  117. check_include_file_cxx(ucontext.h PHAVE_UCONTEXT_H) #TODO doesn't work on OSX, use sys/ucontext.h
  118. check_include_file_cxx(linux/input.h PHAVE_LINUX_INPUT_H)
  119. check_include_file_cxx(stdint.h PHAVE_STDINT_H)
  120. check_include_file_cxx(execinfo.h PHAVE_EXECINFO_H)
  121. # Do we have Posix threads?
  122. #set(HAVE_POSIX_THREADS ${CMAKE_USE_PTHREADS_INIT})
  123. # Do we have SSE2 support?
  124. if(MSVC)
  125. check_cxx_source_compiles("
  126. #if !defined(__SSE2__) && !defined(_M_X64) && !defined(_M_AMD64) && !defined(_M_IX86_FP)
  127. #error no
  128. #endif
  129. int main (int argc, char *argv[]) {
  130. return 0;
  131. }
  132. " HAVE_SSE2)
  133. else()
  134. check_cxx_compiler_flag(-msse2 HAVE_SSE2)
  135. endif()
  136. # Set LINK_ALL_STATIC if we're building everything as static libraries.
  137. # Also set the library type used for "modules" appropriately.
  138. if(BUILD_SHARED_LIBS)
  139. set(LINK_ALL_STATIC OFF)
  140. set(MODULE_TYPE "MODULE"
  141. CACHE INTERNAL "" FORCE)
  142. else()
  143. set(LINK_ALL_STATIC ON)
  144. set(MODULE_TYPE "STATIC"
  145. CACHE INTERNAL "" FORCE)
  146. endif()
  147. # Now go through all the packages and report whether we have them.
  148. show_packages()
  149. message("")
  150. if(HAVE_PYTHON AND NOT PYTHON_FOUND)
  151. message(SEND_ERROR "Configured Panda with Python bindings, but no Python library found. Disable HAVE_PYTHON to continue.")
  152. elseif(INTERROGATE_PYTHON_INTERFACE)
  153. message("Compilation will generate Python interfaces for Python ${PYTHON_VERSION_STRING}.")
  154. else()
  155. message("Configuring Panda WITHOUT Python interfaces.")
  156. endif()
  157. if(HAVE_THREADS)
  158. if(SIMPLE_THREADS)
  159. message("Compilation will include simulated threading support.")
  160. elseif(DO_PIPELINING)
  161. message("Compilation will include full, pipelined threading support.")
  162. else()
  163. message("Compilation will include nonpipelined threading support.")
  164. endif()
  165. else()
  166. message("Configuring Panda without threading support.")
  167. endif()
  168. message("")
  169. message("See dtool_config.h for more details about the specified configuration.")
  170. message("")
  171. # Generate dtool_config.h
  172. if(IS_MULTICONFIG)
  173. foreach(config ${CMAKE_CONFIGURATION_TYPES})
  174. string(TOUPPER "${config}" config_upper)
  175. foreach(option ${_PER_CONFIG_OPTIONS})
  176. # Check for the presence of a config-specific option, and override what's
  177. # in the cache if there is.
  178. if(DEFINED "${option}_${config_upper}")
  179. set(${option} ${${option}_${config_upper}})
  180. else()
  181. message(FATAL_ERROR "${option}_${config_upper} is not defined")
  182. endif()
  183. endforeach(option)
  184. # Generate a dtool_config.h for this specific config
  185. configure_file(dtool_config.h.in "${PROJECT_BINARY_DIR}/${config}/include/dtool_config.h")
  186. # unset() does not unset CACHE variables by default, just normal variables.
  187. # By doing this we're reverting back to what was in the cache.
  188. foreach(option ${_PER_CONFIG_OPTIONS})
  189. unset(${option})
  190. endforeach(option)
  191. endforeach(config)
  192. else()
  193. # Just configure things like normal.
  194. configure_file(dtool_config.h.in "${PROJECT_BINARY_DIR}/include/dtool_config.h")
  195. endif()
  196. install(FILES "${PANDA_OUTPUT_DIR}/include/dtool_config.h"
  197. COMPONENT CoreDevel
  198. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/panda3d)
  199. # Generate the package configuration file
  200. export_packages("${PROJECT_BINARY_DIR}/Panda3DPackages.cmake")
  201. install(FILES "${PROJECT_BINARY_DIR}/Panda3DPackages.cmake"
  202. COMPONENT CoreDevel
  203. DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Panda3D")