Skip to content

Commit 63bbd7b

Browse files
author
Daniel Cohen Gindi
committed
Better support for MSVC/Windows in CMake
1 parent 010d59b commit 63bbd7b

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

CMakeLists.txt

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ endif()
4242

4343
#######
4444

45+
if(MSVC AND MSVC_STATIC_CRT)
46+
set(CompilerFlags
47+
CMAKE_CXX_FLAGS
48+
CMAKE_CXX_FLAGS_DEBUG
49+
CMAKE_CXX_FLAGS_RELEASE
50+
CMAKE_C_FLAGS
51+
CMAKE_C_FLAGS_DEBUG
52+
CMAKE_C_FLAGS_RELEASE
53+
)
54+
foreach(CompilerFlag ${CompilerFlags})
55+
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
56+
endforeach()
57+
endif()
4558

4659
message(WARNING "CMake support is experimental. It does not yet support all build options and may not produce the same Makefiles that OpenBLAS ships with.")
4760

@@ -149,12 +162,6 @@ if (${DYNAMIC_ARCH})
149162
endforeach()
150163
endif ()
151164

152-
# Only build shared libs for MSVC
153-
if (MSVC)
154-
set(BUILD_SHARED_LIBS ON)
155-
endif()
156-
157-
158165
# add objects to the openblas lib
159166
add_library(${OpenBLAS_LIBNAME} ${LA_SOURCES} ${LAPACKE_SOURCES} ${RELA_SOURCES} ${TARGET_OBJS} ${OpenBLAS_DEF_FILE})
160167
target_include_directories(${OpenBLAS_LIBNAME} INTERFACE $<INSTALL_INTERFACE:include>)
@@ -314,7 +321,7 @@ install (FILES ${OPENBLAS_CONFIG_H} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
314321
if(NOT NOFORTRAN)
315322
message(STATUS "Generating f77blas.h in ${CMAKE_INSTALL_INCLUDEDIR}")
316323

317-
set(F77BLAS_H ${CMAKE_BINARY_DIR}/f77blas.h)
324+
set(F77BLAS_H ${CMAKE_BINARY_DIR}/generated/f77blas.h)
318325
file(WRITE ${F77BLAS_H} "#ifndef OPENBLAS_F77BLAS_H\n")
319326
file(APPEND ${F77BLAS_H} "#define OPENBLAS_F77BLAS_H\n")
320327
file(APPEND ${F77BLAS_H} "#include \"openblas_config.h\"\n")
@@ -327,10 +334,11 @@ endif()
327334
if(NOT NO_CBLAS)
328335
message (STATUS "Generating cblas.h in ${CMAKE_INSTALL_INCLUDEDIR}")
329336

337+
set(CBLAS_H ${CMAKE_BINARY_DIR}/generated/cblas.h)
330338
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/cblas.h CBLAS_H_CONTENTS)
331339
string(REPLACE "common" "openblas_config" CBLAS_H_CONTENTS_NEW "${CBLAS_H_CONTENTS}")
332-
file(WRITE ${CMAKE_BINARY_DIR}/cblas.tmp "${CBLAS_H_CONTENTS_NEW}")
333-
install (FILES ${CMAKE_BINARY_DIR}/cblas.tmp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} RENAME cblas.h)
340+
file(WRITE ${CBLAS_H} "${CBLAS_H_CONTENTS_NEW}")
341+
install (FILES ${CBLAS_H} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
334342
endif()
335343

336344
if(NOT NO_LAPACKE)

0 commit comments

Comments
 (0)