diff options
-rw-r--r-- | CMakeLists.txt | 56 | ||||
-rw-r--r-- | cmake/prebuild.cmake | 27 | ||||
-rw-r--r-- | cmake/system.cmake | 2 | ||||
-rw-r--r-- | driver/others/memory.c | 22 | ||||
-rw-r--r-- | gen_config_h.c | 2 | ||||
-rw-r--r-- | utest/CMakeLists.txt | 2 |
6 files changed, 92 insertions, 19 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index b7602a31a..3bdc66f26 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,9 +120,12 @@ if (${NO_STATIC} AND ${NO_SHARED}) endif () #Set default output directory -set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib ) -set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib ) - +set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) +set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) +if(MSVC) +set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${PROJECT_BINARY_DIR}/lib/Debug) +set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BINARY_DIR}/lib/Release) +endif () # get obj vars into format that add_library likes: $<TARGET_OBJS:objlib> (see http://www.cmake.org/cmake/help/v3.0/command/add_library.html) set(TARGET_OBJS "") foreach (SUBDIR ${SUBDIRS}) @@ -142,9 +145,12 @@ if (NOT NO_LAPACKE) endif () endif () -#Only generate .def for dll on MSVC +# Only generate .def for dll on MSVC and always produce pdb files for debug and release if(MSVC) set(OpenBLAS_DEF_FILE "${PROJECT_BINARY_DIR}/openblas.def") +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi") +set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Zi") +set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF") endif() # add objects to the openblas lib @@ -159,15 +165,15 @@ set_target_properties( ${OpenBLAS_LIBNAME} PROPERTIES LIBRARY_OUTPUT_NAME_DEBUG foreach (OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES}) string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG ) - set_target_properties( ${OpenBLAS_LIBNAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_BINARY_DIR}/lib) - set_target_properties( ${OpenBLAS_LIBNAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_BINARY_DIR}/lib) - set_target_properties( ${OpenBLAS_LIBNAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_BINARY_DIR}/lib) + set_target_properties( ${OpenBLAS_LIBNAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_BINARY_DIR}/lib/${OUTPUTCONFIG} ) + set_target_properties( ${OpenBLAS_LIBNAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_BINARY_DIR}/lib/${OUTPUTCONFIG} ) + set_target_properties( ${OpenBLAS_LIBNAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_BINARY_DIR}/lib/${OUTPUTCONFIG} ) endforeach() enable_testing() add_subdirectory(utest) -if(NOT MSVC) +if (NOT MSVC) #only build shared library for MSVC add_library(${OpenBLAS_LIBNAME}_static STATIC ${LA_SOURCES} ${LAPACKE_SOURCES} ${TARGET_OBJS}) @@ -224,10 +230,7 @@ install(TARGETS ${OpenBLAS_LIBNAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ) # Install include files - add_executable(gen_config_h gen_config_h.c) - target_compile_definitions(gen_config_h PRIVATE VERSION=\"${OpenBLAS_VERSION}\") - message (STATUS "Generating openblas_config.h in ${CMAKE_BINARY_DIR}") - GET_TARGET_PROPERTY(GENCONFIG_BIN gen_config_h LOCATION) + set (GENCONFIG_BIN ${CMAKE_BINARY_DIR}/gen_config_h${CMAKE_EXECUTABLE_SUFFIX}) ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_BINARY_DIR}/openblas_config.h DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/config.h @@ -238,19 +241,32 @@ install(TARGETS ${OpenBLAS_LIBNAME} install (FILES ${CMAKE_BINARY_DIR}/openblas_config.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) message(STATUS "Generating f77blas.h in ${CMAKE_INSTALL_INCLUDEDIR}") +if (NOT MSVC) ADD_CUSTOM_TARGET(genf77blas COMMAND ${AWK} 'BEGIN{print \"\#ifndef OPENBLAS_F77BLAS_H\" \; print \"\#define OPENBLAS_F77BLAS_H\" \; print \"\#include \\"openblas_config.h\\" \"}; NF {print}; END{print \"\#endif\"}' ${CMAKE_CURRENT_SOURCE_DIR}/common_interface.h > ${CMAKE_BINARY_DIR}/f77blas.h - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/config.h ) +else () + ADD_CUSTOM_TARGET(genf77blas + COMMAND ${AWK} \"BEGIN{print \\\"\#ifndef OPENBLAS_F77BLAS_H\\\" \; print \\\"\#define OPENBLAS_F77BLAS_H\\\" \; print \\\"\#include \\\\\\"openblas_config.h\\\\\\" \\\"}; NF {print}; END{print \\\"\#endif\\\"}\" ${CMAKE_CURRENT_SOURCE_DIR}/common_interface.h > ${CMAKE_BINARY_DIR}/f77blas.h + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/config.h + ) +endif () install (FILES ${CMAKE_BINARY_DIR}/f77blas.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) if(NOT NO_CBLAS) message (STATUS "Generating cblas.h in ${CMAKE_INSTALL_INCLUDEDIR}") + if(NOT MSVC) ADD_CUSTOM_TARGET(gencblas - COMMAND sed 's/common/openblas_config/g' ${CMAKE_CURRENT_SOURCE_DIR}/cblas.h > "${CMAKE_BINARY_DIR}/cblas.h" + COMMAND ${SED} 's/common/openblas_config/g' ${CMAKE_CURRENT_SOURCE_DIR}/cblas.h > "${CMAKE_BINARY_DIR}/cblas.h" DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/cblas.h ) + else () + ADD_CUSTOM_TARGET(gencblas + COMMAND ${SED} "s/common/openblas_config/g" ${CMAKE_CURRENT_SOURCE_DIR}/cblas.h > "${CMAKE_BINARY_DIR}/cblas.h" + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/cblas.h + ) + endif () add_dependencies( ${OpenBLAS_LIBNAME} gencblas) install (FILES ${CMAKE_BINARY_DIR}/cblas.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) endif() @@ -277,3 +293,15 @@ if(PKG_CONFIG_FOUND) configure_file(${PROJECT_SOURCE_DIR}/cmake/openblas.pc.in ${PROJECT_BINARY_DIR}/openblas.pc @ONLY) install (FILES ${PROJECT_BINARY_DIR}/openblas.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig/) endif() + +# build dependencies graph +# add_dependencies(genconfig gen_config_h genf77blas gencblas) +add_dependencies(genconfig genf77blas gencblas) +add_dependencies(interface genconfig) +add_dependencies(kernel genconfig) +add_dependencies(driver_level2 genconfig) +add_dependencies(driver_level3 genconfig) +add_dependencies(driver_others genconfig) +add_dependencies(${OpenBLAS_LIBNAME} kernel driver_level2 driver_level3 driver_others interface) +add_dependencies(openblas_utest ${OpenBLAS_LIBNAME}) + diff --git a/cmake/prebuild.cmake b/cmake/prebuild.cmake index 471ce90e4..6a21c0bcc 100644 --- a/cmake/prebuild.cmake +++ b/cmake/prebuild.cmake @@ -4,7 +4,8 @@ ## This is triggered by system.cmake and runs before any of the code is built. ## Creates config.h and Makefile.conf by first running the c_check perl script (which creates those files). ## Next it runs f_check and appends some fortran information to the files. -## Finally it runs getarch and getarch_2nd for even more environment information. +## Then it runs getarch and getarch_2nd for even more environment information. +## Finally it builds gen_config_h for use at build time to generate config.h. # CMake vars set by this file: # CORE @@ -81,6 +82,10 @@ try_compile(GETARCH_RESULT ${GETARCH_DIR} COPY_FILE ${PROJECT_BINARY_DIR}/${GETARCH_BIN} ) +if (NOT ${GETARCH_RESULT}) + MESSAGE(FATAL_ERROR "Compiling getarch failed ${GETARCH_LOG}") +endif () + message(STATUS "Running getarch") # use the cmake binary w/ the -E param to run a shell command in a cross-platform way @@ -103,6 +108,10 @@ try_compile(GETARCH2_RESULT ${GETARCH2_DIR} COPY_FILE ${PROJECT_BINARY_DIR}/${GETARCH2_BIN} ) +if (NOT ${GETARCH2_RESULT}) + MESSAGE(FATAL_ERROR "Compiling getarch_2nd failed ${GETARCH2_LOG}") +endif () + # use the cmake binary w/ the -E param to run a shell command in a cross-platform way execute_process(COMMAND ${PROJECT_BINARY_DIR}/${GETARCH2_BIN} 0 OUTPUT_VARIABLE GETARCH2_MAKE_OUT) execute_process(COMMAND ${PROJECT_BINARY_DIR}/${GETARCH2_BIN} 1 OUTPUT_VARIABLE GETARCH2_CONF_OUT) @@ -111,3 +120,19 @@ execute_process(COMMAND ${PROJECT_BINARY_DIR}/${GETARCH2_BIN} 1 OUTPUT_VARIABLE file(APPEND ${TARGET_CONF} ${GETARCH2_CONF_OUT}) ParseGetArchVars(${GETARCH2_MAKE_OUT}) +# compile get_config_h +set(GEN_CONFIG_H_DIR "${PROJECT_BINARY_DIR}/genconfig_h_build") +set(GEN_CONFIG_H_BIN "gen_config_h${CMAKE_EXECUTABLE_SUFFIX}") +set(GEN_CONFIG_H_FLAGS "-DVERSION=\"${OpenBLAS_VERSION}\"") +file(MAKE_DIRECTORY ${GEN_CONFIG_H_DIR}) + +try_compile(GEN_CONFIG_H_RESULT ${GEN_CONFIG_H_DIR} + SOURCES ${PROJECT_SOURCE_DIR}/gen_config_h.c + COMPILE_DEFINITIONS ${EXFLAGS} ${GETARCH_FLAGS} ${GEN_CONFIG_H_FLAGS} -I${PROJECT_SOURCE_DIR} + OUTPUT_VARIABLE GEN_CONFIG_H_LOG + COPY_FILE ${PROJECT_BINARY_DIR}/${GEN_CONFIG_H_BIN} +) + +if (NOT ${GEN_CONFIG_H_RESULT}) + MESSAGE(FATAL_ERROR "Compiling gen_config_h failed ${GEN_CONFIG_H_LOG}") +endif () diff --git a/cmake/system.cmake b/cmake/system.cmake index ee64f85b4..75c8e9c55 100644 --- a/cmake/system.cmake +++ b/cmake/system.cmake @@ -312,6 +312,8 @@ endif () set(AWK awk) +set(SED sed) + set(REVISION "-r${OpenBLAS_VERSION}") set(MAJOR_VERSION ${OpenBLAS_MAJOR_VERSION}) diff --git a/driver/others/memory.c b/driver/others/memory.c index 8564b285b..916950315 100644 --- a/driver/others/memory.c +++ b/driver/others/memory.c @@ -1479,12 +1479,30 @@ static int on_process_term(void) #else #pragma comment(linker, "/INCLUDE:__tls_used") #endif -#pragma data_seg(push, old_seg) + +#ifdef _WIN64 +#pragma const_seg(".CRT$XLB") +#else #pragma data_seg(".CRT$XLB") +#endif static void (APIENTRY *dll_callback)(HINSTANCE h, DWORD ul_reason_for_call, PVOID pv) = DllMain; +#ifdef _WIN64 +#pragma const_seg() +#else +#pragma data_seg() +#endif + +#ifdef _WIN64 +#pragma const_seg(".CRT$XTU") +#else #pragma data_seg(".CRT$XTU") +#endif static int(*p_process_term)(void) = on_process_term; -#pragma data_seg(pop, old_seg) +#ifdef _WIN64 +#pragma const_seg() +#else +#pragma data_seg() +#endif #endif #if (defined(C_PGI) || (!defined(C_SUN) && defined(F_INTERFACE_SUN))) && (defined(ARCH_X86) || defined(ARCH_X86_64)) diff --git a/gen_config_h.c b/gen_config_h.c index e285724c0..dda06f285 100644 --- a/gen_config_h.c +++ b/gen_config_h.c @@ -16,7 +16,7 @@ s=fgets(line,80,fp); if (s== NULL) break; memset(line2,0,80); i=sscanf(line,"#define %70c",line2); -if (i>0) { +if (i!=0) { fprintf(stdout,"#define OPENBLAS_%s",line2); } else { fprintf(stdout,"\n"); diff --git a/utest/CMakeLists.txt b/utest/CMakeLists.txt index f0ffee088..9cf518e05 100644 --- a/utest/CMakeLists.txt +++ b/utest/CMakeLists.txt @@ -31,7 +31,7 @@ endforeach() if (MSVC) add_custom_command(TARGET ${OpenBLAS_utest_bin} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/lib/${OpenBLAS_LIBNAME}.dll ${CMAKE_CURRENT_BINARY_DIR}/. + COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/lib/$<CONFIG>/${OpenBLAS_LIBNAME}.dll ${CMAKE_CURRENT_BINARY_DIR}/. ) endif() |