[PATCH] D61804: Support building shared and static libraries simultaneously
Wink Saville via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon May 13 17:08:09 PDT 2019
winksaville added a comment.
@beanz I found what I think is the reason libclang_shared.so isn't being created.
I added a bunch of debug output using `message` to add_llvm_subdirectory:
1041 function(add_llvm_subdirectory project type name)
1042 message(STATUS "add_llvm_subdirectory ${project} ${type} ${name}:+")
1043 set(add_llvm_external_dir "${ARGN}")
1044 if("${add_llvm_external_dir}" STREQUAL "")
1045 message(STATUS "add_llvm_subdirectory ${project} ${type} ${name}: 1")
1046 set(add_llvm_external_dir ${name})
1047 endif()
1048 canonicalize_tool_name(${name} nameUPPER)
1049 set(canonical_full_name ${project}_${type}_${nameUPPER})
1050 get_property(already_processed GLOBAL PROPERTY ${canonical_full_name}_PROCESSED)
1051 if(already_processed)
1052 message(STATUS "add_llvm_subdirectory ${project} ${type} ${name}:- already_processed")
1053 return()
1054 endif()
1055 set_property(GLOBAL PROPERTY ${canonical_full_name}_PROCESSED YES)
1056 message(STATUS "add_llvm_subdirectory ${project} ${type} ${name}: 1.1 canonical_full_name=${canonical_full_name} nameUPPER=${nameUPPER}")
1057
1058 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir}/CMakeLists.txt)
1059 message(STATUS "add_llvm_subdirectory ${project} ${type} ${name}: 2")
1060 # Treat it as in-tree subproject.
1061 option(${canonical_full_name}_BUILD
1062 "Whether to build ${name} as part of ${project}" On)
1063 mark_as_advanced(${project}_${type}_${name}_BUILD)
1064 if(${canonical_full_name}_BUILD)
1065 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir} ${add_llvm_external_dir})
1066 endif()
1067 else()
1068 set(LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR
1069 "${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}"
1070 CACHE PATH "Path to ${name} source directory")
1071 message(STATUS "add_llvm_subdirectory ${project} ${type} ${name}: 3 LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR=\"${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}\"")
1072 set(${canonical_full_name}_BUILD_DEFAULT ON)
1073 if(NOT LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR OR NOT EXISTS ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR})
1074 set(${canonical_full_name}_BUILD_DEFAULT OFF)
1075 message(STATUS "add_llvm_subdirectory ${project} ${type} ${name}: 3.1 ${canonical_full_name}_BUILD_DEFAULT=${${canonical_full_name}_BUILD_DEFAULT}")
1076 endif()
1077 if("${LLVM_EXTERNAL_${nameUPPER}_BUILD}" STREQUAL "OFF")
1078 set(${canonical_full_name}_BUILD_DEFAULT OFF)
1079 message(STATUS "add_llvm_subdirectory ${project} ${type} ${name}: 3.2 ${LLVM_EXTERNAL_${nameUPPER}_BUILD} ${canonical_full_name}_BUILD_DEFAULT=${${canonical_full_name}_BUILD_DEFAULT}")
1080 endif()
1081 option(${canonical_full_name}_BUILD
1082 "Whether to build ${name} as part of LLVM"
1083 ${${canonical_full_name}_BUILD_DEFAULT})
1084 message(STATUS "add_llvm_subdirectory ${project} ${type} ${name}: 3.3 ${canonical_full_name}_BUILD=${${canonical_full_name}_BUILD}")
1085 if (${canonical_full_name}_BUILD)
1086 message(STATUS "add_llvm_subdirectory ${project} ${type} ${name}: 3.4")
1087 if(EXISTS ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR})
1088 message(STATUS "add_llvm_subdirectory ${project} ${type} ${name}: 3.4.1")
1089 add_subdirectory(${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR} ${add_llvm_external_dir})
1090 elseif(NOT "${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}" STREQUAL "")
1091 message(STATUS "add_llvm_subdirectory ${project} ${type} ${name}: 3.4.2")
1092 message(WARNING "Nonexistent directory for ${name}: ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}")
1093 endif()
1094 message(STATUS "add_llvm_subdirectory ${project} ${type} ${name}: 3.4.99")
1095 endif()
1096 message(STATUS "add_llvm_subdirectory ${project} ${type} ${name}: 3.99")
1097 endif()
1098 message(STATUS "add_llvm_subdirectory ${project} ${type} ${name}:-")
1099 endfunction()
The typical output when adding a subdirectory is:
-- add_llvm_subdirectory CLANG TOOL clang-refactor:+
-- add_llvm_subdirectory CLANG TOOL clang-refactor: 1
-- add_llvm_subdirectory CLANG TOOL clang-refactor: 1.1 canonical_full_name=CLANG_TOOL_CLANG_REFACTOR nameUPPER=CLANG_REFACTOR
-- add_llvm_subdirectory CLANG TOOL clang-refactor: 2
-- add_llvm_subdirectory CLANG TOOL clang-refactor:-
Where at line 1058 the clause `if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir}/CMakeLists.txt)`
is TRUE and we go through path `2`; lines 1059 - 1066.
The only time we don't go though path 2 is clang-shlib which goes though path 3, lines 1068 - 1096.
In that case we endup with CLANG_TOOL_CLANG_SHLIB_BUILD_DEFAULT=OFF
and CLANG_TOOL_CLANG_SHLIB_BUILD=OFF so libclang_shared.so isn't built:
-- add_llvm_subdirectory CLANG TOOL clang-shlib:+
-- add_llvm_subdirectory CLANG TOOL clang-shlib: 1
-- add_llvm_subdirectory CLANG TOOL clang-shlib: 1.1 canonical_full_name=CLANG_TOOL_CLANG_SHLIB nameUPPER=CLANG_SHLIB
-- add_llvm_subdirectory CLANG TOOL clang-shlib: 3 LLVM_EXTERNAL_CLANG_SHLIB_SOURCE_DIR=""
-- add_llvm_subdirectory CLANG TOOL clang-shlib: 3.1 CLANG_TOOL_CLANG_SHLIB_BUILD_DEFAULT=OFF
-- add_llvm_subdirectory CLANG TOOL clang-shlib: 3.3 CLANG_TOOL_CLANG_SHLIB_BUILD=OFF
-- add_llvm_subdirectory CLANG TOOL clang-shlib: 3.99
-- add_llvm_subdirectory CLANG TOOL clang-shlib:-
Also notice that LLVM_EXTERNAL_CLANG_SHLIB_SOURCE_DIR is empty:
-- add_llvm_subdirectory CLANG TOOL clang-shlib: 3 LLVM_EXTERNAL_CLANG_SHLIB_SOURCE_DIR=""
It looks weird that LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR is being set to
a deference of itself "${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}":
1068 set(LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR
1069 "${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}"
1070 CACHE PATH "Path to ${name} source directory")
Maybe that's idiom which causes cmake to cache something, but seems odd to me so I thought I'd point it out.
Of course I could be analyzing all of this totally wrong, so help appreciated.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D61804/new/
https://reviews.llvm.org/D61804
More information about the cfe-commits
mailing list