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 5.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. ## Then it runs getarch and getarch_2nd for even more environment information.
  8. ## Finally it builds gen_config_h for use at build time to generate config.h.
  9. # CMake vars set by this file:
  10. # CORE
  11. # LIBCORE
  12. # NUM_CORES
  13. # HAVE_MMX
  14. # HAVE_SSE
  15. # HAVE_SSE2
  16. # HAVE_SSE3
  17. # MAKE
  18. # SGEMM_UNROLL_M
  19. # SGEMM_UNROLL_N
  20. # DGEMM_UNROLL_M
  21. # DGEMM_UNROLL_M
  22. # QGEMM_UNROLL_N
  23. # QGEMM_UNROLL_N
  24. # CGEMM_UNROLL_M
  25. # CGEMM_UNROLL_M
  26. # ZGEMM_UNROLL_N
  27. # ZGEMM_UNROLL_N
  28. # XGEMM_UNROLL_M
  29. # XGEMM_UNROLL_N
  30. # CGEMM3M_UNROLL_M
  31. # CGEMM3M_UNROLL_N
  32. # ZGEMM3M_UNROLL_M
  33. # ZGEMM3M_UNROLL_M
  34. # XGEMM3M_UNROLL_N
  35. # XGEMM3M_UNROLL_N
  36. # CPUIDEMU = ../../cpuid/table.o
  37. if (DEFINED CPUIDEMU)
  38. set(EXFLAGS "-DCPUIDEMU -DVENDOR=99")
  39. endif ()
  40. if (DEFINED TARGET_CORE)
  41. # set the C flags for just this file
  42. set(GETARCH2_FLAGS "-DBUILD_KERNEL")
  43. set(TARGET_MAKE "Makefile_kernel.conf")
  44. set(TARGET_CONF "config_kernel.h")
  45. set(TARGET_CONF_DIR ${PROJECT_BINARY_DIR}/kernel_config/${TARGET_CORE})
  46. else()
  47. set(TARGET_MAKE "Makefile.conf")
  48. set(TARGET_CONF "config.h")
  49. set(TARGET_CONF_DIR ${PROJECT_BINARY_DIR})
  50. endif ()
  51. set(TARGET_CONF_TEMP "${PROJECT_BINARY_DIR}/${TARGET_CONF}.tmp")
  52. include("${PROJECT_SOURCE_DIR}/cmake/c_check.cmake")
  53. if (NOT NOFORTRAN)
  54. include("${PROJECT_SOURCE_DIR}/cmake/f_check.cmake")
  55. endif ()
  56. # compile getarch
  57. set(GETARCH_SRC
  58. ${PROJECT_SOURCE_DIR}/getarch.c
  59. ${CPUIDEMO}
  60. )
  61. if (NOT MSVC)
  62. list(APPEND GETARCH_SRC ${PROJECT_SOURCE_DIR}/cpuid.S)
  63. endif ()
  64. if (MSVC)
  65. #Use generic for MSVC now
  66. set(GETARCH_FLAGS ${GETARCH_FLAGS} -DFORCE_GENERIC)
  67. endif()
  68. if ("${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore")
  69. # disable WindowsStore strict CRT checks
  70. set(GETARCH_FLAGS ${GETARCH_FLAGS} -D_CRT_SECURE_NO_WARNINGS)
  71. endif ()
  72. set(GETARCH_DIR "${PROJECT_BINARY_DIR}/getarch_build")
  73. set(GETARCH_BIN "getarch${CMAKE_EXECUTABLE_SUFFIX}")
  74. file(MAKE_DIRECTORY ${GETARCH_DIR})
  75. configure_file(${TARGET_CONF_TEMP} ${GETARCH_DIR}/${TARGET_CONF} COPYONLY)
  76. if (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore")
  77. try_compile(GETARCH_RESULT ${GETARCH_DIR}
  78. SOURCES ${GETARCH_SRC}
  79. COMPILE_DEFINITIONS ${EXFLAGS} ${GETARCH_FLAGS} -I${GETARCH_DIR} -I${PROJECT_SOURCE_DIR} -I${PROJECT_BINARY_DIR}
  80. OUTPUT_VARIABLE GETARCH_LOG
  81. COPY_FILE ${PROJECT_BINARY_DIR}/${GETARCH_BIN}
  82. )
  83. if (NOT ${GETARCH_RESULT})
  84. MESSAGE(FATAL_ERROR "Compiling getarch failed ${GETARCH_LOG}")
  85. endif ()
  86. endif ()
  87. message(STATUS "Running getarch")
  88. # use the cmake binary w/ the -E param to run a shell command in a cross-platform way
  89. execute_process(COMMAND ${PROJECT_BINARY_DIR}/${GETARCH_BIN} 0 OUTPUT_VARIABLE GETARCH_MAKE_OUT)
  90. execute_process(COMMAND ${PROJECT_BINARY_DIR}/${GETARCH_BIN} 1 OUTPUT_VARIABLE GETARCH_CONF_OUT)
  91. message(STATUS "GETARCH results:\n${GETARCH_MAKE_OUT}")
  92. # append config data from getarch to the TARGET file and read in CMake vars
  93. file(APPEND ${TARGET_CONF_TEMP} ${GETARCH_CONF_OUT})
  94. ParseGetArchVars(${GETARCH_MAKE_OUT})
  95. set(GETARCH2_DIR "${PROJECT_BINARY_DIR}/getarch2_build")
  96. set(GETARCH2_BIN "getarch_2nd${CMAKE_EXECUTABLE_SUFFIX}")
  97. file(MAKE_DIRECTORY ${GETARCH2_DIR})
  98. configure_file(${TARGET_CONF_TEMP} ${GETARCH2_DIR}/${TARGET_CONF} COPYONLY)
  99. if (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore")
  100. try_compile(GETARCH2_RESULT ${GETARCH2_DIR}
  101. SOURCES ${PROJECT_SOURCE_DIR}/getarch_2nd.c
  102. COMPILE_DEFINITIONS ${EXFLAGS} ${GETARCH_FLAGS} ${GETARCH2_FLAGS} -I${GETARCH2_DIR} -I${PROJECT_SOURCE_DIR} -I${PROJECT_BINARY_DIR}
  103. OUTPUT_VARIABLE GETARCH2_LOG
  104. COPY_FILE ${PROJECT_BINARY_DIR}/${GETARCH2_BIN}
  105. )
  106. if (NOT ${GETARCH2_RESULT})
  107. MESSAGE(FATAL_ERROR "Compiling getarch_2nd failed ${GETARCH2_LOG}")
  108. endif ()
  109. endif ()
  110. # use the cmake binary w/ the -E param to run a shell command in a cross-platform way
  111. execute_process(COMMAND ${PROJECT_BINARY_DIR}/${GETARCH2_BIN} 0 OUTPUT_VARIABLE GETARCH2_MAKE_OUT)
  112. execute_process(COMMAND ${PROJECT_BINARY_DIR}/${GETARCH2_BIN} 1 OUTPUT_VARIABLE GETARCH2_CONF_OUT)
  113. # append config data from getarch_2nd to the TARGET file and read in CMake vars
  114. file(APPEND ${TARGET_CONF_TEMP} ${GETARCH2_CONF_OUT})
  115. if (${BUILD_KERNEL})
  116. configure_file(${TARGET_CONF_TEMP} ${PROJECT_BINARY_DIR}/kernel_config/${TARGET_CORE}/${TARGET_CONF} COPYONLY)
  117. else ()
  118. configure_file(${TARGET_CONF_TEMP} ${PROJECT_BINARY_DIR}/${TARGET_CONF} COPYONLY)
  119. endif ()
  120. ParseGetArchVars(${GETARCH2_MAKE_OUT})
  121. # compile get_config_h
  122. set(GEN_CONFIG_H_DIR "${PROJECT_BINARY_DIR}/genconfig_h_build")
  123. set(GEN_CONFIG_H_BIN "gen_config_h${CMAKE_EXECUTABLE_SUFFIX}")
  124. set(GEN_CONFIG_H_FLAGS "-DVERSION=\"${OpenBLAS_VERSION}\"")
  125. file(MAKE_DIRECTORY ${GEN_CONFIG_H_DIR})
  126. if (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore")
  127. try_compile(GEN_CONFIG_H_RESULT ${GEN_CONFIG_H_DIR}
  128. SOURCES ${PROJECT_SOURCE_DIR}/gen_config_h.c
  129. COMPILE_DEFINITIONS ${EXFLAGS} ${GETARCH_FLAGS} ${GEN_CONFIG_H_FLAGS} -I${PROJECT_SOURCE_DIR}
  130. OUTPUT_VARIABLE GEN_CONFIG_H_LOG
  131. COPY_FILE ${PROJECT_BINARY_DIR}/${GEN_CONFIG_H_BIN}
  132. )
  133. if (NOT ${GEN_CONFIG_H_RESULT})
  134. MESSAGE(FATAL_ERROR "Compiling gen_config_h failed ${GEN_CONFIG_H_LOG}")
  135. endif ()
  136. endif ()