diff --git a/.travis.yml b/.travis.yml index 0e73459..c8dd405 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,15 @@ language: cpp install: + # update, clean + - sudo apt-get update + - sudo apt-get clean + - sudo apt-get autoclean # compilers - sudo apt-get install g++ cmake gfortran + # libraries for static linking + - sudo apt-get install binutils-gold libc6-dev libpthread-stubs0-dev # math libraries - - sudo apt-get install libblas-dev liblapack-dev + - sudo apt-get install libblas-dev liblapack-dev libatlas-base-dev # MPI - sudo apt-get install openmpi-bin libopenmpi-dev # PEP8 and py.test diff --git a/modules/math_libs.cmake b/modules/math_libs.cmake index 1d12cef..ebe617e 100644 --- a/modules/math_libs.cmake +++ b/modules/math_libs.cmake @@ -5,6 +5,7 @@ # Variables used:: # # MATH_LIB_SEARCH_ORDER, example: set(MATH_LIB_SEARCH_ORDER MKL ESSL ATLAS ACML SYSTEM_NATIVE) +# ENABLE_STATIC_LINKING # ENABLE_BLAS # ENABLE_LAPACK # BLAS_FOUND @@ -48,6 +49,13 @@ # '-DBLAS_LANG=Fortran' # '-DLAPACK_LANG=Fortran' +#------------------------------------------------------------------------------- +# ENABLE_STATIC_LINKING + +if(ENABLE_STATIC_LINKING) + set(CMAKE_FIND_LIBRARY_SUFFIXES .a) +endif() + #------------------------------------------------------------------------------- # SYSTEM_NATIVE @@ -355,7 +363,8 @@ macro(config_math_service _SERVICE) if(MKL_COMPILER_BINDINGS MATCHES GNU) set(_omp_flag -fopenmp) endif() - if(MKL_COMPILER_BINDINGS MATCHES PGI) + # do not add -mp flag for PGI+MKL+STATIC_LINKING + if(MKL_COMPILER_BINDINGS MATCHES PGI AND NOT ENABLE_STATIC_LINKING) set(_omp_flag -mp) endif() endif() @@ -470,9 +479,24 @@ if("${MATH_LIBS}" STREQUAL "" AND "${MKL_FLAG}" STREQUAL "off") endforeach() endif() +#miro: first lapack, then blas as lapack might need blas routine set(MATH_LIBS ${MATH_LIBS} - ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} + ${BLAS_LIBRARIES} CACHE STRING "Math libraries" ) + +#miro: further adaptation for the static linking +if (ENABLE_STATIC_LINKING) + if (LAPACK_TYPE MATCHES ATLAS OR LAPACK_TYPE MATCHES SYSTEM_NATIVE OR BLAS_TYPE MATCHES ATLAS OR BLAS_TYPE MATCHES SYSTEM_NATIVE) + #miro: TODO: some compilers might need -lgfortran + set (MATH_LIBS ${MATH_LIBS} -Wl,--whole-archive -lpthread -Wl,--no-whole-archive) + endif() + if (LAPACK_TYPE MATCHES MKL OR BLAS_TYPE MATCHES MKL) + # miro: fix for MKL static linking (-lc not needed for PGI ) + set (MATH_LIBS ${MATH_LIBS} -ldl -lc) + endif() +endif() + + diff --git a/modules/static_linking.cmake b/modules/static_linking.cmake index 07a1af9..e1c6095 100644 --- a/modules/static_linking.cmake +++ b/modules/static_linking.cmake @@ -18,13 +18,13 @@ option(ENABLE_STATIC_LINKING "Enable static libraries linking" OFF) if(ENABLE_STATIC_LINKING) if(DEFINED CMAKE_Fortran_COMPILER_ID) if(CMAKE_Fortran_COMPILER_ID MATCHES GNU) - set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -static") + set(CMAKE_Fortran_FLAGS "-static ${CMAKE_Fortran_FLAGS}") endif() if(CMAKE_Fortran_COMPILER_ID MATCHES Intel) - set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -static-libgcc -static-intel") + set(CMAKE_Fortran_FLAGS "-static -static-libgcc -static-intel ${CMAKE_Fortran_FLAGS}") endif() if(CMAKE_Fortran_COMPILER_ID MATCHES PGI) - set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Bstatic") + set(CMAKE_Fortran_FLAGS "-Bstatic ${CMAKE_Fortran_FLAGS}") endif() endif() diff --git a/test/cxx/cmake/autocmake.cfg b/test/cxx/cmake/autocmake.cfg index e35cf0c..958d0b2 100644 --- a/test/cxx/cmake/autocmake.cfg +++ b/test/cxx/cmake/autocmake.cfg @@ -4,6 +4,9 @@ name: example [cxx] source: ../../../modules/cxx.cmake +[static] +source: ../../../modules/static_linking.cmake + [default_build_paths] source: ../../../modules/default_build_paths.cmake diff --git a/test/fc/cmake/autocmake.cfg b/test/fc/cmake/autocmake.cfg index 79e4a61..d892d02 100644 --- a/test/fc/cmake/autocmake.cfg +++ b/test/fc/cmake/autocmake.cfg @@ -4,6 +4,9 @@ name: example [fc] source: ../../../modules/fc.cmake +[static] +source: ../../../modules/static_linking.cmake + [default_build_paths] source: ../../../modules/default_build_paths.cmake diff --git a/test/fc_blas/cmake/autocmake.cfg b/test/fc_blas/cmake/autocmake.cfg index 8d08592..7314248 100644 --- a/test/fc_blas/cmake/autocmake.cfg +++ b/test/fc_blas/cmake/autocmake.cfg @@ -4,6 +4,9 @@ name: example [fc] source: ../../../modules/fc.cmake +[static] +source: ../../../modules/static_linking.cmake + [int64] source: ../../../modules/int64.cmake diff --git a/test/fc_blas/src/CMakeLists.txt b/test/fc_blas/src/CMakeLists.txt index 5c8f849..61fe45e 100644 --- a/test/fc_blas/src/CMakeLists.txt +++ b/test/fc_blas/src/CMakeLists.txt @@ -1,10 +1,15 @@ -if(BLAS_FOUND) - if(CMAKE_Fortran_COMPILER_ID MATCHES PGI) - # we remove -rdynamic flag added by CMake - # PGI Fortran does not recognize this flag - SET(CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS) - endif() +if(CMAKE_Fortran_COMPILER_ID MATCHES PGI) + # remove -rdynamic flag offensive for PGI Fortran + list(REMOVE_ITEM CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS "-rdynamic") +endif() +if(CMAKE_Fortran_COMPILER_ID MATCHES Intel AND ENABLE_STATIC_LINKING) + # prevent "ifort: ... warning #10121: overriding '-static-intel' with + # '-i_dynamic'" + list(REMOVE_ITEM CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS "-i_dynamic") +endif() + +if(BLAS_FOUND) add_executable(example example.f90) target_link_libraries(example ${MATH_LIBS}) else() diff --git a/test/fc_lapack/src/CMakeLists.txt b/test/fc_lapack/src/CMakeLists.txt index d03b41f..b80d7f7 100644 --- a/test/fc_lapack/src/CMakeLists.txt +++ b/test/fc_lapack/src/CMakeLists.txt @@ -1,10 +1,14 @@ -if(LAPACK_FOUND) - if(CMAKE_Fortran_COMPILER_ID MATCHES PGI) - # we remove -rdynamic flag added by CMake - # PGI Fortran does not recognize this flag - SET(CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS) - endif() +if(CMAKE_Fortran_COMPILER_ID MATCHES PGI) + # remove -rdynamic flag offensive for PGI Fortran + list(REMOVE_ITEM CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS "-rdynamic") +endif() +if(CMAKE_Fortran_COMPILER_ID MATCHES Intel AND ENABLE_STATIC_LINKING) + # prevent "ifort: ... warning #10121: overriding '-static-intel' with '-i_dynamic'" + list(REMOVE_ITEM CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS "-i_dynamic") +endif() + +if(LAPACK_FOUND) add_executable(example example.F90) target_link_libraries(example ${MATH_LIBS}) else() diff --git a/test/test.py b/test/test.py index ddb27fe..e5ac9c9 100644 --- a/test/test.py +++ b/test/test.py @@ -132,6 +132,10 @@ def test_extra_cmake_options(): def test_cxx(): configure_build_and_exe('cxx', 'python setup.py --cxx=g++') + +def test_cxx_static(): + configure_build_and_exe('cxx', 'python setup.py --cxx=g++ --static') + # ------------------------------------------------------------------------------ @@ -165,6 +169,10 @@ def test_fc_omp(): os.environ['OMP_NUM_THREADS'] = '2' configure_build_and_exe('fc_omp', 'python setup.py --omp --fc=gfortran') + +def test_fc_static(): + configure_build_and_exe('fc', 'python setup.py --fc=gfortran --static') + # ------------------------------------------------------------------------------ @@ -172,9 +180,19 @@ def test_fc_omp(): def test_fc_blas(): configure_build_and_exe('fc_blas', 'python setup.py --fc=gfortran') + +@no_windows +def test_fc_blas_static(): + configure_build_and_exe('fc_blas', 'python setup.py --fc=gfortran --static') + # ------------------------------------------------------------------------------ @no_windows def test_fc_lapack(): configure_build_and_exe('fc_lapack', 'python setup.py --fc=gfortran') + + +@no_windows +def test_fc_lapack_static(): + configure_build_and_exe('fc_lapack', 'python setup.py --fc=gfortran --static --cmake-options="-DMATH_LIB_SEARCH_ORDER=ATLAS"')