Fix installation of header files with cmake (#1186)

* Fix installation of header files with cmake 

Install only the required header files, with openblas_config.h preprocessed like in Makefile.install
Fixes #1184

* Update CMakeLists.txt

Escape remaining semicolons in awk argument list (to get it working on Windows as well)

* Update CMakeLists.txt

* Update CMakeLists.txt

* Update CMakeLists.txt

* Update CMakeLists.txt

* Update CMakeLists.txt

* Add files via upload

* Update CMakeLists.txt

* Update CMakeLists.txt

* Update CMakeLists.txt

see if it is the single quotes that cause the problem on windows

* Update CMakeLists.txt

* Update CMakeLists.txt

* Update CMakeLists.txt

* Update CMakeLists.txt

* Update CMakeLists.txt

* Use C utility instead of awk for header generation in cmake builds

* Update CMakeLists.txt

* Fix generation and installation of header files

Generate openblas_config.h and f77blas.h with same contents as in plain Makefile builds and install only the public header files
This commit is contained in:
Martin Kroeker 2017-06-01 16:36:26 +02:00 committed by GitHub
parent 410a07cbec
commit 8f0d6c06a9
2 changed files with 79 additions and 2 deletions

View File

@ -224,8 +224,49 @@ install(TARGETS ${OpenBLAS_LIBNAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} )
# Install include files
FILE(GLOB_RECURSE INCLUDE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
install (FILES ${INCLUDE_FILES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
add_executable(gen_config_h gen_config_h.c)
target_compile_definitions(gen_config_h PRIVATE VERSION=\"${OpenBLAS_VERSION}\")
message (STATUS "Generating openblas_config.h in ${CMAKE_BINARY_DIR}")
GET_TARGET_PROPERTY(GENCONFIG_BIN gen_config_h LOCATION)
ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_BINARY_DIR}/openblas_config.h
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/config.h
COMMAND ${GENCONFIG_BIN} ${CMAKE_CURRENT_SOURCE_DIR}/config.h ${CMAKE_CURRENT_SOURCE_DIR}/openblas_config_template.h > ${CMAKE_BINARY_DIR}/openblas_config.h
)
ADD_CUSTOM_TARGET(genconfig DEPENDS openblas_config.h)
add_dependencies( ${OpenBLAS_LIBNAME} genconfig genf77blas)
install (FILES ${CMAKE_BINARY_DIR}/openblas_config.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
message(STATUS "Generating f77blas.h in ${CMAKE_INSTALL_INCLUDEDIR}")
ADD_CUSTOM_TARGET(genf77blas
COMMAND ${AWK} 'BEGIN{print \"\#ifndef OPENBLAS_F77BLAS_H\" \; print \"\#define OPENBLAS_F77BLAS_H\" \; print \"\#include \\"openblas_config.h\\" \"}; NF {print}; END{print \"\#endif\"}' ${CMAKE_CURRENT_SOURCE_DIR}/common_interface.h > ${CMAKE_BINARY_DIR}/f77blas.h
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/config.h
)
install (FILES ${CMAKE_BINARY_DIR}/f77blas.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
if(NOT NO_CBLAS)
message (STATUS "Generating cblas.h in ${CMAKE_INSTALL_INCLUDEDIR}")
ADD_CUSTOM_TARGET(gencblas
COMMAND sed 's/common/openblas_config/g' ${CMAKE_CURRENT_SOURCE_DIR}/cblas.h > "${CMAKE_BINARY_DIR}/cblas.h"
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/cblas.h
)
add_dependencies( ${OpenBLAS_LIBNAME} gencblas)
install (FILES ${CMAKE_BINARY_DIR}/cblas.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()
if(NOT NO_LAPACKE)
message (STATUS "Copying LAPACKE header files to ${CMAKE_INSTALL_INCLUDEDIR}")
add_dependencies( ${OpenBLAS_LIBNAME} genlapacke)
FILE(GLOB_RECURSE INCLUDE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/lapack-netlib/LAPACKE/*.h")
install (FILES ${INCLUDE_FILES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
ADD_CUSTOM_TARGET(genlapacke
COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/lapack-netlib/LAPACKE/include/lapacke_mangling_with_flags.h.in "${CMAKE_BINARY_DIR}/lapacke_mangling.h"
)
install (FILES ${CMAKE_BINARY_DIR}/lapacke_mangling.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()
if(NOT MSVC)
install (TARGETS ${OpenBLAS_LIBNAME}_static DESTINATION ${CMAKE_INSTALL_LIBDIR})

36
gen_config_h.c Normal file
View File

@ -0,0 +1,36 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char**argv) {
FILE *fp;
char line[100];
char line2[80];
char *s;
int i;
fprintf(stdout,"#ifndef OPENBLAS_CONFIG_H\n");
fprintf(stdout,"#define OPENBLAS_CONFIG_H\n");
fp=fopen(argv[1],"r");
do{
s=fgets(line,80,fp);
if (s== NULL) break;
memset(line2,0,80);
i=sscanf(line,"#define %70c",line2);
if (i>0) {
fprintf(stdout,"#define OPENBLAS_%s",line2);
} else {
fprintf(stdout,"\n");
}
} while (1);
fclose(fp);
fprintf(stdout,"#define OPENBLAS_VERSION \"OpenBLAS %s\"\n", VERSION);
fp=fopen(argv[2],"r");
do{
s=fgets(line,100,fp);
if (s== NULL) break;
fprintf(stdout,"%s",line);
} while(1);
fclose(fp);
fprintf(stdout,"#endif /* OPENBLAS_CONFIG_H */\n");
exit(0);
}