From 89d5cee4c1bccffeeae233a7e5ab0dc2fd183cb9 Mon Sep 17 00:00:00 2001 From: Deve Date: Mon, 2 Mar 2015 19:30:26 +0100 Subject: [PATCH] MinGW: Better finding libraries --- CMakeLists.txt | 22 ++++++++++++++++------ cmake/Toolchain-mingw.cmake | 6 +++--- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7cc9cb17e..b193ff600 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -278,7 +278,7 @@ else() if(MSVC) set(PTHREAD_NAMES pthreadVC2) elseif(MINGW) - set(PTHREAD_NAMES "winpthread-1" pthreadGC2) + set(PTHREAD_NAMES "winpthread-1" "pthreadGC2" "libwinpthread-1") endif() find_library(PTHREAD_LIBRARY NAMES pthread ${PTHREAD_NAMES} PATHS ${PROJECT_SOURCE_DIR}/dependencies/lib) mark_as_advanced(PTHREAD_LIBRARY) @@ -380,12 +380,22 @@ if(MSVC OR MINGW) endif() if(MINGW) - find_library(LIBGCC NAMES libgcc_s_dw2-1.dll libgcc_s_sjlj-1.dll) - find_library(LIBSTDCPP NAMES libstdc++-6.dll) - if(OPENMP_FOUND) - find_library(LIBOPENMP NAMES libgomp-1.dll) + find_library(LIBGCC NAMES "libgcc_s_dw2-1.dll" "libgcc_s_sjlj-1.dll" PATHS ${CMAKE_FIND_ROOT_PATH}) + if(LIBGCC) + file(COPY ${LIBGCC} DESTINATION ${CMAKE_BINARY_DIR}/bin/) + endif() + find_library(LIBSTDCPP NAMES "libstdc++-6.dll" PATHS ${CMAKE_FIND_ROOT_PATH}) + if(LIBSTDCPP) + file(COPY ${LIBSTDCPP} DESTINATION ${CMAKE_BINARY_DIR}/bin/) + endif() + find_library(LIBOPENMP NAMES "libgomp-1.dll" PATHS ${CMAKE_FIND_ROOT_PATH}) + if(LIBOPENMP) + file(COPY ${LIBOPENMP} DESTINATION ${CMAKE_BINARY_DIR}/bin/) + endif() + find_library(LIBPTHREAD NAMES "winpthread-1.dll" "pthreadGC2.dll" "libwinpthread-1.dll" PATHS ${CMAKE_FIND_ROOT_PATH}) + if(LIBPTHREAD) + file(COPY ${LIBPTHREAD} DESTINATION ${CMAKE_BINARY_DIR}/bin/) endif() - file(COPY ${LIBGCC} ${LIBSTDCPP} ${PTHREAD_LIBRARY} ${LIBOPENMP} DESTINATION ${CMAKE_BINARY_DIR}/bin/) endif() # Optional tools diff --git a/cmake/Toolchain-mingw.cmake b/cmake/Toolchain-mingw.cmake index 1ecb47ac2..56908e12e 100644 --- a/cmake/Toolchain-mingw.cmake +++ b/cmake/Toolchain-mingw.cmake @@ -7,11 +7,11 @@ SET(CMAKE_CXX_COMPILER i686-w64-mingw32-g++-posix) SET(CMAKE_RC_COMPILER i686-w64-mingw32-windres) # here is the target environment located -SET(CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32 ${PROJECT_SOURCE_DIR}/dependencies) +SET(CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32 /usr/lib/gcc/i686-w64-mingw32/4.9-posix ${PROJECT_SOURCE_DIR}/dependencies) # adjust the default behaviour of the FIND_XXX() commands: # search headers and libraries in the target environment, search # programs in the host environment set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) -set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) \ No newline at end of file +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ALWAYS) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)