From 0d8e227ea76514ce18db97a544197ec5c49d0c96 Mon Sep 17 00:00:00 2001 From: Hank Anderson Date: Tue, 24 Feb 2015 12:26:33 -0600 Subject: [PATCH] Changed strategy for setting preprocessor definitions. Instead of generating separate object files for each permutation of defines for a source file, GenerateNamedObjects now writes an entirely new source file and inserts the defines as #define c statements. This solves a problem I ran into with ar.exe where it was refusing to link objects that had the same filename despite having different paths. --- CMakeLists.txt | 16 ++++------------ cmake/utils.cmake | 29 ++++++++++++++++++++--------- driver/level2/CMakeLists.txt | 3 +-- driver/level3/CMakeLists.txt | 3 +-- driver/others/CMakeLists.txt | 11 +---------- interface/CMakeLists.txt | 3 +-- kernel/CMakeLists.txt | 2 +- lapack/CMakeLists.txt | 2 +- 8 files changed, 30 insertions(+), 39 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 85b20b176..530f3dda3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,24 +75,16 @@ if (NOT DEFINED CORE OR "${CORE}" STREQUAL "UNKNOWN") message(FATAL_ERROR "Detecting CPU failed. Please set TARGET explicitly, e.g. make TARGET=your_cpu_target. Please read README for details.") endif () -# Let CMake handle this -#if (${NOFORTRAN}) -# message(ERROR "OpenBLAS: Detecting fortran compiler failed. Please install fortran compiler, e.g. gfortran, ifort, openf90.") -#endif () - if (${NO_STATIC} AND ${NO_SHARED}) message(FATAL_ERROR "Neither static nor shared are enabled.") endif () -set(DBLAS_OBJS "") -foreach (SUBDIR ${SUBDIRS}) - add_subdirectory(${SUBDIR}) -endforeach () - # get obj vars into format that add_library likes: $ (see http://www.cmake.org/cmake/help/v3.0/command/add_library.html) set(TARGET_OBJS "") -foreach (DBLAS_OBJ ${DBLAS_OBJS}) - list(APPEND TARGET_OBJS "$") +foreach (SUBDIR ${SUBDIRS}) + add_subdirectory(${SUBDIR}) + string(REPLACE "/" "_" subdir_obj ${SUBDIR}) + list(APPEND TARGET_OBJS "$") endforeach () # netlib: diff --git a/cmake/utils.cmake b/cmake/utils.cmake index edf25cdb2..498c3840a 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -13,7 +13,6 @@ function(ParseGetArchVars GETARCH_IN) endfunction () # Reads a Makefile into CMake vars. -# TODO: respect IFDEF/IFNDEF? macro(ParseMakefileVars MAKEFILE_IN) message(STATUS "Reading vars from ${MAKEFILE_IN}...") file(STRINGS ${MAKEFILE_IN} makefile_contents) @@ -215,16 +214,30 @@ function(GenerateNamedObjects sources_in) endif () endif () - add_library(${obj_name} OBJECT ${source_file}) - set_target_properties(${obj_name} PROPERTIES COMPILE_DEFINITIONS "${obj_defines}") + if (VERBOSE_GEN) + message(STATUS "${obj_name}:${source_file}") + message(STATUS "${obj_defines}") + endif () - list(APPEND OBJ_LIST_OUT ${obj_name}) + # create a copy of the source to avoid duplicate obj filename problem with ar.exe + get_filename_component(source_extension ${source_file} EXT) + set(new_source_file "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${obj_name}${source_extension}") + if (IS_ABSOLUTE ${source_file}) + set(old_source_file ${source_file}) + else () + set(old_source_file "${CMAKE_CURRENT_LIST_DIR}/${source_file}") + endif () + + string(REPLACE ";" "\n#define " define_source "${obj_defines}") + string(REPLACE "=" " " define_source "${define_source}") + file(WRITE ${new_source_file} "#define ${define_source}\n#include \"${old_source_file}\"") + list(APPEND SRC_LIST_OUT ${new_source_file}) endforeach () endforeach () - list(APPEND DBLAS_OBJS ${OBJ_LIST_OUT}) - set(DBLAS_OBJS ${DBLAS_OBJS} PARENT_SCOPE) + list(APPEND OPENBLAS_SRC ${SRC_LIST_OUT}) + set(OPENBLAS_SRC ${OPENBLAS_SRC} PARENT_SCOPE) endfunction () # generates object files for each of the sources for each of the combinations of the preprocessor definitions passed in @@ -260,7 +273,6 @@ function(GenerateCombinationObjects sources_in defines_in absent_codes_in all_de set(define_combos ${LIST_OUT}) set(define_codes ${CODES_OUT}) - set(COMBO_OBJ_LIST_OUT "") list(LENGTH define_combos num_combos) math(EXPR num_combos "${num_combos} - 1") @@ -322,10 +334,9 @@ function(GenerateCombinationObjects sources_in defines_in absent_codes_in all_de endif () GenerateNamedObjects("${source_file}" "${cur_defines}" "${alternate_name}" false "${replace_code}" "${append_code}" "${no_float_type}" "${complex_filename_scheme}") - list(APPEND COMBO_OBJ_LIST_OUT "${OBJ_LIST_OUT}") endforeach () endforeach () - set(DBLAS_OBJS ${DBLAS_OBJS} PARENT_SCOPE) + set(OPENBLAS_SRC ${OPENBLAS_SRC} PARENT_SCOPE) endfunction () diff --git a/driver/level2/CMakeLists.txt b/driver/level2/CMakeLists.txt index 54e0eb42f..be275724f 100644 --- a/driver/level2/CMakeLists.txt +++ b/driver/level2/CMakeLists.txt @@ -115,5 +115,4 @@ if (SMP) endif () -set(DBLAS_OBJS ${DBLAS_OBJS} PARENT_SCOPE) # list append removes the scope from DBLAS_OBJS - +add_library(driver_level2 OBJECT ${OPENBLAS_SRC}) diff --git a/driver/level3/CMakeLists.txt b/driver/level3/CMakeLists.txt index 85bde071d..fac96cc82 100644 --- a/driver/level3/CMakeLists.txt +++ b/driver/level3/CMakeLists.txt @@ -69,5 +69,4 @@ endforeach () #endif # -set(DBLAS_OBJS ${DBLAS_OBJS} PARENT_SCOPE) # list append removes the scope from DBLAS_OBJS - +add_library(driver_level3 OBJECT ${OPENBLAS_SRC}) diff --git a/driver/others/CMakeLists.txt b/driver/others/CMakeLists.txt index 3e17ce5be..938f1daaf 100644 --- a/driver/others/CMakeLists.txt +++ b/driver/others/CMakeLists.txt @@ -62,14 +62,6 @@ endif () #COMMONOBJS += profile.$(SUFFIX) #endif -add_library(COMMON_OBJS OBJECT - ${MEMORY} - ${SMP_SOURCES} - ${COMMON_SOURCES} -) - -list(APPEND DBLAS_OBJS "COMMON_OBJS") - #LIBOTHERS = libothers.$(LIBSUFFIX) #ifeq ($(DYNAMIC_ARCH), 1) @@ -78,5 +70,4 @@ list(APPEND DBLAS_OBJS "COMMON_OBJS") #HPLOBJS = memory.$(SUFFIX) xerbla.$(SUFFIX) parameter.$(SUFFIX) #endif -set(DBLAS_OBJS ${DBLAS_OBJS} PARENT_SCOPE) # list append removes the scope from DBLAS_OBJS - +add_library(driver_others OBJECT ${OPENBLAS_SRC} ${MEMORY} ${SMP_SOURCES} ${COMMON_SOURCES}) diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 1ca554307..ae949235b 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -117,5 +117,4 @@ if (NOT DEFINED NO_LAPACK) GenerateNamedObjects("${LAPACK_MANGLED_SOURCES}" "" "" 0 "" "" 0 3) endif () -set(DBLAS_OBJS ${DBLAS_OBJS} PARENT_SCOPE) # list append removes the scope from DBLAS_OBJS - +add_library(interface OBJECT ${OPENBLAS_SRC}) diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt index 939eef6c7..368af90b2 100644 --- a/kernel/CMakeLists.txt +++ b/kernel/CMakeLists.txt @@ -251,4 +251,4 @@ endforeach () # Makefile.LA #DBLASOBJS += dneg_tcopy$(TSUFFIX).$(SUFFIX) dlaswp_ncopy$(TSUFFIX).$(SUFFIX) -set(DBLAS_OBJS ${DBLAS_OBJS} PARENT_SCOPE) # list append removes the scope from DBLAS_OBJS +add_library(kernel OBJECT ${OPENBLAS_SRC}) diff --git a/lapack/CMakeLists.txt b/lapack/CMakeLists.txt index 7e17de7de..c8c82219d 100644 --- a/lapack/CMakeLists.txt +++ b/lapack/CMakeLists.txt @@ -99,5 +99,5 @@ GenerateCombinationObjects("${TRANS_SOURCES}" "TRANS" "N" "" 4 "" "" 3) GenerateCombinationObjects("${UNIT_SOURCES}" "UNIT" "N" "" 4) GenerateCombinationObjects("${UNIT_SOURCES2}" "UNIT" "N" "" 0 "" "" 3) -set(DBLAS_OBJS ${DBLAS_OBJS} PARENT_SCOPE) # list append removes the scope from DBLAS_OBJS +add_library(lapack OBJECT ${OPENBLAS_SRC})