Skip to content

Commit 69b5607

Browse files
committed
Improvements to previous commit (cross-compile).
Fix typos and bad if statements discovered in 0.2.20.
1 parent 0a7a527 commit 69b5607

File tree

4 files changed

+108
-128
lines changed

4 files changed

+108
-128
lines changed

cmake/f_check.cmake

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ else()
3434
endif()
3535

3636
if (NOT ONLY_CBLAS)
37-
# N.B. f_check is not cross-platform, so instead try to use CMake variables
3837
# run f_check (appends to TARGET files)
39-
# message(STATUS "Running f_check...")
40-
# execute_process(COMMAND perl f_check ${TARGET_MAKE} ${TARGET_CONF} ${CMAKE_Fortran_COMPILER}
41-
# WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
4238

4339
# TODO: detect whether underscore needed, set #defines and BU appropriately - use try_compile
4440
# TODO: set FEXTRALIB flags a la f_check?

cmake/prebuild.cmake

Lines changed: 107 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,12 @@ if (DEFINED CPUIDEMU)
4242
set(EXFLAGS "-DCPUIDEMU -DVENDOR=99")
4343
endif ()
4444

45-
if(CMAKE_CROSSCOMPILING AND NOT DEFINED TARGET_CORE)
46-
# Detect target without running getarch
47-
if(AARCH64)
48-
set(TARGET_CORE "ARMV8")
49-
else()
50-
message(FATAL_ERROR "When cross compiling, a TARGET_CORE is required.")
51-
endif()
52-
endif()
53-
54-
if (DEFINED TARGET_CORE)
45+
if (BUILD_KERNEL)
5546
# set the C flags for just this file
5647
set(GETARCH2_FLAGS "-DBUILD_KERNEL")
57-
set(TARGET_MAKE "Makefile_kernel.conf")
5848
set(TARGET_CONF "config_kernel.h")
5949
set(TARGET_CONF_DIR ${PROJECT_BINARY_DIR}/kernel_config/${TARGET_CORE})
6050
else()
61-
set(TARGET_MAKE "Makefile.conf")
6251
set(TARGET_CONF "config.h")
6352
set(TARGET_CONF_DIR ${PROJECT_BINARY_DIR})
6453
endif ()
@@ -70,16 +59,26 @@ if (NOT NOFORTRAN)
7059
include("${PROJECT_SOURCE_DIR}/cmake/f_check.cmake")
7160
endif ()
7261

62+
# This check requires c_check for arch but it should probably be done earlier
63+
if(CMAKE_CROSSCOMPILING AND NOT DEFINED CORE)
64+
# Detect target without running getarch
65+
if(ARM64)
66+
set(CORE "ARMV8")
67+
else()
68+
message(FATAL_ERROR "When cross compiling, a CORE is required.")
69+
endif()
70+
endif()
71+
7372
# Cannot run getarch on target if we are cross-compiling
74-
if (CMAKE_CROSSCOMPILING)
73+
if (DEFINED CORE AND CMAKE_CROSSCOMPILING)
7574
# Write to config as getarch would
7675

