2015-08-03 01:42:47 +00:00
|
|
|
###############
|
|
|
|
# ATDNA Build #
|
|
|
|
###############
|
|
|
|
|
2017-12-07 04:07:33 +00:00
|
|
|
if(NOT CMAKE_CROSSCOMPILING)
|
|
|
|
|
2019-07-20 04:19:44 +00:00
|
|
|
string(REPLACE -stdlib=libc++ "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
|
|
|
|
2019-07-07 08:21:13 +00:00
|
|
|
get_directory_property(ATDNA_DEFINES COMPILE_DEFINITIONS)
|
|
|
|
list(REMOVE_ITEM ATDNA_DEFINES _GLIBCXX_DEBUG=1)
|
|
|
|
set_directory_properties(PROPERTIES COMPILE_DEFINITIONS "${ATDNA_DEFINES}")
|
|
|
|
|
2015-08-03 01:42:47 +00:00
|
|
|
# Find dependencies
|
|
|
|
include(FindLLVM.cmake)
|
|
|
|
if(NOT LLVM_FOUND)
|
2015-11-17 20:37:08 +00:00
|
|
|
message(STATUS "Unable to locate LLVM installation; skipping atdna")
|
2015-08-03 01:42:47 +00:00
|
|
|
else()
|
2018-04-03 00:42:43 +00:00
|
|
|
|
|
|
|
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
|
|
|
option(ATDNA_DYNAMIC_LLVM "Use dynamic library targets when linking LLVM" ON)
|
|
|
|
else()
|
|
|
|
option(ATDNA_DYNAMIC_LLVM "Use dynamic library targets when linking LLVM" OFF)
|
2016-12-11 20:18:12 +00:00
|
|
|
endif()
|
2018-04-03 00:42:43 +00:00
|
|
|
|
|
|
|
if(ATDNA_DYNAMIC_LLVM)
|
2020-04-22 10:36:08 +00:00
|
|
|
find_library(CLANGCPP_LIB clang-cpp HINTS "${LLVM_ROOT_DIR}/lib")
|
|
|
|
if (NOT CLANGCPP_LIB)
|
2020-09-06 05:39:12 +00:00
|
|
|
list(APPEND LLVM_LIBS
|
|
|
|
clangFrontend
|
|
|
|
clangTooling
|
|
|
|
clangDriver
|
|
|
|
clangSerialization
|
|
|
|
clangParse
|
|
|
|
clangSema
|
|
|
|
clangAnalysis
|
|
|
|
clangEdit
|
|
|
|
clangAST
|
|
|
|
clangLex
|
|
|
|
clangBasic
|
|
|
|
LLVM)
|
|
|
|
else()
|
2020-04-22 10:36:08 +00:00
|
|
|
list(APPEND LLVM_LIBS
|
|
|
|
clang-cpp
|
|
|
|
LLVM)
|
2020-09-06 05:39:12 +00:00
|
|
|
endif()
|
2018-04-03 00:42:43 +00:00
|
|
|
else()
|
|
|
|
find_library(LLVMDEMANGLE_LIB LLVMDemangle HINTS "${LLVM_ROOT_DIR}/lib")
|
|
|
|
find_library(LLVMBINARYFORMAT_LIB LLVMBinaryFormat HINTS "${LLVM_ROOT_DIR}/lib")
|
|
|
|
if (NOT LLVMDEMANGLE_LIB)
|
|
|
|
set(LLVMDEMANGLE_LIB "")
|
|
|
|
endif()
|
|
|
|
if (NOT LLVMBINARYFORMAT_LIB)
|
2017-10-15 05:41:07 +00:00
|
|
|
set(LLVMBINARYFORMAT_LIB "")
|
2018-04-03 00:42:43 +00:00
|
|
|
endif()
|
2020-04-22 10:36:08 +00:00
|
|
|
find_library(CLANG_CPP_LIB clang-cpp HINTS "${LLVM_ROOT_DIR}/lib")
|
|
|
|
if (NOT CLANG_CPP_LIB)
|
|
|
|
list(APPEND CLANG_LIBS
|
|
|
|
clangFrontend
|
|
|
|
clangTooling
|
|
|
|
clangDriver
|
|
|
|
clangSerialization
|
|
|
|
clangParse
|
|
|
|
clangSema
|
|
|
|
clangAnalysis
|
|
|
|
clangEdit
|
|
|
|
clangAST
|
|
|
|
clangLex
|
|
|
|
clangBasic)
|
|
|
|
else()
|
|
|
|
list(APPEND CLANG_LIBS
|
|
|
|
clang-cpp)
|
|
|
|
endif()
|
|
|
|
|
2018-04-03 00:42:43 +00:00
|
|
|
list(APPEND LLVM_LIBS
|
2020-04-22 10:36:08 +00:00
|
|
|
${CLANG_LIBS}
|
2018-04-03 00:42:43 +00:00
|
|
|
LLVMCore
|
|
|
|
LLVMOption
|
|
|
|
LLVMMCParser
|
|
|
|
LLVMBitReader
|
|
|
|
${LLVMBINARYFORMAT_LIB}
|
|
|
|
LLVMMC
|
|
|
|
LLVMProfileData
|
|
|
|
LLVMSupport
|
2020-04-15 00:51:39 +00:00
|
|
|
LLVMRemarks
|
|
|
|
LLVMBitStreamReader
|
2020-09-06 05:39:12 +00:00
|
|
|
${LLVMDEMANGLE_LIB}
|
|
|
|
LLVMFrontendOpenMP)
|
2017-10-15 05:41:07 +00:00
|
|
|
endif()
|
2016-06-27 22:54:55 +00:00
|
|
|
|
|
|
|
string(FIND ${LLVM_VERSION_STRING} "svn" SVN_FILTER_IDX)
|
|
|
|
if(NOT SVN_FILTER_IDX EQUAL -1)
|
|
|
|
string(SUBSTRING ${LLVM_VERSION_STRING} 0 ${SVN_FILTER_IDX} LLVM_VERSION_BASE)
|
|
|
|
else()
|
|
|
|
set(LLVM_VERSION_BASE ${LLVM_VERSION_STRING})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(CLANG_INCLUDE_DIR ${LLVM_LIBRARY_DIRS}/clang/${LLVM_VERSION_BASE}/include
|
2015-09-02 18:49:23 +00:00
|
|
|
CACHE PATH "Clang include dir" FORCE)
|
2015-08-03 01:42:47 +00:00
|
|
|
|
|
|
|
if(UNIX)
|
2016-09-10 23:38:44 +00:00
|
|
|
list(APPEND PLAT_LIBS z pthread curses)
|
|
|
|
if (APPLE)
|
2015-09-12 18:25:58 +00:00
|
|
|
list(APPEND PLAT_LIBS dl)
|
2016-09-10 23:38:44 +00:00
|
|
|
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
2017-10-31 03:50:44 +00:00
|
|
|
list(APPEND PLAT_LIBS dl tinfo)
|
2016-09-10 23:38:44 +00:00
|
|
|
endif()
|
|
|
|
elseif(WIN32)
|
2016-12-22 00:58:09 +00:00
|
|
|
list(APPEND PLAT_LIBS Version)
|
2015-08-03 01:42:47 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Offer the user the choice of overriding the installation directories
|
|
|
|
set(INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files")
|
|
|
|
set(INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables")
|
|
|
|
if(WIN32 AND NOT CYGWIN)
|
|
|
|
set(INSTALL_CMAKE_DIR cmake)
|
|
|
|
else()
|
|
|
|
set(INSTALL_CMAKE_DIR lib/cmake/atdna)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Make relative paths absolute (needed later on)
|
|
|
|
foreach(p BIN INCLUDE CMAKE)
|
|
|
|
set(var INSTALL_${p}_DIR)
|
|
|
|
if(NOT IS_ABSOLUTE "${${var}}")
|
|
|
|
set(ABS_${var} "${CMAKE_INSTALL_PREFIX}/${${var}}")
|
|
|
|
else()
|
|
|
|
set(ABS_${var} "${${var}}")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
# Windows resource
|
|
|
|
if(WIN32)
|
|
|
|
configure_file(main.rc.in main.rc @ONLY)
|
|
|
|
set(PLAT_SRCS ${CMAKE_CURRENT_BINARY_DIR}/main.rc)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# ATDNA target
|
|
|
|
add_executable(atdna main.cpp test.hpp ${PLAT_SRCS})
|
|
|
|
target_link_libraries(atdna ${LLVM_LIBS} ${PLAT_LIBS})
|
2016-09-10 23:38:44 +00:00
|
|
|
set_source_files_properties(main.cpp PROPERTIES COMPILE_DEFINITIONS
|
2015-08-03 01:42:47 +00:00
|
|
|
"INSTALL_PREFIX=${ABS_INSTALL_BIN_DIR};__STDC_LIMIT_MACROS=1;__STDC_CONSTANT_MACROS=1")
|
2019-06-12 01:58:44 +00:00
|
|
|
target_include_directories(atdna PRIVATE ${LLVM_INCLUDE_DIRS})
|
|
|
|
target_link_directories(atdna PRIVATE ${LLVM_LIBRARY_DIRS})
|
2020-09-06 05:39:12 +00:00
|
|
|
# Clang 10.0.x headers currently broken with C++20
|
|
|
|
set_property(TARGET atdna PROPERTY CXX_STANDARD 17)
|
2015-08-03 01:42:47 +00:00
|
|
|
if(MSVC)
|
2020-05-28 01:37:03 +00:00
|
|
|
# Allow linking against release-built LLVM libraries
|
|
|
|
target_compile_options(atdna PRIVATE /GR- /D_ITERATOR_DEBUG_LEVEL=0)
|
|
|
|
set_property(TARGET atdna PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
|
2015-08-03 01:42:47 +00:00
|
|
|
else()
|
2019-08-31 20:35:50 +00:00
|
|
|
target_compile_options(atdna PRIVATE -fno-rtti -Wno-error)
|
2015-08-03 01:42:47 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Define installs
|
|
|
|
install(TARGETS atdna DESTINATION ${INSTALL_BIN_DIR} EXPORT atdnaTargets COMPONENT atdna)
|
2016-03-04 23:00:12 +00:00
|
|
|
install(DIRECTORY ${CLANG_INCLUDE_DIR}/ DESTINATION ${INSTALL_INCLUDE_DIR}/athena/clang COMPONENT atdna)
|
2015-08-03 01:42:47 +00:00
|
|
|
|
|
|
|
##################
|
|
|
|
# Package Export #
|
|
|
|
##################
|
|
|
|
|
|
|
|
# Add all targets to the build-tree export set
|
2017-12-07 04:07:33 +00:00
|
|
|
export(TARGETS atdna FILE "${CMAKE_CURRENT_BINARY_DIR}/atdnaTargets.cmake")
|
2015-08-03 01:42:47 +00:00
|
|
|
|
|
|
|
# Export the package for use from the build-tree
|
|
|
|
# (this registers the build-tree with a global CMake-registry)
|
|
|
|
export(PACKAGE atdna)
|
|
|
|
|
|
|
|
# Create the atdnaConfig.cmake
|
|
|
|
# ... for the build tree
|
|
|
|
set(CONF_CLANG_INCLUDE_DIR "${CLANG_INCLUDE_DIR}")
|
2017-12-07 04:07:33 +00:00
|
|
|
configure_file(atdnaConfig.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/atdnaConfig.cmake" @ONLY)
|
2015-08-03 01:42:47 +00:00
|
|
|
# ... for the install tree
|
|
|
|
set(CONF_CLANG_INCLUDE_DIR "\${ATHENA_INCLUDE_DIR}/clang")
|
2017-12-07 04:07:33 +00:00
|
|
|
configure_file(atdnaConfig.cmake.in "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/atdnaConfig.cmake" @ONLY)
|
2015-08-03 01:42:47 +00:00
|
|
|
# ... for both
|
2017-12-07 04:07:33 +00:00
|
|
|
configure_file(atdnaConfigVersion.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/atdnaConfigVersion.cmake" @ONLY)
|
2015-08-03 01:42:47 +00:00
|
|
|
|
|
|
|
# Install atdnaConfig.cmake
|
|
|
|
install(FILES
|
2017-12-07 04:07:33 +00:00
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/atdnaConfig.cmake"
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/atdnaConfigVersion.cmake"
|
2015-08-03 01:42:47 +00:00
|
|
|
DESTINATION ${INSTALL_CMAKE_DIR} COMPONENT atdna)
|
|
|
|
|
|
|
|
# Install the export set for use with the install-tree
|
|
|
|
install(EXPORT atdnaTargets DESTINATION ${INSTALL_CMAKE_DIR} COMPONENT atdna)
|
|
|
|
|
|
|
|
#########
|
|
|
|
# CTest #
|
|
|
|
#########
|
|
|
|
|
|
|
|
enable_testing()
|
2016-09-10 23:38:44 +00:00
|
|
|
add_test(NAME test-dna COMMAND $<TARGET_FILE:atdna> -o test.cpp
|
2015-08-03 01:42:47 +00:00
|
|
|
"-I${ATHENA_INCLUDE_DIR}" -isystem "${CLANG_INCLUDE_DIR}"
|
|
|
|
${CMAKE_SOURCE_DIR}/test.hpp)
|
|
|
|
|
|
|
|
endif()
|
|
|
|
|
2015-09-02 18:49:23 +00:00
|
|
|
#######################
|
|
|
|
# In-tree atdna macro #
|
|
|
|
#######################
|
|
|
|
|
|
|
|
# Super handy macro for adding atdna target
|
2019-06-12 01:58:44 +00:00
|
|
|
function(atdna out incdirs cdefs)
|
2017-08-20 05:22:25 +00:00
|
|
|
# Ninja wants invocations in root binary dir for DEPFILE application
|
|
|
|
file(RELATIVE_PATH out_rel ${CMAKE_BINARY_DIR} "${CMAKE_CURRENT_BINARY_DIR}/${out}")
|
|
|
|
|
2015-09-02 18:49:23 +00:00
|
|
|
# Make input files source-relative
|
2019-06-12 01:58:44 +00:00
|
|
|
unset(ins)
|
|
|
|
unset(ins_impdeps)
|
2015-09-02 18:49:23 +00:00
|
|
|
foreach(arg ${ARGN})
|
|
|
|
list(APPEND ins ${CMAKE_CURRENT_SOURCE_DIR}/${arg})
|
2017-08-20 05:22:25 +00:00
|
|
|
list(APPEND ins_impdeps CXX)
|
|
|
|
list(APPEND ins_impdeps ${CMAKE_CURRENT_SOURCE_DIR}/${arg})
|
2015-09-02 18:49:23 +00:00
|
|
|
endforeach()
|
|
|
|
|
|
|
|
# MS extra
|
|
|
|
unset(extraargs)
|
|
|
|
if(MSVC)
|
|
|
|
list(APPEND extraargs -fms-compatibility -fexceptions)
|
|
|
|
if(MSVC_VERSION EQUAL 1800)
|
|
|
|
list(APPEND extraargs -fms-compatibility-version=18.00)
|
|
|
|
elseif(MSVC_VERSION EQUAL 1900)
|
|
|
|
list(APPEND extraargs -fms-compatibility-version=19.00)
|
2017-03-10 17:57:44 +00:00
|
|
|
elseif(MSVC_VERSION EQUAL 1910)
|
|
|
|
list(APPEND extraargs -fms-compatibility-version=19.10)
|
2017-10-24 03:10:58 +00:00
|
|
|
elseif(MSVC_VERSION EQUAL 1911)
|
|
|
|
list(APPEND extraargs -fms-compatibility-version=19.11)
|
2017-08-25 06:17:03 +00:00
|
|
|
endif()
|
2015-09-02 18:49:23 +00:00
|
|
|
|
|
|
|
# OSX Extra
|
|
|
|
elseif(APPLE)
|
2018-01-03 23:52:01 +00:00
|
|
|
get_filename_component(COMPILER_DIR "${CMAKE_CXX_COMPILER}" DIRECTORY)
|
2016-01-09 02:00:08 +00:00
|
|
|
if (NOT EXISTS "${CMAKE_OSX_SYSROOT}")
|
|
|
|
message(FATAL_ERROR "CMAKE_OSX_SYSROOT not set")
|
|
|
|
endif()
|
2018-01-03 23:52:01 +00:00
|
|
|
list(APPEND extraargs
|
2018-08-28 03:47:14 +00:00
|
|
|
-I ${COMPILER_DIR}/../include/c++/v1
|
|
|
|
-isysroot ${CMAKE_OSX_SYSROOT})
|
2015-09-02 18:49:23 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Make target
|
2017-08-20 05:22:25 +00:00
|
|
|
if(${CMAKE_GENERATOR} STREQUAL "Ninja")
|
|
|
|
# Use Ninja's DEPFILE parser in cooperation with atdna
|
|
|
|
add_custom_command(OUTPUT ${out} COMMAND $<TARGET_FILE:atdna>
|
2019-06-12 01:58:44 +00:00
|
|
|
ARGS ${extraargs} -o ${out_rel} -MD -MT ${out_rel} -MF ${out_rel}.d
|
|
|
|
"$<$<BOOL:${incdirs}>:-I$<JOIN:${incdirs},;-I>>"
|
|
|
|
"$<$<BOOL:${cdefs}>:-D$<JOIN:${cdefs},;-D>>"
|
|
|
|
"-I${athena_SOURCE_DIR}/include" -isystem "${CLANG_INCLUDE_DIR}" ${ins}
|
2017-08-20 05:22:25 +00:00
|
|
|
DEPENDS atdna ${ins} IMPLICIT_DEPENDS ${ins_impdeps}
|
|
|
|
DEPFILE "${CMAKE_CURRENT_BINARY_DIR}/${out}.d"
|
|
|
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
2019-06-12 01:58:44 +00:00
|
|
|
COMMENT "Generating DNA ${out_rel}"
|
|
|
|
COMMAND_EXPAND_LISTS)
|
2017-08-20 05:22:25 +00:00
|
|
|
else()
|
|
|
|
# Use CMake's built-in dependency scanner for makefile targets
|
|
|
|
add_custom_command(OUTPUT ${out} COMMAND $<TARGET_FILE:atdna>
|
2019-06-12 01:58:44 +00:00
|
|
|
ARGS ${extraargs} -o ${out_rel}
|
|
|
|
"$<$<BOOL:${incdirs}>:-I$<JOIN:${incdirs},;-I>>"
|
|
|
|
"$<$<BOOL:${cdefs}>:-D$<JOIN:${cdefs},;-D>>"
|
|
|
|
"-I${athena_SOURCE_DIR}/include" -isystem "${CLANG_INCLUDE_DIR}" ${ins}
|
2017-08-20 05:22:25 +00:00
|
|
|
DEPENDS atdna ${ins} IMPLICIT_DEPENDS ${ins_impdeps}
|
|
|
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
2019-06-12 01:58:44 +00:00
|
|
|
COMMENT "Generating DNA ${out_rel}"
|
|
|
|
COMMAND_EXPAND_LISTS)
|
2017-08-20 05:22:25 +00:00
|
|
|
endif()
|
2018-10-07 02:51:06 +00:00
|
|
|
endfunction()
|
2017-12-07 04:07:33 +00:00
|
|
|
|
2019-06-12 01:58:44 +00:00
|
|
|
function(target_atdna target out)
|
|
|
|
atdna(${out} "$<TARGET_PROPERTY:${target},INCLUDE_DIRECTORIES>"
|
|
|
|
"$<TARGET_PROPERTY:${target},COMPILE_DEFINITIONS>" ${ARGN})
|
|
|
|
target_sources(${target} PRIVATE ${out} ${ARGN})
|
|
|
|
endfunction()
|
|
|
|
|
2017-12-07 04:07:33 +00:00
|
|
|
endif()
|