Skip to content

Commit 514d237

Browse files
authored
Merge pull request #1279 from xsacha/develop
CMake improvements
2 parents e1b2502 + ef64991 commit 514d237

18 files changed

+474
-518
lines changed

.travis.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,34 @@ jobs:
119119
- TARGET_BOX=LINUX64_MUSL
120120
- BTYPE="BINARY=64 NO_AFFINITY=1 USE_OPENMP=0 NO_LAPACK=0 TARGET=core2"
121121

122+
- &test-cmake
123+
stage: test
124+
compiler: clang
125+
addons:
126+
apt:
127+
packages:
128+
- gfortran
129+
- cmake
130+
dist: trusty
131+
sudo: true
132+
before_script:
133+
- COMMON_ARGS="-DTARGET=NEHALEM -DNUM_THREADS=32"
134+
script:
135+
- set -e
136+
- mkdir build
137+
- CONFIG=Release
138+
- cmake -Bbuild -H. $CMAKE_ARGS $COMMON_ARGS -DCMAKE_BUILD_TYPE=$CONFIG
139+
- cmake --build build --config $CONFIG -- -j2
140+
env:
141+
- CMAKE=1
142+
- <<: *test-cmake
143+
env:
144+
- CMAKE=1 CMAKE_ARGS="-DNOFORTRAN=1"
145+
- <<: *test-cmake
146+
compiler: gcc
147+
env:
148+
- CMAKE=1
149+
122150
# whitelist
123151
branches:
124152
only:

CMakeLists.txt

Lines changed: 73 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
##
44

55
cmake_minimum_required(VERSION 2.8.5)
6-
project(OpenBLAS)
6+
project(OpenBLAS C ASM)
77
set(OpenBLAS_MAJOR_VERSION 0)
88
set(OpenBLAS_MINOR_VERSION 3)
99
set(OpenBLAS_PATCH_VERSION 0.dev)
1010
set(OpenBLAS_VERSION "${OpenBLAS_MAJOR_VERSION}.${OpenBLAS_MINOR_VERSION}.${OpenBLAS_PATCH_VERSION}")
1111

12-
enable_language(ASM)
13-
enable_language(C)
14-
1512
# Adhere to GNU filesystem layout conventions
1613
include(GNUInstallDirs)
1714

@@ -26,30 +23,13 @@ if(MSVC)
2623
option(BUILD_WITHOUT_LAPACK "Without LAPACK and LAPACKE (Only BLAS or CBLAS)" ON)
2724
endif()
2825
option(BUILD_WITHOUT_CBLAS "Without CBLAS" OFF)
29-
option(BUILD_DEBUG "Build Debug Version" OFF)
3026
option(DYNAMIC_ARCH "Build with DYNAMIC_ARCH" OFF)
3127
#######
3228
if(BUILD_WITHOUT_LAPACK)
3329
set(NO_LAPACK 1)
3430
set(NO_LAPACKE 1)
3531
endif()
3632

37-
if(CMAKE_CONFIGURATION_TYPES) # multiconfig generator?
38-
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "" FORCE)
39-
set(CMAKE_BUILD_TYPE
40-
Debug Debug
41-
Release Release
42-
)
43-
else()
44-
if( NOT CMAKE_BUILD_TYPE )
45-
if(BUILD_DEBUG)
46-
set(CMAKE_BUILD_TYPE Debug)
47-
else()
48-
set(CMAKE_BUILD_TYPE Release)
49-
endif()
50-
endif()
51-
endif()
52-
5333
if(BUILD_WITHOUT_CBLAS)
5434
set(NO_CBLAS 1)
5535
endif()
@@ -107,19 +87,10 @@ if (BUILD_COMPLEX16)
10787
list(APPEND FLOAT_TYPES "ZCOMPLEX") # defines COMPLEX and DOUBLE
10888
endif ()
10989

110-
set(SUBDIRS_ALL ${SUBDIRS} test ctest utest exports benchmark ../laswp ../bench)
111-
112-
# all :: libs netlib tests shared
113-
114-
# libs :
11590
if (NOT DEFINED CORE OR "${CORE}" STREQUAL "UNKNOWN")
11691
message(FATAL_ERROR "Detecting CPU failed. Please set TARGET explicitly, e.g. make TARGET=your_cpu_target. Please read README for details.")
11792
endif ()
11893