7776
# TODO: Set up defines that getarch sets up based on every other target
7877
# Perhaps this should be inside a different file as it grows larger
7978
file(APPEND ${TARGET_CONF_TEMP}
80-
"#define ${TARGET_CORE}\n"
81-
"#define CHAR_CORENAME \"${TARGET_CORE}\"\n")
82-
if ("${TARGET_CORE}" STREQUAL "ARMV8")
79+
"#define ${CORE}\n"
80+
"#define CHAR_CORENAME \"${CORE}\"\n")
81+
if ("${CORE}" STREQUAL "ARMV8")
8382
file(APPEND ${TARGET_CONF_TEMP}
8483
"#define L1_DATA_SIZE\t32768\n"
8584
"#define L1_DATA_LINESIZE\t64\n"
@@ -90,7 +89,7 @@ if (CMAKE_CROSSCOMPILING)
9089
"#define L2_ASSOCIATIVE\t32\n")
9190
set(SGEMM_UNROLL_M 4)
9291
set(SGEMM_UNROLL_N 4)
93-
elseif ("${TARGET_CORE}" STREQUAL "CORTEXA57")
92+
elseif ("${CORE}" STREQUAL "CORTEXA57")
9493
file(APPEND ${TARGET_CONF_TEMP}
9594
"#define L1_CODE_SIZE\t49152\n"
9695
"#define L1_CODE_LINESIZE\t64\n"
@@ -107,14 +106,14 @@ if (CMAKE_CROSSCOMPILING)
107106
"#define HAVE_VFPV3\n"
108107
"#define HAVE_VFP\n"
109108
"#define HAVE_NEON\n")
110-
set(SGEMM_DEFAULT_UNROLL_M 16)
111-
set(SGEMM_DEFAULT_UNROLL_N 4)
112-
set(DGEMM_DEFAULT_UNROLL_M 8)
113-
set(DGEMM_DEFAULT_UNROLL_N 4)
114-
set(CGEMM_DEFAULT_UNROLL_M 8)
115-
set(CGEMM_DEFAULT_UNROLL_N 4)
116-
set(ZGEMM_DEFAULT_UNROLL_M 8)
117-
set(ZGEMM_DEFAULT_UNROLL_N 4)
109+
set(SGEMM_UNROLL_M 16)
110+
set(SGEMM_UNROLL_N 4)
111+
set(DGEMM_UNROLL_M 8)
112+
set(DGEMM_UNROLL_N 4)
113+
set(CGEMM_UNROLL_M 8)
114+
set(CGEMM_UNROLL_N 4)
115+
set(ZGEMM_UNROLL_M 8)
116+
set(ZGEMM_UNROLL_N 4)
118117
endif()
119118

120119
# Or should this actually be NUM_CORES?
@@ -134,105 +133,101 @@ if (CMAKE_CROSSCOMPILING)
134133
file(APPEND ${TARGET_CONF_TEMP}
135134
"#define GEMM_MULTITHREAD_THRESHOLD\t${GEMM_MULTITHREAD_THRESHOLD}\n")
136135
# Move to where gen_config_h would place it
137-
file(RENAME ${TARGET_CONF_TEMP} "${PROJECT_BINARY_DIR}/config.h")
138-
139-
else()
140-
# compile getarch
141-
set(GETARCH_SRC
142-
${PROJECT_SOURCE_DIR}/getarch.c
143-
${CPUIDEMO}
144-
)
145-
146-
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
147-
#Use generic for MSVC now
148-
message("MSVC")
149-
set(GETARCH_FLAGS ${GETARCH_FLAGS} -DFORCE_GENERIC)
150-
else()
151-
list(APPEND GETARCH_SRC ${PROJECT_SOURCE_DIR}/cpuid.S)
152-
endif ()
153-
154-
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore")
155-
# disable WindowsStore strict CRT checks
156-
set(GETARCH_FLAGS ${GETARCH_FLAGS} -D_CRT_SECURE_NO_WARNINGS)
157-
endif ()
136+
file(RENAME ${TARGET_CONF_TEMP} "${TARGET_CONF_DIR}/${TARGET_CONF}")
158137

