Fix GSL port so that CMake can find it

- Remove lib prefix from library
- Generate separate library for the cblas part
This commit is contained in:
Martin Müller 2017-05-31 10:42:25 +02:00
parent 683d8a8820
commit ed826d8412
1 changed files with 18 additions and 7 deletions

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.8)
project(libgsl C)
project(gsl C)
option(INSTALL_HEADERS "Install public header files" ON)
@ -27,10 +27,15 @@ function(extract_sources SUBFOLDER ALLSOURCES)
endfunction(extract_sources)
set(SOURCES)
set(CBLAS_SOURCES)
extract_from_makefile("SUBDIRS = ([^\n]*)" FOLDERS "./Makefile.am")
extract_sources("." SOURCES)
foreach(DIR IN LISTS FOLDERS)
extract_sources("${DIR}" SOURCES)
if("${DIR}" STREQUAL "cblas")
extract_sources("${DIR}" CBLAS_SOURCES)
else()
extract_sources("${DIR}" SOURCES)
endif()
endforeach()
file(READ gsl_types.h GSLTYPES_H)
@ -43,13 +48,19 @@ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/gsl_types.h "${GSLTYPES_H}")
file(GLOB_RECURSE PUBLIC_HEADERS gsl*.h)
list(APPEND PUBLIC_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/gsl_types.h)
add_library(libgsl ${SOURCES})
set_target_properties(libgsl PROPERTIES DEFINE_SYMBOL DLL_EXPORT WINDOWS_EXPORT_ALL_SYMBOLS ON)
add_library(gslcblas ${CBLAS_SOURCES})
set_target_properties(gslcblas PROPERTIES DEFINE_SYMBOL DLL_EXPORT WINDOWS_EXPORT_ALL_SYMBOLS ON)
add_library(gsl ${SOURCES})
set_target_properties(gsl PROPERTIES DEFINE_SYMBOL DLL_EXPORT WINDOWS_EXPORT_ALL_SYMBOLS ON)
target_link_libraries(gsl PUBLIC gslcblas)
if(INSTALL_HEADERS)
set_target_properties(libgsl PROPERTIES PUBLIC_HEADER "${PUBLIC_HEADERS}")
set_target_properties(gsl PROPERTIES PUBLIC_HEADER "${PUBLIC_HEADERS}")
endif()
target_include_directories(libgsl PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(gslcblas PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(gsl PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
# For the build, we need to copy all headers to the gsl directory
file(COPY ${PUBLIC_HEADERS} DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/gsl")
@ -58,7 +69,7 @@ if(INSTALL_HEADERS)
set(TARGET_INSTALL_OPTIONS PUBLIC_HEADER DESTINATION include/gsl)
endif()
install(TARGETS libgsl
install(TARGETS gsl gslcblas
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib