From 2644031ac8258528344d380e815aee75e291e0f3 Mon Sep 17 00:00:00 2001 From: Paul Sutton Date: Mon, 16 Jan 2017 16:23:10 +0000 Subject: [PATCH] Adding option to statically link MKL --- CMakeLists.txt | 3 ++- cmake/modules/FindMKL.cmake | 32 ++++++++++++++++++++++++++------ srslte/lib/CMakeLists.txt | 15 +++++++++++---- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fec7856b9..86df46c34 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,7 @@ configure_file( # Options ######################################################################## option(DisableMEX "DisableMEX" ON) +option(StaticMKL "StaticMKL" OFF) ######################################################################## # Install Dirs @@ -98,7 +99,7 @@ endif(CMAKE_COMPILER_IS_GNUCXX) if(CMAKE_COMPILER_IS_GNUCC) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-write-strings -Wno-format-extra-args -Winline -Wno-unused-result -Wno-format -std=c99 -D_GNU_SOURCE -g") - + if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") find_package(SSE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0") diff --git a/cmake/modules/FindMKL.cmake b/cmake/modules/FindMKL.cmake index 2320cf065..ef9d53379 100644 --- a/cmake/modules/FindMKL.cmake +++ b/cmake/modules/FindMKL.cmake @@ -5,23 +5,43 @@ # MKL_LIBRARIES - The libraries needed to use mkl # MKL_DEFINITIONS - Compiler switches required for using mkl -find_path(MKL_INCLUDE_DIR +find_path(MKL_INCLUDE_DIRS NAMES mkl.h HINTS $ENV{MKL_DIR}/include PATHS) -find_library(MKL_LIBRARY +find_library(MKL_LIBRARIES NAMES mkl_rt HINTS $ENV{MKL_DIR}/lib/intel64 PATHS) -set(MKL_LIBRARIES ${MKL_LIBRARY} ) -set(MKL_INCLUDE_DIRS ${MKL_INCLUDE_DIR} ) +find_library(MKL_CORE + NAMES libmkl_core.a + HINTS $ENV{MKL_DIR}/lib/intel64 + PATHS) + +find_library(MKL_ILP + NAMES libmkl_intel_ilp64.a + HINTS $ENV{MKL_DIR}/lib/intel64 + PATHS) + +find_library(MKL_SEQ + NAMES libmkl_sequential.a + HINTS $ENV{MKL_DIR}/lib/intel64 + PATHS) + +set(MKL_STATIC_LIBRARIES -Wl,--start-group ${MKL_CORE} ${MKL_ILP} ${MKL_SEQ} -Wl,--end-group -lpthread -lm -ldl) include(FindPackageHandleStandardArgs) # handle the QUIETLY and REQUIRED arguments and set MKL_FOUND to TRUE # if all listed variables are TRUE find_package_handle_standard_args(mkl DEFAULT_MSG - MKL_LIBRARY MKL_INCLUDE_DIR) + MKL_LIBRARIES MKL_CORE MKL_ILP MKL_SEQ MKL_INCLUDE_DIRS) + +if(MKL_FOUND) + MESSAGE(STATUS "Found MKL_INCLUDE_DIRS: ${MKL_INCLUDE_DIRS}" ) + MESSAGE(STATUS "Found MKL_LIBRARIES: ${MKL_LIBRARIES}" ) + MESSAGE(STATUS "Found MKL_STATIC_LIBRARIES: ${MKL_STATIC_LIBRARIES}" ) +endif(MKL_FOUND) -mark_as_advanced(MKL_INCLUDE_DIR MKL_LIBRARY ) +mark_as_advanced(MKL_INCLUDE_DIRS MKL_LIBRARIES MKL_CORE MKL_ILP MKL_SEQ) diff --git a/srslte/lib/CMakeLists.txt b/srslte/lib/CMakeLists.txt index 3a73d8761..6047ac78d 100644 --- a/srslte/lib/CMakeLists.txt +++ b/srslte/lib/CMakeLists.txt @@ -69,10 +69,17 @@ if(NOT DisableMEX) endif(NOT DisableMEX) if(MKL_FOUND) - target_link_libraries(srslte ${MKL_LIBRARIES}) - if(NOT DisableMEX) - target_link_libraries(srslte_static ${MKL_LIBRARIES}) - endif(NOT DisableMEX) + if(StaticMKL) + target_link_libraries(srslte ${MKL_STATIC_LIBRARIES}) + if(NOT DisableMEX) + target_link_libraries(srslte_static ${MKL_STATIC_LIBRARIES}) + endif(NOT DisableMEX) + else(StaticMKL) + target_link_libraries(srslte ${MKL_LIBRARIES}) + if(NOT DisableMEX) + target_link_libraries(srslte_static ${MKL_LIBRARIES}) + endif(NOT DisableMEX) + endif(StaticMKL) else(MKL_FOUND) target_link_libraries(srslte ${FFTW3F_LIBRARIES}) if(NOT DisableMEX)