Skip to content

Commit

Permalink
Fix VCS version header problems.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-penev authored and vgvassilev committed Nov 28, 2019
1 parent 4faf53e commit 842bdba
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 24 deletions.
8 changes: 3 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ cmake_minimum_required(VERSION 3.7.0)
if(POLICY CMP0075)
cmake_policy(SET CMP0075 NEW)
endif()
if(POLICY CMP0077)
cmake_policy(SET CMP0077 NEW)
endif()

# If we are not building as a part of LLVM, build clad as an
# standalone project, using LLVM as an external library:
Expand Down Expand Up @@ -231,11 +234,6 @@ add_definitions( -D_GNU_SOURCE
-DCLAD_SRCDIR_INCL="${CLAD_SOURCE_DIR}/include"
-DCLAD_INSTDIR_INCL="${CLAD_BINARY_DIR}/include" )

include(VersionFromVCS)
# SVN_REVISION and GIT_COMMIT get set by the call to add_version_info_from_vcs.
# DUMMY_VAR contains a version string which we don't care about.
add_version_info_from_vcs(DUMMY_VAR)

option(CLAD_BUILD_STATIC_ONLY "Does not build shared libraries. Useful when we have LLVM_ENABLE_PLUGINS=OFF (eg. Win or CYGWIN)" OFF)
if (NOT CLAD_BUILD_STATIC_ONLY AND NOT LLVM_ENABLE_PLUGINS)
message(FATAL_ERROR "LLVM_ENABLE_PLUGINS is set to OFF. Please build clad with -DCLAD_BUILD_STATIC_ONLY=ON.")
Expand Down
50 changes: 44 additions & 6 deletions Compatibility.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,58 @@ endif()
# Clang 9 remove add_version_info_from_vcs.
# Recomended is use of get_source_info
if (NOT COMMAND add_version_info_from_vcs)
set(clad_compat__isClang9 TRUE)
macro(add_version_info_from_vcs VERS)
get_source_info(${CMAKE_CURRENT_SOURCE_DIR} VERS DUMMY_REP)
endmacro(add_version_info_from_vcs)
endif()

# Clang 9 change find_first_existing_vc_file interface.
# Clang 9 change find_first_existing_vc_file interface. (Clang => 9)
# find_first_existing_vc_file(var path) --> find_first_existing_vc_file(path var)
if (clad_compat__isClang9)
macro(clad_compat__find_first_existing_vc_file path out_var)
find_first_existing_vc_file(${path} out_var)
if (COMMAND find_first_existing_vc_file)
find_first_existing_vc_file(${path} out_var)
endif()
endmacro(clad_compat__find_first_existing_vc_file)
else()
# Clang 9 change find_first_existing_vc_file interface. (Clang < 9)
# find_first_existing_vc_file(var path) --> find_first_existing_vc_file(path var)
macro(clad_compat__find_first_existing_vc_file path out_var)
find_first_existing_vc_file(out_var ${path})
if (COMMAND find_first_existing_vc_file)
find_first_existing_vc_file(out_var ${path})
endif()
endmacro(clad_compat__find_first_existing_vc_file)
endif()

# Clang 9 VCS
function (clad_compat__DefineCustomCommandVCS version_inc LLVM_CMAKE_DIR CLANG_SOURCE_DIR CLAD_SOURCE_DIR clang_vc clad_vc)

if (LLVM_CMAKE_DIR STREQUAL "")
set(LLVM_CMAKE_DIR "${CLAD_SOURCE_DIR}/../../cmake/modules/")
endif()

