2017-05-01 21:49:29 +08:00
|
|
|
cmake_minimum_required(VERSION 3.8)
|
2017-05-31 16:42:25 +08:00
|
|
|
project(gsl C)
|
2017-05-01 21:49:29 +08:00
|
|
|
|
|
|
|
option(INSTALL_HEADERS "Install public header files" ON)
|
|
|
|
|
|
|
|
# Function to extract parameter from makefile. Space separated values are returned as lists
|
|
|
|
function(extract_from_makefile PATTERN RETURN FILEPATH)
|
|
|
|
file(READ ${FILEPATH} MAKEFILE_CONTENT)
|
|
|
|
string(REGEX MATCH "${PATTERN}" CONTENTS "${MAKEFILE_CONTENT}")
|
|
|
|
set(CONTENTS ${CMAKE_MATCH_1})
|
|
|
|
# Split string into list
|
2020-04-09 18:41:16 +08:00
|
|
|
string(REGEX REPLACE "([\t ]+(\\\\\n)?)+" ";" CONTENTS "${CONTENTS}")
|
|
|
|
string(REGEX REPLACE "[\t ]*\\\\\n[\t ]*;" "" CONTENTS "${CONTENTS}")
|
2017-05-01 21:49:29 +08:00
|
|
|
if("${CONTENTS}" STREQUAL "")
|
|
|
|
message(AUTHOR_WARNING "No match for \"${PATTERN}\" found in file ${FILEPATH}")
|
|
|
|
endif()
|
|
|
|
# Return
|
|
|
|
set(${RETURN} ${CONTENTS} PARENT_SCOPE)
|
|
|
|
endfunction(extract_from_makefile)
|
|
|
|
|
|
|
|
# Function to extract C sources from makefile
|
|
|
|
function(extract_sources SUBFOLDER ALLSOURCES)
|
2020-04-09 18:41:16 +08:00
|
|
|
extract_from_makefile("lib[a-zA-Z1-9_]*_la_SOURCES[ \t]*=[ \t]*(((\\\\\n)?[^\n])*)" SOURCEFILES "${SUBFOLDER}/Makefile.am")
|
|
|
|
# Add the folder in front of the file names
|
2017-05-01 21:49:29 +08:00
|
|
|
string(REGEX REPLACE "([^;]+)" "${SUBFOLDER}/\\1" SOURCEFILES "${SOURCEFILES}")
|
|
|
|
# Return
|
|
|
|
set(${ALLSOURCES} ${${ALLSOURCES}} ${SOURCEFILES} PARENT_SCOPE)
|
|
|
|
endfunction(extract_sources)
|
|
|
|
|
|
|
|
set(SOURCES)
|
2017-05-31 16:42:25 +08:00
|
|
|
set(CBLAS_SOURCES)
|
2020-04-09 18:41:16 +08:00
|
|
|
extract_from_makefile("SUBDIRS = (((\\\\\n)?[^\n])*)" FOLDERS "./Makefile.am")
|
2017-05-01 21:49:29 +08:00
|
|
|
extract_sources("." SOURCES)
|
|
|
|
foreach(DIR IN LISTS FOLDERS)
|
2017-05-31 16:42:25 +08:00
|
|
|
if("${DIR}" STREQUAL "cblas")
|
|
|
|
extract_sources("${DIR}" CBLAS_SOURCES)
|
|
|
|
else()
|
|
|
|
extract_sources("${DIR}" SOURCES)
|
|
|
|
endif()
|
2017-05-01 21:49:29 +08:00
|
|
|
endforeach()
|
|
|
|
|
|
|
|
file(READ gsl_types.h GSLTYPES_H)
|
|
|
|
string(REPLACE "#ifdef WIN32" "#if 1 /*WIN32*/" GSLTYPES_H "${GSLTYPES_H}")
|
|
|
|
if(BUILD_SHARED_LIBS)
|
|
|
|
string(REPLACE "# ifdef GSL_DLL" "# if 1 /*GSL_DLL*/" GSLTYPES_H "${GSLTYPES_H}")
|
|
|
|
endif()
|
|
|
|
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)
|
|
|
|
|
2017-07-21 16:48:20 +08:00
|
|
|
# The debug libraries have a "d" postfix so that CMake's FindGSL.cmake
|
|
|
|
# module can distinguish between Release and Debug libraries
|
|
|
|
set(CMAKE_DEBUG_POSTFIX "d")
|
|
|
|
|
2017-05-31 16:42:25 +08:00
|
|
|
add_library(gslcblas ${CBLAS_SOURCES})
|
2017-05-31 18:13:48 +08:00
|
|
|
set_target_properties(gslcblas PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
2017-05-31 16:42:25 +08:00
|
|
|
|
|
|
|
add_library(gsl ${SOURCES})
|
|
|
|
set_target_properties(gsl PROPERTIES DEFINE_SYMBOL DLL_EXPORT WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
|
|
|
target_link_libraries(gsl PUBLIC gslcblas)
|
|
|
|
|
2017-05-01 21:49:29 +08:00
|
|
|
|
|
|
|
if(INSTALL_HEADERS)
|
2017-05-31 16:42:25 +08:00
|
|
|
set_target_properties(gsl PROPERTIES PUBLIC_HEADER "${PUBLIC_HEADERS}")
|
2017-05-01 21:49:29 +08:00
|
|
|
endif()
|
2018-03-08 03:56:21 +08:00
|
|
|
target_include_directories(gslcblas PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
target_include_directories(gsl PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
|
2017-05-01 21:49:29 +08:00
|
|
|
# For the build, we need to copy all headers to the gsl directory
|
2018-03-08 03:56:21 +08:00
|
|
|
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/gsl)
|
|
|
|
file(COPY ${PUBLIC_HEADERS} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/gsl")
|
2017-05-01 21:49:29 +08:00
|
|
|
|
|
|
|
set(TARGET_INSTALL_OPTIONS)
|
|
|
|
if(INSTALL_HEADERS)
|
|
|
|
set(TARGET_INSTALL_OPTIONS PUBLIC_HEADER DESTINATION include/gsl)
|
|
|
|
endif()
|
|
|
|
|
2017-05-31 16:42:25 +08:00
|
|
|
install(TARGETS gsl gslcblas
|
2017-05-01 21:49:29 +08:00
|
|
|
RUNTIME DESTINATION bin
|
|
|
|
LIBRARY DESTINATION lib
|
|
|
|
ARCHIVE DESTINATION lib
|
|
|
|
${TARGET_INSTALL_OPTIONS}
|
2017-07-21 16:48:20 +08:00
|
|
|
)
|