#######################################################################
#  This is the makefile to create a library for the BLAS.
#  The files are grouped as follows:
#
#      ALLBLAS -- Auxiliary routines for Level 2 and 3 BLAS
#
#######################################################################

add_subdirectory(double)
add_subdirectory(single)

add_compile_options(-fPIC -Wall -Wextra -Wpedantic -lm -O3 -march=native -mtune=native)

#---------------------------------------------------------------------
#  Auxiliary routines needed by both the Level 2 and Level 3 BLAS
#---------------------------------------------------------------------
set(ALLBLAS lsame.c xerbla.c xerbla_array.c)

set(SOURCES)
if(BUILD_SINGLE)
  list(APPEND SOURCES ${SBLAS1} ${ALLBLAS} ${SBLAS2} ${SBLAS3})
endif()
if(BUILD_DOUBLE)
  list(APPEND SOURCES ${DBLAS1} ${ALLBLAS} ${DBLAS2} ${DBLAS3})
endif()
if(BUILD_COMPLEX)
  list(APPEND SOURCES abssq.c ${CBLAS1} ${CB1AUX} ${ALLBLAS} ${CBLAS2} ${CBLAS3})
endif()
if(BUILD_COMPLEX16)
  list(APPEND SOURCES abssq.c ${ZBLAS1} ${ZB1AUX} ${ALLBLAS} ${ZBLAS2} ${ZBLAS3})
endif()
list(REMOVE_DUPLICATES SOURCES)

add_library(${BLASLIB} ${SOURCES})
set_target_properties(
  ${BLASLIB} PROPERTIES
  VERSION ${BLAS_VERSION}
  SOVERSION ${BLAS_MAJOR_VERSION}
  )

blas_install_library(${BLASLIB})

add_custom_command(
  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated_header.h
  COMMAND ${CMAKE_COMMAND} -E echo "#define SOME_VALUE 123" > ${CMAKE_CURRENT_BINARY_DIR}/generated_header.h
  COMMENT "Generating header file..."
)

# Add the generated file to the list of sources
set(SOURCES ${SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/generated_header.h)
