2014-01-07 14:57:25 +04:00
#------------------------------------------------------------------------------
# CLING - the C++ LLVM-based InterpreterG :)
#
# This file is dual-licensed: you can choose to license it under the University
# of Illinois Open Source License or the GNU Lesser General Public License. See
# LICENSE.TXT for details.
#------------------------------------------------------------------------------
2012-09-05 13:37:39 +04:00
# If we are not building as a part of LLVM, build Cling as an
# standalone project, using LLVM as an external library:
if ( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
project ( Cling )
cmake_minimum_required ( VERSION 2.8 )
2012-12-13 21:22:52 +04:00
find_package ( Subversion )
2012-09-05 13:37:39 +04:00
set ( CLING_PATH_TO_LLVM_SOURCE "" CACHE PATH
" P a t h t o L L V M s o u r c e c o d e . N o t n e c e s s a r y i f u s i n g a n i n s t a l l e d L L V M . " )
set ( CLING_PATH_TO_LLVM_BUILD "" CACHE PATH
" P a t h t o t h e d i r e c t o r y w h e r e L L V M w a s b u i l t o r i n s t a l l e d . " )
if ( CLING_PATH_TO_LLVM_SOURCE )
if ( NOT EXISTS "${CLING_PATH_TO_LLVM_SOURCE}/cmake/config-ix.cmake" )
message ( FATAL_ERROR "Please set CLING_PATH_TO_LLVM_SOURCE to the root directory of LLVM source code." )
else ( )
get_filename_component ( LLVM_MAIN_SRC_DIR ${ CLING_PATH_TO_LLVM_SOURCE }
A B S O L U T E )
list ( APPEND CMAKE_MODULE_PATH "${LLVM_MAIN_SRC_DIR}/cmake/modules" )
endif ( )
endif ( )
2012-12-13 21:22:52 +04:00
if ( NOT EXISTS "${CLING_PATH_TO_LLVM_BUILD}/bin/llvm-tblgen${CMAKE_EXECUTABLE_SUFFIX}" )
2012-09-05 13:37:39 +04:00
message ( FATAL_ERROR "Please set CLING_PATH_TO_LLVM_BUILD to a directory containing a LLVM build." )
endif ( )
list ( APPEND CMAKE_MODULE_PATH "${CLING_PATH_TO_LLVM_BUILD}/share/llvm/cmake" )
get_filename_component ( PATH_TO_LLVM_BUILD ${ CLING_PATH_TO_LLVM_BUILD }
A B S O L U T E )
include ( AddLLVM )
include ( "${CLING_PATH_TO_LLVM_BUILD}/share/llvm/cmake/LLVMConfig.cmake" )
include ( HandleLLVMOptions )
set ( PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}" )
set ( LLVM_MAIN_INCLUDE_DIR "${LLVM_MAIN_SRC_DIR}/include" )
set ( LLVM_BINARY_DIR ${ CMAKE_BINARY_DIR } )
set ( CMAKE_INCLUDE_CURRENT_DIR ON )
include_directories ( "${PATH_TO_LLVM_BUILD}/include" "${LLVM_MAIN_INCLUDE_DIR}" )
link_directories ( "${PATH_TO_LLVM_BUILD}/lib" )
2012-12-13 21:22:52 +04:00
set ( LLVM_TABLEGEN_EXE "${PATH_TO_LLVM_BUILD}/bin/llvm-tblgen" )
2012-09-05 13:37:39 +04:00
set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${ CMAKE_BINARY_DIR } /bin )
set ( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${ CMAKE_BINARY_DIR } /lib )
set ( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${ CMAKE_BINARY_DIR } /lib )
set ( CLING_BUILT_STANDALONE 1 )
endif ( )
set ( C_INCLUDE_DIRS "" CACHE STRING
" C o l o n s e p a r a t e d l i s t o f d i r e c t o r i e s c l i n g w i l l s e a r c h f o r h e a d e r s . " )
set ( CLING_SOURCE_DIR ${ CMAKE_CURRENT_SOURCE_DIR } )
set ( CLING_BINARY_DIR ${ CMAKE_CURRENT_BINARY_DIR } )
if ( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
message ( FATAL_ERROR "In-source builds are not allowed. CMake would overwrite "
" t h e m a k e f i l e s d i s t r i b u t e d w i t h L L V M . P l e a s e c r e a t e a d i r e c t o r y a n d r u n c m a k e "
" f r o m t h e r e , p a s s i n g t h e p a t h t o t h i s s o u r c e d i r e c t o r y a s t h e l a s t a r g u m e n t . "
" T h i s p r o c e s s c r e a t e d t h e f i l e ` C M a k e C a c h e . t x t ' a n d t h e d i r e c t o r y "
" ` C M a k e F i l e s ' . P l e a s e d e l e t e t h e m . " )
endif ( )
# Add appropriate flags for GCC
if ( LLVM_COMPILER_IS_GCC_COMPATIBLE )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual -Wcast-qual -fno-strict-aliasing -pedantic -Wno-long-long -Wall -W -Wno-unused-parameter -Wwrite-strings" )
endif ( )
if ( APPLE )
set ( CMAKE_MODULE_LINKER_FLAGS "-Wl,-flat_namespace -Wl,-undefined -Wl,suppress" )
endif ( )
include ( LLVMParseArguments )
macro ( add_cling_library name )
llvm_process_sources ( srcs ${ ARGN } )
if ( MSVC_IDE OR XCODE )
string ( REGEX MATCHALL "/[^/]+" split_path ${ CMAKE_CURRENT_SOURCE_DIR } )
list ( GET split_path -1 dir )
file ( GLOB_RECURSE headers
. . / . . / i n c l u d e / c l i n g $ { d i r } / * . h
. . / . . / i n c l u d e / c l i n g $ { d i r } / * . t d
. . / . . / i n c l u d e / c l i n g $ { d i r } / * . d e f )
set ( srcs ${ srcs } ${ headers } )
endif ( MSVC_IDE OR XCODE )
if ( MODULE )
set ( libkind MODULE )
elseif ( SHARED_LIBRARY )
set ( libkind SHARED )
else ( )
set ( libkind )
endif ( )
add_library ( ${ name } ${ libkind } ${ srcs } )
if ( LLVM_COMMON_DEPENDS )
add_dependencies ( ${ name } ${ LLVM_COMMON_DEPENDS } )
endif ( LLVM_COMMON_DEPENDS )
target_link_libraries ( ${ name } ${ LLVM_USED_LIBS } )
llvm_config ( ${ name } ${ LLVM_LINK_COMPONENTS } )
target_link_libraries ( ${ name } ${ LLVM_COMMON_LIBS } )
link_system_libs ( ${ name } )
if ( MSVC )
get_target_property ( cflag ${ name } COMPILE_FLAGS )
if ( NOT cflag )
set ( cflag "" )
endif ( NOT cflag )
2013-12-04 13:58:47 +04:00
set ( cflag "${cflag} " )
2012-09-05 13:37:39 +04:00
set_target_properties ( ${ name } PROPERTIES COMPILE_FLAGS ${ cflag } )
endif ( MSVC )
install ( TARGETS ${ name }
L I B R A R Y D E S T I N A T I O N l i b $ { L L V M _ L I B D I R _ S U F F I X }
A R C H I V E D E S T I N A T I O N l i b $ { L L V M _ L I B D I R _ S U F F I X } )
set_target_properties ( ${ name } PROPERTIES FOLDER "Cling libraries" )
endmacro ( add_cling_library )
macro ( add_cling_executable name )
add_llvm_executable ( ${ name } ${ ARGN } )
set_target_properties ( ${ name } PROPERTIES FOLDER "Cling executables" )
endmacro ( add_cling_executable )
include_directories ( BEFORE
$ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / . . / c l a n g / i n c l u d e
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / . . / c l a n g / i n c l u d e
)
include_directories ( BEFORE
$ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / i n c l u d e
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / i n c l u d e
)
install ( DIRECTORY include/
D E S T I N A T I O N i n c l u d e
F I L E S _ M A T C H I N G
P A T T E R N " * . d e f "
P A T T E R N " * . h "
P A T T E R N " . s v n " E X C L U D E
)
install ( DIRECTORY ${ CMAKE_CURRENT_BINARY_DIR } /include/
D E S T I N A T I O N i n c l u d e
F I L E S _ M A T C H I N G
P A T T E R N " C M a k e F i l e s " E X C L U D E
P A T T E R N " * . i n c "
)
add_definitions ( -D_GNU_SOURCE
2013-09-30 20:09:26 +04:00
- D C L I N G _ I N C L U D E _ P A T H S = " $ { C L I N G _ S O U R C E _ D I R } / i n c l u d e : $ { C L I N G _ B I N A R Y _ D I R } / i n c l u d e " )
2012-09-05 13:37:39 +04:00
add_subdirectory ( lib )
add_subdirectory ( tools )
# TODO: docs.
#add_subdirectory(test)
# Workaround for MSVS10 to avoid the Dialog Hell
# FIXME: This could be removed with future version of CMake.
if ( CLING_BUILT_STANDALONE AND MSVC_VERSION EQUAL 1600 )
set ( CLING_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/Cling.sln" )
if ( EXISTS "${CLING_SLN_FILENAME}" )
file ( APPEND "${CLING_SLN_FILENAME}" "\n# This should be regenerated!\n" )
endif ( )
endif ( )