119-
if (${NO_STATIC} AND ${NO_SHARED})
120-
message(FATAL_ERROR "Neither static nor shared are enabled.")
121-
endif ()
122-
12394
#Set default output directory
12495
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
12596
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
@@ -141,26 +112,20 @@ endforeach ()
141112
# Not using add_subdirectory here because lapack-netlib already has its own CMakeLists.txt. Instead include a cmake script with the sources we want.
142113
if (NOT NOFORTRAN AND NOT NO_LAPACK)
143114
include("${PROJECT_SOURCE_DIR}/cmake/lapack.cmake")
144-
if (NOT NO_LAPACKE)
145-
include("${PROJECT_SOURCE_DIR}/cmake/lapacke.cmake")
146-
endif ()
115+
if (NOT NO_LAPACKE)
116+
include("${PROJECT_SOURCE_DIR}/cmake/lapacke.cmake")
117+
endif ()
147118
endif ()
148119

149120
# Only generate .def for dll on MSVC and always produce pdb files for debug and release
150121
if(MSVC)
151-
set(OpenBLAS_DEF_FILE "${PROJECT_BINARY_DIR}/openblas.def")
152-
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
153-
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Zi")
154-
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
122+
if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} LESS 3.4)
123+
set(OpenBLAS_DEF_FILE "${PROJECT_BINARY_DIR}/openblas.def")
124+
endif()
125+
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Zi")
126+
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
155127
endif()
156128

157-
#ifeq ($(DYNAMIC_ARCH), 1)
158-
# @$(MAKE) -C kernel commonlibs || exit 1
159-
# @for d in $(DYNAMIC_CORE) ; \
160-
# do $(MAKE) GOTOBLAS_MAKEFILE= -C kernel TARGET_CORE=$$d kernel || exit 1 ;\
161-
# done
162-
# @echo DYNAMIC_ARCH=1 >> Makefile.conf_last
163-
#endif
164129
if (${DYNAMIC_ARCH})
165130
add_subdirectory(kernel)
166131
foreach(TARGET_CORE ${DYNAMIC_CORE})
@@ -169,11 +134,24 @@ if (${DYNAMIC_ARCH})
169134
endforeach()
170135
endif ()
171136

137+
# Only build shared libs for MSVC
138+
if (MSVC)
139+
set(BUILD_SHARED_LIBS ON)
140+
endif()
172141

173-
# add objects to the openblas lib
174-
add_library(${OpenBLAS_LIBNAME} SHARED ${LA_SOURCES} ${LAPACKE_SOURCES} ${TARGET_OBJS} ${OpenBLAS_DEF_FILE})
175142

176-
include("${PROJECT_SOURCE_DIR}/cmake/export.cmake")
143+
# add objects to the openblas lib
144+
add_library(${OpenBLAS_LIBNAME} ${LA_SOURCES} ${LAPACKE_SOURCES} ${TARGET_OBJS} ${OpenBLAS_DEF_FILE})
145+
146+
# Handle MSVC exports
147+
if(MSVC AND BUILD_SHARED_LIBS)
148+
if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} LESS 3.4)
149+
include("${PROJECT_SOURCE_DIR}/cmake/export.cmake")
150+
else()
151+
# Creates verbose .def file (51KB vs 18KB)
152+
set_target_properties(${OpenBLAS_LIBNAME} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS true)
153+
endif()
154+
endif()
177155