159-
set(GETARCH_DIR "${PROJECT_BINARY_DIR}/getarch_build")
160-
set(GETARCH_BIN "getarch${CMAKE_EXECUTABLE_SUFFIX}")
161-
file(MAKE_DIRECTORY ${GETARCH_DIR})
162-
configure_file(${TARGET_CONF_TEMP} ${GETARCH_DIR}/${TARGET_CONF} COPYONLY)
163-
if (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore")
164-
try_compile(GETARCH_RESULT ${GETARCH_DIR}
165-
SOURCES ${GETARCH_SRC}
166-
COMPILE_DEFINITIONS ${EXFLAGS} ${GETARCH_FLAGS} -I${GETARCH_DIR} -I${PROJECT_SOURCE_DIR} -I${PROJECT_BINARY_DIR}
167-
OUTPUT_VARIABLE GETARCH_LOG
168-
COPY_FILE ${PROJECT_BINARY_DIR}/${GETARCH_BIN}
138+
else(NOT CMAKE_CROSSCOMPILING)
139+
# compile getarch
140+
set(GETARCH_SRC
141+
${PROJECT_SOURCE_DIR}/getarch.c
142+
${CPUIDEMU}
169143
)
170144

171-
if (NOT ${GETARCH_RESULT})
172-
MESSAGE(FATAL_ERROR "Compiling getarch failed ${GETARCH_LOG}")
145+
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
146+
#Use generic for MSVC now
147+
message("MSVC")
148+
set(GETARCH_FLAGS ${GETARCH_FLAGS} -DFORCE_GENERIC)
149+
else()
150+
list(APPEND GETARCH_SRC ${PROJECT_SOURCE_DIR}/cpuid.S)
173151
endif ()
174-
endif ()
175-
message(STATUS "Running getarch")
176-
177-
# use the cmake binary w/ the -E param to run a shell command in a cross-platform way
178-
execute_process(COMMAND ${PROJECT_BINARY_DIR}/${GETARCH_BIN} 0 OUTPUT_VARIABLE GETARCH_MAKE_OUT)
179-
execute_process(COMMAND ${PROJECT_BINARY_DIR}/${GETARCH_BIN} 1 OUTPUT_VARIABLE GETARCH_CONF_OUT)
180-
181-
message(STATUS "GETARCH results:\n${GETARCH_MAKE_OUT}")
182-
183-
# append config data from getarch to the TARGET file and read in CMake vars
184-
file(APPEND ${TARGET_CONF_TEMP} ${GETARCH_CONF_OUT})
185-
ParseGetArchVars(${GETARCH_MAKE_OUT})
186-
187-
set(GETARCH2_DIR "${PROJECT_BINARY_DIR}/getarch2_build")
188-
set(GETARCH2_BIN "getarch_2nd${CMAKE_EXECUTABLE_SUFFIX}")
189-
file(MAKE_DIRECTORY ${GETARCH2_DIR})
190-
configure_file(${TARGET_CONF_TEMP} ${GETARCH2_DIR}/${TARGET_CONF} COPYONLY)
191-
if (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore")
192-
try_compile(GETARCH2_RESULT ${GETARCH2_DIR}
193-
SOURCES ${PROJECT_SOURCE_DIR}/getarch_2nd.c
194-
COMPILE_DEFINITIONS ${EXFLAGS} ${GETARCH_FLAGS} ${GETARCH2_FLAGS} -I${GETARCH2_DIR} -I${PROJECT_SOURCE_DIR} -I${PROJECT_BINARY_DIR}
195-
OUTPUT_VARIABLE GETARCH2_LOG
196-
COPY_FILE ${PROJECT_BINARY_DIR}/${GETARCH2_BIN}
197-
)
198152

199-
if (NOT ${GETARCH2_RESULT})
200-
MESSAGE(FATAL_ERROR "Compiling getarch_2nd failed ${GETARCH2_LOG}")
153+
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore")
154+
# disable WindowsStore strict CRT checks
155+
set(GETARCH_FLAGS ${GETARCH_FLAGS} -D_CRT_SECURE_NO_WARNINGS)
201156
endif ()
202-
endif ()
203157

204-
# use the cmake binary w/ the -E param to run a shell command in a cross-platform way
205-
execute_process(COMMAND ${PROJECT_BINARY_DIR}/${GETARCH2_BIN} 0 OUTPUT_VARIABLE GETARCH2_MAKE_OUT)
206-
execute_process(COMMAND ${PROJECT_BINARY_DIR}/${GETARCH2_BIN} 1 OUTPUT_VARIABLE GETARCH2_CONF_OUT)
158+
set(GETARCH_DIR "${PROJECT_BINARY_DIR}/getarch_build")
159+
set(GETARCH_BIN "getarch${CMAKE_EXECUTABLE_SUFFIX}")
160+
file(MAKE_DIRECTORY ${GETARCH_DIR})
161+
configure_file(${TARGET_CONF_TEMP} ${GETARCH_DIR}/${TARGET_CONF} COPYONLY)
162+
if (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore")
163+
try_compile(GETARCH_RESULT ${GETARCH_DIR}
164+
SOURCES ${GETARCH_SRC}
165+
COMPILE_DEFINITIONS ${EXFLAGS} ${GETARCH_FLAGS} -I${GETARCH_DIR} -I${PROJECT_SOURCE_DIR} -I${PROJECT_BINARY_DIR}
166+
OUTPUT_VARIABLE GETARCH_LOG
167+
COPY_FILE ${PROJECT_BINARY_DIR}/${GETARCH_BIN}
168+
)
169+
170+
if (NOT ${GETARCH_RESULT})
171+
MESSAGE(FATAL_ERROR "Compiling getarch failed ${GETARCH_LOG}")
172+
endif ()
173+
endif ()
174+
message(STATUS "Running getarch")
175+
176+
# use the cmake binary w/ the -E param to run a shell command in a cross-platform way
177+
execute_process(COMMAND ${PROJECT_BINARY_DIR}/${GETARCH_BIN} 0 OUTPUT_VARIABLE GETARCH_MAKE_OUT)
178+
execute_process(COMMAND ${PROJECT_BINARY_DIR}/${GETARCH_BIN} 1 OUTPUT_VARIABLE GETARCH_CONF_OUT)
179+
180+
message(STATUS "GETARCH results:\n${GETARCH_MAKE_OUT}")
181+
182+
# append config data from getarch to the TARGET file and read in CMake vars
183+
file(APPEND ${TARGET_CONF_TEMP} ${GETARCH_CONF_OUT})
184+
ParseGetArchVars(${GETARCH_MAKE_OUT})
185+
186+
set(GETARCH2_DIR "${PROJECT_BINARY_DIR}/getarch2_build")
187+
set(GETARCH2_BIN "getarch_2nd${CMAKE_EXECUTABLE_SUFFIX}")
188+
file(MAKE_DIRECTORY ${GETARCH2_DIR})
189+
configure_file(${TARGET_CONF_TEMP} ${GETARCH2_DIR}/${TARGET_CONF} COPYONLY)
190+
if (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore")
191+
try_compile(GETARCH2_RESULT ${GETARCH2_DIR}
192+
SOURCES ${PROJECT_SOURCE_DIR}/getarch_2nd.c
193+
COMPILE_DEFINITIONS ${EXFLAGS} ${GETARCH_FLAGS} ${GETARCH2_FLAGS} -I${GETARCH2_DIR} -I${PROJECT_SOURCE_DIR} -I${PROJECT_BINARY_DIR}
194+
OUTPUT_VARIABLE GETARCH2_LOG
195+
COPY_FILE ${PROJECT_BINARY_DIR}/${GETARCH2_BIN}
196+
)
197+
198+
if (NOT ${GETARCH2_RESULT})
199+
MESSAGE(FATAL_ERROR "Compiling getarch_2nd failed ${GETARCH2_LOG}")
200+
endif ()
201+
endif ()
207202

208-
# append config data from getarch_2nd to the TARGET file and read in CMake vars
209-
file(APPEND ${TARGET_CONF_TEMP} ${GETARCH2_CONF_OUT})
203+
# use the cmake binary w/ the -E param to run a shell command in a cross-platform way
204+
execute_process(COMMAND ${PROJECT_BINARY_DIR}/${GETARCH2_BIN} 0 OUTPUT_VARIABLE GETARCH2_MAKE_OUT)
205+
execute_process(COMMAND ${PROJECT_BINARY_DIR}/${GETARCH2_BIN} 1 OUTPUT_VARIABLE GETARCH2_CONF_OUT)
210206

211-
if (${BUILD_KERNEL})
212-
configure_file(${TARGET_CONF_TEMP} ${PROJECT_BINARY_DIR}/kernel_config/${TARGET_CORE}/${TARGET_CONF} COPYONLY)
213-
else ()
214-
configure_file(${TARGET_CONF_TEMP} ${PROJECT_BINARY_DIR}/${TARGET_CONF} COPYONLY)
215-
endif ()
207+
# append config data from getarch_2nd to the TARGET file and read in CMake vars
208+
file(APPEND ${TARGET_CONF_TEMP} ${GETARCH2_CONF_OUT})
216209

217-
ParseGetArchVars(${GETARCH2_MAKE_OUT})
210+
configure_file(${TARGET_CONF_TEMP} ${TARGET_CONF_DIR}/${TARGET_CONF} COPYONLY)
218211

219-
# compile get_config_h
220-
set(GEN_CONFIG_H_DIR "${PROJECT_BINARY_DIR}/genconfig_h_build")
221-
set(GEN_CONFIG_H_BIN "gen_config_h${CMAKE_EXECUTABLE_SUFFIX}")
222-
set(GEN_CONFIG_H_FLAGS "-DVERSION=\"${OpenBLAS_VERSION}\"")
223-
file(MAKE_DIRECTORY ${GEN_CONFIG_H_DIR})
212+
ParseGetArchVars(${GETARCH2_MAKE_OUT})
224213

225-
if (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore")
226-
try_compile(GEN_CONFIG_H_RESULT ${GEN_CONFIG_H_DIR}
227-
SOURCES ${PROJECT_SOURCE_DIR}/gen_config_h.c
228-
COMPILE_DEFINITIONS ${EXFLAGS} ${GETARCH_FLAGS} ${GEN_CONFIG_H_FLAGS} -I${PROJECT_SOURCE_DIR}
229-
OUTPUT_VARIABLE GEN_CONFIG_H_LOG
230-
COPY_FILE ${PROJECT_BINARY_DIR}/${GEN_CONFIG_H_BIN}
231-
)
214+
# compile get_config_h
215+
set(GEN_CONFIG_H_DIR "${PROJECT_BINARY_DIR}/genconfig_h_build")
216+
set(GEN_CONFIG_H_BIN "gen_config_h${CMAKE_EXECUTABLE_SUFFIX}")
217+
set(GEN_CONFIG_H_FLAGS "-DVERSION=\"${OpenBLAS_VERSION}\"")
218+
file(MAKE_DIRECTORY ${GEN_CONFIG_H_DIR})
232219

233-
if (NOT ${GEN_CONFIG_H_RESULT})
234-
MESSAGE(FATAL_ERROR "Compiling gen_config_h failed ${GEN_CONFIG_H_LOG}")
235-
endif ()
220+
if (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore")
221+
try_compile(GEN_CONFIG_H_RESULT ${GEN_CONFIG_H_DIR}
222+
SOURCES ${PROJECT_SOURCE_DIR}/gen_config_h.c
223+
COMPILE_DEFINITIONS ${EXFLAGS} ${GETARCH_FLAGS} ${GEN_CONFIG_H_FLAGS} -I${PROJECT_SOURCE_DIR}
224+
OUTPUT_VARIABLE GEN_CONFIG_H_LOG
225+
COPY_FILE ${PROJECT_BINARY_DIR}/${GEN_CONFIG_H_BIN}
226+
)
227+
228+
if (NOT ${GEN_CONFIG_H_RESULT})
229+
MESSAGE(FATAL_ERROR "Compiling gen_config_h failed ${GEN_CONFIG_H_LOG}")
230+
endif ()
236231
endif ()
237232

238-
endif(CMAKE_CROSSCOMPILING)
233+
endif()

cmake/system.cmake

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,9 @@
44
##
55
set(NETLIB_LAPACK_DIR "${PROJECT_SOURCE_DIR}/lapack-netlib")
66

7-
# TODO: Makefile.system detects Darwin (mac) and switches to clang here -hpa
8-
# http://stackoverflow.com/questions/714100/os-detecting-makefile
9-
10-
# TODO: Makefile.system sets HOSTCC = $(CC) here if not already set -hpa
11-
127
# TARGET_CORE will override TARGET which is used in DYNAMIC_ARCH=1.
138
if (DEFINED TARGET_CORE)
149
set(TARGET ${TARGET_CORE})
15-
if(NOT DEFINED CORE)
16-
set(CORE ${TARGET_CORE})
17-
endif()
1810
endif ()
1911

2012
# Force fallbacks for 32bit
@@ -107,9 +99,6 @@ if (NOT DEFINED NEED_PIC)
10799
set(NEED_PIC 1)
108100
endif ()
109101

110-
# TODO: I think CMake should be handling all this stuff -hpa
111-
unset(ARFLAGS)
112-
113102
# OS dependent settings
114103
include("${PROJECT_SOURCE_DIR}/cmake/os.cmake")
115104

kernel/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function (build_core TARGET_CORE KDIR TSUFFIX KERNEL_DEFINITIONS)
2222

2323
if (${ADD_COMMONOBJS})
2424
if (${ARCH} STREQUAL "x86")
25-
if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
25+
if (NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
2626
GenerateNamedObjects("${KERNELDIR}/cpuid.S" "" "" false "" "" true)
2727
else()
2828
GenerateNamedObjects("${KERNELDIR}/cpuid_win.c" "" "" false "" "" true)

0 commit comments

Comments
 (0)