athena/atdna/CMakeLists.txt

200 lines
6.1 KiB
CMake
Raw Normal View History

2015-08-03 01:42:47 +00:00
###############
# ATDNA Build #
###############
2015-08-31 03:29:37 +00:00
# Force this binary to Release flags (to make MSVC happy)
if(MSVC)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_RELEASE}")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
endif()
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()
find_library(LLVMDEMANGLE_LIB LLVMDemangle HINTS "${LLVM_ROOT_DIR}/lib")
2016-12-11 20:18:12 +00:00
if (NOT LLVMDEMANGLE_LIB)
set(LLVMDEMANGLE_LIB "")
endif()
2015-08-03 01:42:47 +00:00
list(APPEND LLVM_LIBS
clangFrontend
clangTooling
clangDriver
clangSerialization
clangParse
clangSema
clangAnalysis
clangEdit
clangAST
clangLex
clangBasic
2016-06-27 22:54:55 +00:00
LLVMCore
2015-08-03 01:42:47 +00:00
LLVMOption
LLVMMCParser
LLVMBitReader
LLVMMC
2016-06-27 22:54:55 +00:00
LLVMProfileData
2016-12-11 20:18:12 +00:00
${LLVMDEMANGLE_LIB}
2015-08-03 01:42:47 +00:00
LLVMSupport)
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
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")
2015-09-12 18:25:58 +00:00
list(APPEND PLAT_LIBS dl)
2016-09-10 23:38:44 +00:00
endif()
elseif(WIN32)
2016-10-23 20:37:00 +00:00
list(APPEND PLAT_LIBS Mincore 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
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
include_directories(${LLVM_INCLUDE_DIRS})
link_directories(${LLVM_LIBRARY_DIRS})
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")
if(MSVC)
set_target_properties(atdna PROPERTIES
COMPILE_FLAGS "/GR-")
else()
set_target_properties(atdna PROPERTIES
COMPILE_FLAGS "-std=c++11 -fno-rtti -Wno-unused-parameter"
LINK_FLAGS -std=c++11)
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
export(TARGETS atdna FILE "${PROJECT_BINARY_DIR}/atdnaTargets.cmake")
# 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}")
configure_file(atdnaConfig.cmake.in "${PROJECT_BINARY_DIR}/atdnaConfig.cmake" @ONLY)
# ... for the install tree
set(CONF_CLANG_INCLUDE_DIR "\${ATHENA_INCLUDE_DIR}/clang")
configure_file(atdnaConfig.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/atdnaConfig.cmake" @ONLY)
# ... for both
configure_file(atdnaConfigVersion.cmake.in "${PROJECT_BINARY_DIR}/atdnaConfigVersion.cmake" @ONLY)
# Install atdnaConfig.cmake
install(FILES
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/atdnaConfig.cmake"
"${PROJECT_BINARY_DIR}/atdnaConfigVersion.cmake"
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()
#######################
# In-tree atdna macro #
#######################
# Super handy macro for adding atdna target
macro(atdna out)
# Make input files source-relative
set(ins "")
foreach(arg ${ARGN})
list(APPEND ins ${CMAKE_CURRENT_SOURCE_DIR}/${arg})
endforeach()
# Get local include directories for atdna
get_property(incdirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
set(inccli "")
foreach(dir ${incdirs})
list(APPEND inccli "-I${dir}")
endforeach()
# Get local defines for atdna
get_property(cdefs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY COMPILE_DEFINITIONS)
set(cdefcli "")
foreach(def ${cdefs})
list(APPEND cdefcli "-D${def}")
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)
endif()
# OSX Extra
elseif(APPLE)
2016-01-09 02:00:08 +00:00
if (NOT EXISTS "${CMAKE_OSX_SYSROOT}")
message(FATAL_ERROR "CMAKE_OSX_SYSROOT not set")
endif()
2015-11-11 07:01:41 +00:00
list(APPEND extraargs -isysroot ${CMAKE_OSX_SYSROOT} -I ${CMAKE_OSX_SYSROOT}/usr/include -isysroot
2015-10-12 05:17:39 +00:00
${CMAKE_OSX_SYSROOT}/../../../../../Toolchains/XcodeDefault.xctoolchain)
endif()
# Make target
2016-09-10 23:38:44 +00:00
add_custom_command(OUTPUT ${out} COMMAND $<TARGET_FILE:atdna>
ARGS ${extraargs} -o ${out} ${cdefcli} ${inccli} "-I${ATHENA_INCLUDE_DIR}"
-isystem "${CLANG_INCLUDE_DIR}" ${ins}
DEPENDS ${ins} COMMENT "Generating DNA ${out}")
endmacro()