178156
# Set output for libopenblas
179157
set_target_properties( ${OpenBLAS_LIBNAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
@@ -188,79 +166,71 @@ foreach (OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
188166
endforeach()
189167

190168
enable_testing()
191-
add_subdirectory(utest)
192-
193-
if (NOT MSVC)
194-
#only build shared library for MSVC
195-
196-
add_library(${OpenBLAS_LIBNAME}_static STATIC ${LA_SOURCES} ${LAPACKE_SOURCES} ${TARGET_OBJS})
197-
set_target_properties(${OpenBLAS_LIBNAME}_static PROPERTIES OUTPUT_NAME ${OpenBLAS_LIBNAME})
198-
set_target_properties(${OpenBLAS_LIBNAME}_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
199169

200-
if(SMP)
201-
target_link_libraries(${OpenBLAS_LIBNAME} pthread)
202-
target_link_libraries(${OpenBLAS_LIBNAME}_static pthread)
170+
if (USE_THREAD)
171+
# Add threading library to linker
172+
find_package(Threads)
173+
if (THREADS_HAVE_PTHREAD_ARG)
174+
set_property(TARGET ${OpenBLAS_LIBNAME} PROPERTY COMPILE_OPTIONS "-pthread")
175+
set_property(TARGET ${OpenBLAS_LIBNAME} PROPERTY INTERFACE_COMPILE_OPTIONS "-pthread")
176+
endif()
177+
target_link_libraries(${OpenBLAS_LIBNAME} ${CMAKE_THREAD_LIBS_INIT})
203178
endif()
204179

205-
#build test and ctest
206-
add_subdirectory(test)
207-
if(NOT NO_CBLAS)
208-
add_subdirectory(ctest)
180+
if (MSVC OR NOT NOFORTRAN)
181+
# Broken without fortran on unix
182+
add_subdirectory(utest)
209183
endif()
184+
185+
if (NOT MSVC AND NOT NOFORTRAN)
186+
# Build test and ctest
187+
add_subdirectory(test)
188+
if(NOT NO_CBLAS)
189+
add_subdirectory(ctest)
190+
endif()
210191
endif()
211192

212193
set_target_properties(${OpenBLAS_LIBNAME} PROPERTIES
213194
VERSION ${OpenBLAS_MAJOR_VERSION}.${OpenBLAS_MINOR_VERSION}
214195
SOVERSION ${OpenBLAS_MAJOR_VERSION}
215196
)
216197

217-
218-
# TODO: Why is the config saved here? Is this necessary with CMake?
219-
#Save the config files for installation
220-
# @cp Makefile.conf Makefile.conf_last
221-
# @cp config.h config_last.h
222-
#ifdef QUAD_PRECISION
223-
# @echo "#define QUAD_PRECISION">> config_last.h
224-
#endif
225-
#ifeq ($(EXPRECISION), 1)
226-
# @echo "#define EXPRECISION">> config_last.h
227-
#endif
228-
###
229-
230-
#ifdef USE_THREAD
231-
# @echo USE_THREAD=$(USE_THREAD) >> Makefile.conf_last
232-
#endif
233-
# @touch lib.grd
234-
235198
# Install project
236199

237200
# Install libraries
238201
install(TARGETS ${OpenBLAS_LIBNAME}
239202
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
240203
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
241-
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} )
242-
243-
# Install include files
244-
set (GENCONFIG_BIN ${CMAKE_BINARY_DIR}/gen_config_h${CMAKE_EXECUTABLE_SUFFIX})
245-
246-
execute_process(COMMAND ${GENCONFIG_BIN}
247-
${CMAKE_CURRENT_SOURCE_DIR}/config.h
248-
${CMAKE_CURRENT_SOURCE_DIR}/openblas_config_template.h
249-
OUTPUT_VARIABLE OPENBLAS_CONFIG_H_CONTENTS)
250-
251-
file(WRITE ${CMAKE_BINARY_DIR}/openblas_config.tmp "${OPENBLAS_CONFIG_H_CONTENTS}")
252-
configure_file(${CMAKE_BINARY_DIR}/openblas_config.tmp ${CMAKE_BINARY_DIR}/openblas_config.h COPYONLY)
253-
254-
install (FILES ${CMAKE_BINARY_DIR}/openblas_config.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
255-
256-
message(STATUS "Generating f77blas.h in ${CMAKE_INSTALL_INCLUDEDIR}")
257-
258-
file(WRITE ${CMAKE_BINARY_DIR}/f77blas.h "")
259-
file(APPEND ${CMAKE_BINARY_DIR}/f77blas.h "#ifndef OPENBLAS_F77BLAS_H\n#define OPENBLAS_F77BLAS_H\n#include \"openblas_config.h\"\n")
260-
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/common_interface.h COMMON_INTERFACE_H_CONTENTS)
261-
file(APPEND ${CMAKE_BINARY_DIR}/f77blas.h "${COMMON_INTERFACE_H_CONTENTS}")
262-
file(APPEND ${CMAKE_BINARY_DIR}/f77blas.h "#endif")
263-
install (FILES ${CMAKE_BINARY_DIR}/f77blas.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
204+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} )
205+
206+
message(STATUS "Generating openblas_config.h in ${CMAKE_INSTALL_INCLUDEDIR}")
207+
208+
set(OPENBLAS_CONFIG_H ${CMAKE_BINARY_DIR}/openblas_config.h)
209+
file(WRITE ${OPENBLAS_CONFIG_H} "#ifndef OPENBLAS_CONFIG_H\n")
210+
file(APPEND ${OPENBLAS_CONFIG_H} "#define OPENBLAS_CONFIG_H\n")
211+
file(STRINGS ${PROJECT_BINARY_DIR}/config.h __lines)
212+
foreach(line ${__lines})
213+
string(REPLACE "#define " "" line ${line})
214+
file(APPEND ${OPENBLAS_CONFIG_H} "#define OPENBLAS_${line}\n")
215+
endforeach()
216+
file(APPEND ${OPENBLAS_CONFIG_H} "#define OPENBLAS_VERSION \"OpenBLAS ${OpenBLAS_VERSION}\"\n")
217+
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/openblas_config_template.h OPENBLAS_CONFIG_TEMPLATE_H_CONTENTS)
218+
file(APPEND ${OPENBLAS_CONFIG_H} "${OPENBLAS_CONFIG_TEMPLATE_H_CONTENTS}\n")
219+
file(APPEND ${OPENBLAS_CONFIG_H} "#endif /* OPENBLAS_CONFIG_H */\n")
220+
install (FILES ${OPENBLAS_CONFIG_H} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
221+
222+
if(NOT NOFORTRAN)
223+
message(STATUS "Generating f77blas.h in ${CMAKE_INSTALL_INCLUDEDIR}")
224+
225+
set(F77BLAS_H ${CMAKE_BINARY_DIR}/f77blas.h)
226+
file(WRITE ${F77BLAS_H} "#ifndef OPENBLAS_F77BLAS_H\n")
227+
file(APPEND ${F77BLAS_H} "#define OPENBLAS_F77BLAS_H\n")
228+
file(APPEND ${F77BLAS_H} "#include \"openblas_config.h\"\n")
229+
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/common_interface.h COMMON_INTERFACE_H_CONTENTS)
230+
file(APPEND ${F77BLAS_H} "${COMMON_INTERFACE_H_CONTENTS}\n")
231+
file(APPEND ${F77BLAS_H} "#endif")
232+
install (FILES ${F77BLAS_H} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
233+
endif()
264234

265235
if(NOT NO_CBLAS)
266236
message (STATUS "Generating cblas.h in ${CMAKE_INSTALL_INCLUDEDIR}")
@@ -282,10 +252,6 @@ if(NOT NO_LAPACKE)
282252
)
283253
install (FILES ${CMAKE_BINARY_DIR}/lapacke_mangling.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
284254
endif()
285-
286-
if(NOT MSVC)
287-
install (TARGETS ${OpenBLAS_LIBNAME}_static DESTINATION ${CMAKE_INSTALL_LIBDIR})
288-
endif()
289255

290256
include(FindPkgConfig QUIET)
291257
if(PKG_CONFIG_FOUND)

cmake/arch.cmake

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
## Description: Ported from portion of OpenBLAS/Makefile.system
44
## Sets various variables based on architecture.
55

6-
if (${ARCH} STREQUAL "x86" OR ${ARCH} STREQUAL "x86_64")
6+
if (X86 OR X86_64)
77

8-
if (${ARCH} STREQUAL "x86")
8+
if (X86)
99
if (NOT BINARY)
1010
set(NO_BINARY_MODE 1)
1111
endif ()
@@ -33,41 +33,22 @@ if (${CMAKE_C_COMPILER_ID} STREQUAL "Intel")
3333
endif ()
3434

3535
if (USE_OPENMP)
36-
37-
if (${CMAKE_C_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_C_COMPILER_ID} STREQUAL "LSB")
38-
set(CCOMMON_OPT "${CCOMMON_OPT} -fopenmp")
39-
endif ()
40-
41-
if (${CMAKE_C_COMPILER_ID} STREQUAL "Clang")
42-
message(WARNING "Clang doesn't support OpenMP yet.")
43-
set(CCOMMON_OPT "${CCOMMON_OPT} -fopenmp")
44-
endif ()
45-
46-
if (${CMAKE_C_COMPILER_ID} STREQUAL "Intel")
47-
set(CCOMMON_OPT "${CCOMMON_OPT} -openmp")
48-
endif ()
49-
50-
if (${CMAKE_C_COMPILER_ID} STREQUAL "PGI")
51-
set(CCOMMON_OPT "${CCOMMON_OPT} -mp")
52-
endif ()
53-
54-
if (${CMAKE_C_COMPILER_ID} STREQUAL "OPEN64")
55-
set(CCOMMON_OPT "${CCOMMON_OPT} -mp")
56-
set(CEXTRALIB "${CEXTRALIB} -lstdc++")
57-
endif ()
58-
59-
if (${CMAKE_C_COMPILER_ID} STREQUAL "PATHSCALE")
60-
set(CCOMMON_OPT "${CCOMMON_OPT} -mp")
61-
endif ()
36+
# USE_SIMPLE_THREADED_LEVEL3 = 1
37+
# NO_AFFINITY = 1
38+
find_package(OpenMP REQUIRED)
39+
if (OpenMP_FOUND)
40+
set(CCOMMON_OPT "${CCOMMON_OPT} ${OpenMP_C_FLAGS} -DUSE_OPENMP")
41+
set(FCOMMON_OPT "${FCOMMON_OPT} ${OpenMP_Fortran_FLAGS}")
42+
endif()
6243
endif ()
6344

6445

6546
if (DYNAMIC_ARCH)
66-
if (${ARCH} STREQUAL "x86")
47+
if (X86)
6748
set(DYNAMIC_CORE KATMAI COPPERMINE NORTHWOOD PRESCOTT BANIAS CORE2 PENRYN DUNNINGTON NEHALEM ATHLON OPTERON OPTERON_SSE3 BARCELONA BOBCAT ATOM NANO)
6849
endif ()
6950

70-
if (${ARCH} STREQUAL "x86_64")
51+
if (X86_64)
7152
set(DYNAMIC_CORE PRESCOTT CORE2 PENRYN DUNNINGTON NEHALEM OPTERON OPTERON_SSE3 BARCELONA BOBCAT ATOM NANO)
7253
if (NOT NO_AVX)
7354
set(DYNAMIC_CORE ${DYNAMIC_CORE} SANDYBRIDGE BULLDOZER PILEDRIVER STEAMROLLER EXCAVATOR)
@@ -94,7 +75,7 @@ if (${ARCH} STREQUAL "ia64")
9475
endif ()
9576
endif ()
9677

97-
if (${ARCH} STREQUAL "mips64")
78+
if (MIPS64)
9879
set(NO_BINARY_MODE 1)
9980
endif ()
10081

@@ -103,12 +84,12 @@ if (${ARCH} STREQUAL "alpha")
10384
set(BINARY_DEFINED 1)
10485
endif ()
10586

106-
if (${ARCH} STREQUAL "arm")
87+
if (ARM)
10788
set(NO_BINARY_MODE 1)
10889
set(BINARY_DEFINED 1)
10990
endif ()
11091

111-
if (${ARCH} STREQUAL "arm64")
92+
if (ARM64)
11293
set(NO_BINARY_MODE 1)
11394
set(BINARY_DEFINED 1)
11495
endif ()

0 commit comments

Comments
 (0)