You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

prebuild.cmake 3.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. ##
  2. ## Author: Hank Anderson <hank@statease.com>
  3. ## Description: Ported from OpenBLAS/Makefile.prebuild
  4. ## This is triggered by system.cmake and runs before any of the code is built.
  5. ## Creates config.h and Makefile.conf by first running the c_check perl script (which creates those files).
  6. ## Next it runs f_check and appends some fortran information to the files.
  7. ## Finally it runs getarch and getarch_2nd for even more environment information.
  8. # CMake vars set by this file:
  9. # CORE
  10. # LIBCORE
  11. # NUM_CORES
  12. # HAVE_MMX
  13. # HAVE_SSE
  14. # HAVE_SSE2
  15. # HAVE_SSE3
  16. # MAKE
  17. # SGEMM_UNROLL_M
  18. # SGEMM_UNROLL_N
  19. # DGEMM_UNROLL_M
  20. # DGEMM_UNROLL_M
  21. # QGEMM_UNROLL_N
  22. # QGEMM_UNROLL_N
  23. # CGEMM_UNROLL_M
  24. # CGEMM_UNROLL_M
  25. # ZGEMM_UNROLL_N
  26. # ZGEMM_UNROLL_N
  27. # XGEMM_UNROLL_M
  28. # XGEMM_UNROLL_N
  29. # CGEMM3M_UNROLL_M
  30. # CGEMM3M_UNROLL_N
  31. # ZGEMM3M_UNROLL_M
  32. # ZGEMM3M_UNROLL_M
  33. # XGEMM3M_UNROLL_N
  34. # XGEMM3M_UNROLL_N
  35. # CPUIDEMU = ../../cpuid/table.o
  36. if (DEFINED CPUIDEMU)
  37. set(EXFLAGS "-DCPUIDEMU -DVENDOR=99")
  38. endif ()
  39. if (DEFINED TARGET_CORE)
  40. # set the C flags for just this file
  41. set(GETARCH2_FLAGS "-DBUILD_KERNEL")
  42. set(TARGET_MAKE "Makefile_kernel.conf")
  43. set(TARGET_CONF "config_kernel.h")
  44. else()
  45. set(TARGET_MAKE "Makefile.conf")
  46. set(TARGET_CONF "config.h")
  47. endif ()
  48. include("${PROJECT_SOURCE_DIR}/cmake/c_check.cmake")
  49. if (NOT NOFORTRAN)
  50. include("${PROJECT_SOURCE_DIR}/cmake/f_check.cmake")
  51. endif ()
  52. # compile getarch
  53. set(GETARCH_SRC
  54. ${PROJECT_SOURCE_DIR}/getarch.c
  55. ${CPUIDEMO}
  56. )
  57. if (NOT MSVC)
  58. list(APPEND GETARCH_SRC ${PROJECT_SOURCE_DIR}/cpuid.S)
  59. endif ()
  60. if (MSVC)
  61. #Use generic for MSVC now
  62. set(GETARCH_FLAGS ${GETARCH_FLAGS} -DFORCE_GENERIC)
  63. endif()
  64. set(GETARCH_DIR "${PROJECT_BINARY_DIR}/getarch_build")
  65. set(GETARCH_BIN "getarch${CMAKE_EXECUTABLE_SUFFIX}")
  66. file(MAKE_DIRECTORY ${GETARCH_DIR})
  67. try_compile(GETARCH_RESULT ${GETARCH_DIR}
  68. SOURCES ${GETARCH_SRC}
  69. COMPILE_DEFINITIONS ${EXFLAGS} ${GETARCH_FLAGS} -I${PROJECT_SOURCE_DIR}
  70. OUTPUT_VARIABLE GETARCH_LOG
  71. COPY_FILE ${PROJECT_BINARY_DIR}/${GETARCH_BIN}
  72. )
  73. message(STATUS "Running getarch")
  74. # use the cmake binary w/ the -E param to run a shell command in a cross-platform way
  75. execute_process(COMMAND ${PROJECT_BINARY_DIR}/${GETARCH_BIN} 0 OUTPUT_VARIABLE GETARCH_MAKE_OUT)
  76. execute_process(COMMAND ${PROJECT_BINARY_DIR}/${GETARCH_BIN} 1 OUTPUT_VARIABLE GETARCH_CONF_OUT)
  77. message(STATUS "GETARCH results:\n${GETARCH_MAKE_OUT}")
  78. # append config data from getarch to the TARGET file and read in CMake vars
  79. file(APPEND ${TARGET_CONF} ${GETARCH_CONF_OUT})
  80. ParseGetArchVars(${GETARCH_MAKE_OUT})
  81. set(GETARCH2_DIR "${PROJECT_BINARY_DIR}/getarch2_build")
  82. set(GETARCH2_BIN "getarch_2nd${CMAKE_EXECUTABLE_SUFFIX}")
  83. file(MAKE_DIRECTORY ${GETARCH2_DIR})
  84. try_compile(GETARCH2_RESULT ${GETARCH2_DIR}
  85. SOURCES ${PROJECT_SOURCE_DIR}/getarch_2nd.c
  86. COMPILE_DEFINITIONS ${EXFLAGS} ${GETARCH_FLAGS} ${GETARCH2_FLAGS} -I${PROJECT_SOURCE_DIR}
  87. OUTPUT_VARIABLE GETARCH2_LOG
  88. COPY_FILE ${PROJECT_BINARY_DIR}/${GETARCH2_BIN}
  89. )
  90. # use the cmake binary w/ the -E param to run a shell command in a cross-platform way
  91. execute_process(COMMAND ${PROJECT_BINARY_DIR}/${GETARCH2_BIN} 0 OUTPUT_VARIABLE GETARCH2_MAKE_OUT)
  92. execute_process(COMMAND ${PROJECT_BINARY_DIR}/${GETARCH2_BIN} 1 OUTPUT_VARIABLE GETARCH2_CONF_OUT)
  93. # append config data from getarch_2nd to the TARGET file and read in CMake vars
  94. file(APPEND ${TARGET_CONF} ${GETARCH2_CONF_OUT})
  95. ParseGetArchVars(${GETARCH2_MAKE_OUT})