Skip to content

Refactor llvmclangcmark config into separate macros #3201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 72 additions & 58 deletions cmake/modules/SwiftSharedCMakeConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,7 @@ else()
set(cmake_3_2_USES_TERMINAL USES_TERMINAL)
endif()

# Common cmake project config for standalone builds.
#
# Parameters:
# product
# The product name, e.g. Swift or SourceKit. Used as prefix for some
# cmake variables.
#
# is_cross_compiling
# Whether this is cross-compiling host tools.
macro(swift_common_standalone_build_config product is_cross_compiling)
macro(swift_common_standalone_build_config_llvm product is_cross_compiling)
option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)

precondition_translate_flag(${product}_PATH_TO_LLVM_SOURCE PATH_TO_LLVM_SOURCE)
Expand Down Expand Up @@ -68,44 +59,6 @@ macro(swift_common_standalone_build_config product is_cross_compiling)
precondition_translate_flag(LLVM_BUILD_BINARY_DIR LLVM_BINARY_DIR)
precondition_translate_flag(LLVM_BUILD_MAIN_SRC_DIR LLVM_MAIN_SRC_DIR)

# Clang
set(${product}_PATH_TO_CLANG_SOURCE "${PATH_TO_LLVM_SOURCE}/tools/clang"
CACHE PATH "Path to Clang source code.")
set(${product}_PATH_TO_CLANG_BUILD "${PATH_TO_LLVM_BUILD}" CACHE PATH
"Path to the directory where Clang was built or installed.")

set(${product}_PATH_TO_CMARK_SOURCE "${${product}_PATH_TO_CMARK_SOURCE}"
CACHE PATH "Path to CMark source code.")
set(${product}_PATH_TO_CMARK_BUILD "${${product}_PATH_TO_CMARK_BUILD}"
CACHE PATH "Path to the directory where CMark was built.")
set(${product}_CMARK_LIBRARY_DIR "${${product}_CMARK_LIBRARY_DIR}" CACHE PATH
"Path to the directory where CMark was installed.")
get_filename_component(PATH_TO_CMARK_BUILD "${${product}_PATH_TO_CMARK_BUILD}"
ABSOLUTE)
get_filename_component(CMARK_MAIN_SRC_DIR "${${product}_PATH_TO_CMARK_SOURCE}"
ABSOLUTE)
get_filename_component(CMARK_LIBRARY_DIR "${${product}_CMARK_LIBRARY_DIR}"
ABSOLUTE)

if(NOT EXISTS "${${product}_PATH_TO_CLANG_SOURCE}/include/clang/AST/Decl.h")
message(FATAL_ERROR "Please set ${product}_PATH_TO_CLANG_SOURCE to the root directory of Clang's source code.")
else()
get_filename_component(CLANG_MAIN_SRC_DIR ${${product}_PATH_TO_CLANG_SOURCE}
ABSOLUTE)
endif()

if(EXISTS "${${product}_PATH_TO_CLANG_BUILD}/include/clang/Basic/Version.inc")
set(CLANG_BUILD_INCLUDE_DIR "${${product}_PATH_TO_CLANG_BUILD}/include")
elseif(EXISTS "${${product}_PATH_TO_CLANG_BUILD}/tools/clang/include/clang/Basic/Version.inc")
set(CLANG_BUILD_INCLUDE_DIR "${${product}_PATH_TO_CLANG_BUILD}/tools/clang/include")
else()
message(FATAL_ERROR "Please set ${product}_PATH_TO_CLANG_BUILD to a directory containing a Clang build.")
endif()
if(CLANG_MAIN_INCLUDE_DIR)
get_filename_component(CLANG_MAIN_SRC_DIR ${${product}_PATH_TO_CLANG_SOURCE}
ABSOLUTE)
endif()

if(${is_cross_compiling})
find_program(SWIFT_TABLEGEN_EXE "llvm-tblgen" "${${product}_NATIVE_LLVM_TOOLS_PATH}"
NO_DEFAULT_PATH)
Expand All @@ -115,7 +68,6 @@ macro(swift_common_standalone_build_config product is_cross_compiling)
else()
set(SWIFT_TABLEGEN_EXE llvm-tblgen)
set(${product}_NATIVE_LLVM_TOOLS_PATH "${PATH_TO_LLVM_TOOLS_BINARY_DIR}")
set(${product}_NATIVE_CLANG_TOOLS_PATH "${PATH_TO_LLVM_TOOLS_BINARY_DIR}")
endif()

include(AddLLVM)
Expand All @@ -132,17 +84,9 @@ macro(swift_common_standalone_build_config product is_cross_compiling)
"${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}" CACHE STRING
"Version number that will be placed into the libclang library , in the form XX.YY")

set(CLANG_MAIN_INCLUDE_DIR "${CLANG_MAIN_SRC_DIR}/include")
set(CMARK_MAIN_INCLUDE_DIR "${CMARK_MAIN_SRC_DIR}/src")
set(CMARK_BUILD_INCLUDE_DIR "${PATH_TO_CMARK_BUILD}/src")

