Skip to content

Commit 8f0d6c0

Browse files
authored
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
1 parent 410a07c commit 8f0d6c0

2 files changed

Lines changed: 79 additions & 2 deletions

File tree

CMakeLists.txt

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,49 @@ install(TARGETS ${OpenBLAS_LIBNAME}
224224
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} )
225225

226226
# Install include files
227-
FILE(GLOB_RECURSE INCLUDE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
228-
install (FILES ${INCLUDE_FILES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
227+
add_executable(gen_config_h gen_config_h.c)
228+
target_compile_definitions(gen_config_h PRIVATE VERSION=\"${OpenBLAS_VERSION}\")
229+
message (STATUS "Generating openblas_config.h in ${CMAKE_BINARY_DIR}")
230+
GET_TARGET_PROPERTY(GENCONFIG_BIN gen_config_h LOCATION)
231+
ADD_CUSTOM_COMMAND(
232+
OUTPUT ${CMAKE_BINARY_DIR}/openblas_config.h
233+
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/config.h
234+
COMMAND ${GENCONFIG_BIN} ${CMAKE_CURRENT_SOURCE_DIR}/config.h ${CMAKE_CURRENT_SOURCE_DIR}/openblas_config_template.h > ${CMAKE_BINARY_DIR}/openblas_config.h
235+
)
236+
ADD_CUSTOM_TARGET(genconfig DEPENDS openblas_config.h)
237+
add_dependencies( ${OpenBLAS_LIBNAME} genconfig genf77blas)
238+
install (FILES ${CMAKE_BINARY_DIR}/openblas_config.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
239+
240+
message(STATUS "Generating f77blas.h in ${CMAKE_INSTALL_INCLUDEDIR}")
241+
ADD_CUSTOM_TARGET(genf77blas
242+
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
243+
244+
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/config.h
245+
)
246+
install (FILES ${CMAKE_BINARY_DIR}/f77blas.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
247+
248+
if(NOT NO_CBLAS)
249+
message (STATUS "Generating cblas.h in ${CMAKE_INSTALL_INCLUDEDIR}")
250+
ADD_CUSTOM_TARGET(gencblas
251+
COMMAND sed 's/common/openblas_config/g' ${CMAKE_CURRENT_SOURCE_DIR}/cblas.h > "${CMAKE_BINARY_DIR}/cblas.h"
252+
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/cblas.h
253+
)
254+
add_dependencies( ${OpenBLAS_LIBNAME} gencblas)
255+
install (FILES ${CMAKE_BINARY_DIR}/cblas.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
256+
endif()
257+
258+
if(NOT NO_LAPACKE)
259+
message (STATUS "Copying LAPACKE header files to ${CMAKE_INSTALL_INCLUDEDIR}")
260+
add_dependencies( ${OpenBLAS_LIBNAME} genlapacke)
261+
FILE(GLOB_RECURSE INCLUDE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/lapack-netlib/LAPACKE/*.h")
262+
install (FILES ${INCLUDE_FILES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
263+
264+
265+
ADD_CUSTOM_TARGET(genlapacke
266+
COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/lapack-netlib/LAPACKE/include/lapacke_mangling_with_flags.h.in "${CMAKE_BINARY_DIR}/lapacke_mangling.h"
267+
)
268+
install (FILES ${CMAKE_BINARY_DIR}/lapacke_mangling.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
269+
endif()
229270
230271
if(NOT MSVC)
231272
install (TARGETS ${OpenBLAS_LIBNAME}_static DESTINATION ${CMAKE_INSTALL_LIBDIR})

gen_config_h.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
int main(int argc, char**argv) {
5+
FILE *fp;
6+
char line[100];
7+
char line2[80];
8+
char *s;
9+
int i;
10+
11+
fprintf(stdout,"#ifndef OPENBLAS_CONFIG_H\n");
12+
fprintf(stdout,"#define OPENBLAS_CONFIG_H\n");
13+
fp=fopen(argv[1],"r");
14+
do{
15+
s=fgets(line,80,fp);
16+
if (s== NULL) break;
17+
memset(line2,0,80);
18+
i=sscanf(line,"#define %70c",line2);
19+
if (i>0) {
20+
fprintf(stdout,"#define OPENBLAS_%s",line2);
21+
} else {
22+
fprintf(stdout,"\n");
23+
}
24+
} while (1);
25+
fclose(fp);
26+
fprintf(stdout,"#define OPENBLAS_VERSION \"OpenBLAS %s\"\n", VERSION);
27+
fp=fopen(argv[2],"r");
28+
do{
29+
s=fgets(line,100,fp);
30+
if (s== NULL) break;
31+
fprintf(stdout,"%s",line);
32+
} while(1);
33+
fclose(fp);
34+
fprintf(stdout,"#endif /* OPENBLAS_CONFIG_H */\n");
35+
exit(0);
36+
}

0 commit comments

Comments
 (0)