set(generate_vcs_version_script "${LLVM_CMAKE_DIR}/GetSVN.cmake")
if (NOT EXISTS ${generate_vcs_version_script})
set(generate_vcs_version_script "${LLVM_CMAKE_DIR}/GenerateVersionFromVCS.cmake")
# Create custom target to generate the VC revision include. (Clang >= 9)
add_custom_command(OUTPUT "${version_inc}"
DEPENDS "${generate_vcs_version_script}"
COMMAND ${CMAKE_COMMAND} "-DNAMES=\"CLAD;CLANG\""
"-DCLAD_SOURCE_DIR=${CLAD_SOURCE_DIR}"
"-DCLANG_SOURCE_DIR=${CLANG_SOURCE_DIR}"
"-DLLVM_DIR=${LLVM_CMAKE_DIR}"
"-DCMAKE_MODULE_PATH=${LLVM_CMAKE_DIR}"
"-DHEADER_FILE=${version_inc}"
-P "${generate_vcs_version_script}")
else()
# Create custom target to generate the VC revision include. (Clang < 9)
add_custom_command(OUTPUT "${version_inc}"
DEPENDS "${clang_vc}" "${clad_vc}" "${get_svn_script}" "${generate_vcs_version_script}"
COMMAND ${CMAKE_COMMAND} "-DFIRST_SOURCE_DIR=${CLANG_SOURCE_DIR}"
"-DFIRST_NAME=CLANG"
"-DSECOND_SOURCE_DIR=${CLAD_SOURCE_DIR}"
"-DSECOND_NAME=CLAD"
"-DLLVM_DIR=${LLVM_CMAKE_DIR}"
"-DCMAKE_MODULE_PATH=${LLVM_CMAKE_DIR}"
"-DHEADER_FILE=${version_inc}"
-P "${generate_vcs_version_script}")
endif()
endfunction()
4 changes: 2 additions & 2 deletions include/clad/Differentiator/Compatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,9 @@ static inline ConstexprSpecKind Function_GetConstexprKind(const FunctionDecl* F)

static inline QualType getConstantArrayType(const ASTContext &Ctx,
QualType EltTy,
const llvm::APInt &ArySize,
const APInt &ArySize,
const Expr* SizeExpr,
ArrayType::ArraySizeModifier ASM,
clang::ArrayType::ArraySizeModifier ASM,
unsigned IndexTypeQuals)
{
#if CLANG_VERSION_MAJOR < 10
Expand Down
16 changes: 5 additions & 11 deletions lib/Differentiator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
set(CLANG_SOURCE_DIR ${CLAD_SOURCE_DIR}/../clang/)
if (NOT EXISTS ${CLANG_SOURCE_DIR})
set(CLANG_SOURCE_DIR "${Clang_DIR}/")
endif()

clad_compat__find_first_existing_vc_file("${CLANG_SOURCE_DIR}" clang_vc)
clad_compat__find_first_existing_vc_file("${CLAD_SOURCE_DIR}" clad_vc)
set(last_known_good_rev "${CLAD_SOURCE_DIR}/LastKnownGoodLLVMRevision.txt")

# The VC revision include that we want to generate.
set(version_inc "${CMAKE_CURRENT_BINARY_DIR}/VCSVersion.inc")

set(generate_vcs_version_script "${LLVM_CMAKE_PATH}/GenerateVersionFromVCS.cmake")

# Create custom target to generate the VC revision include.
add_custom_command(OUTPUT "${version_inc}"
DEPENDS "${clang_vc}" "${clad_vc}" "${generate_vcs_version_script}"
COMMAND ${CMAKE_COMMAND} "-DNAMES=\"LLVM;CLANG\""
"-DLLVM_SOURCE_DIR=${llvm_source_dir}"
"-DCLANG_SOURCE_DIR=${clang_source_dir}"
"-DHEADER_FILE=${version_inc}"
-P "${generate_vcs_version_script}")
clad_compat__DefineCustomCommandVCS("${version_inc}" "${LLVM_CMAKE_DIR}" "${CLANG_SOURCE_DIR}" "${CLAD_SOURCE_DIR}" "${clang_vc}" "${cald_vc}")

# Mark the generated header as being generated.
set_source_files_properties("${version_inc}"
Expand Down

0 comments on commit 842bdba

Please sign in to comment.