set(CMAKE_INCLUDE_CURRENT_DIR ON)
include_directories("${PATH_TO_LLVM_BUILD}/include"
"${LLVM_MAIN_INCLUDE_DIR}"
"${CLANG_BUILD_INCLUDE_DIR}"
"${CLANG_MAIN_INCLUDE_DIR}"
"${CMARK_MAIN_INCLUDE_DIR}"
"${CMARK_BUILD_INCLUDE_DIR}")
"${LLVM_MAIN_INCLUDE_DIR}")
foreach (INCLUDE_DIR ${LLVM_INCLUDE_DIRS})
include_directories(${INCLUDE_DIR})
endforeach ()
Expand Down Expand Up @@ -170,6 +114,76 @@ macro(swift_common_standalone_build_config product is_cross_compiling)
endif()
endmacro()

macro(swift_common_standalone_build_config_clang product is_cross_compiling)
# Clang
set(${product}_PATH_TO_CLANG_SOURCE "${PATH_TO_LLVM_SOURCE}/tools/clang"
CACHE PATH "Path to Clang source code.")
set(${product}_PATH_TO_CLANG_BUILD "${PATH_TO_LLVM_BUILD}" CACHE PATH
"Path to the directory where Clang was built or installed.")

if(NOT EXISTS "${${product}_PATH_TO_CLANG_SOURCE}/include/clang/AST/Decl.h")
message(FATAL_ERROR "Please set ${product}_PATH_TO_CLANG_SOURCE to the root directory of Clang's source code.")
else()
get_filename_component(CLANG_MAIN_SRC_DIR ${${product}_PATH_TO_CLANG_SOURCE}
ABSOLUTE)
endif()

if(EXISTS "${${product}_PATH_TO_CLANG_BUILD}/include/clang/Basic/Version.inc")
set(CLANG_BUILD_INCLUDE_DIR "${${product}_PATH_TO_CLANG_BUILD}/include")
elseif(EXISTS "${${product}_PATH_TO_CLANG_BUILD}/tools/clang/include/clang/Basic/Version.inc")
set(CLANG_BUILD_INCLUDE_DIR "${${product}_PATH_TO_CLANG_BUILD}/tools/clang/include")
else()
message(FATAL_ERROR "Please set ${product}_PATH_TO_CLANG_BUILD to a directory containing a Clang build.")
endif()
if(CLANG_MAIN_INCLUDE_DIR)
get_filename_component(CLANG_MAIN_SRC_DIR ${${product}_PATH_TO_CLANG_SOURCE}
ABSOLUTE)
endif()

if (NOT ${is_cross_compiling})
set(${product}_NATIVE_CLANG_TOOLS_PATH "${PATH_TO_LLVM_TOOLS_BINARY_DIR}")
endif()

set(CLANG_MAIN_INCLUDE_DIR "${CLANG_MAIN_SRC_DIR}/include")

include_directories("${CLANG_BUILD_INCLUDE_DIR}"
"${CLANG_MAIN_INCLUDE_DIR}")
endmacro()

macro(swift_common_standalone_build_config_cmark product)
set(${product}_PATH_TO_CMARK_SOURCE "${${product}_PATH_TO_CMARK_SOURCE}"
CACHE PATH "Path to CMark source code.")
set(${product}_PATH_TO_CMARK_BUILD "${${product}_PATH_TO_CMARK_BUILD}"
CACHE PATH "Path to the directory where CMark was built.")
set(${product}_CMARK_LIBRARY_DIR "${${product}_CMARK_LIBRARY_DIR}" CACHE PATH
"Path to the directory where CMark was installed.")
get_filename_component(PATH_TO_CMARK_BUILD "${${product}_PATH_TO_CMARK_BUILD}"
ABSOLUTE)
get_filename_component(CMARK_MAIN_SRC_DIR "${${product}_PATH_TO_CMARK_SOURCE}"
ABSOLUTE)
get_filename_component(CMARK_LIBRARY_DIR "${${product}_CMARK_LIBRARY_DIR}"
ABSOLUTE)
set(CMARK_MAIN_INCLUDE_DIR "${CMARK_MAIN_SRC_DIR}/src")
set(CMARK_BUILD_INCLUDE_DIR "${PATH_TO_CMARK_BUILD}/src")
include_directories("${CMARK_MAIN_INCLUDE_DIR}"
"${CMARK_BUILD_INCLUDE_DIR}")
endmacro()

# Common cmake project config for standalone builds.
#
# Parameters:
# product
# The product name, e.g. Swift or SourceKit. Used as prefix for some
# cmake variables.
#
# is_cross_compiling
# Whether this is cross-compiling host tools.
macro(swift_common_standalone_build_config product is_cross_compiling)
swift_common_standalone_build_config_llvm(${product} ${is_cross_compiling})
swift_common_standalone_build_config_clang(${product} ${is_cross_compiling})
swift_common_standalone_build_config_cmark(${product})
endmacro()

# Common cmake project config for unified builds.
#
# Parameters:
Expand Down