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 )
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 }
2014-08-04 04:34:35 +04:00
A B S O L U T E )
2012-09-05 13:37:39 +04:00
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" )
2014-03-10 00:45:27 +04:00
# They are used as destination of target generators.
set ( LLVM_RUNTIME_OUTPUT_INTDIR ${ CMAKE_BINARY_DIR } / ${ CMAKE_CFG_INTDIR } /bin )
set ( LLVM_LIBRARY_OUTPUT_INTDIR ${ CMAKE_BINARY_DIR } / ${ CMAKE_CFG_INTDIR } /lib )
2012-09-05 13:37:39 +04:00
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" )
2015-03-21 14:52:02 +03:00
if ( ${ CMAKE_CXX_COMPILER_ID } STREQUAL Clang )
string ( COMPARE GREATER ${ CLANG_MAJOR } "3" IS_CLANG_GREATER_THAN_3_X )
string ( COMPARE GREATER ${ CLANG_MINOR } "5" IS_CLANG_GREATER_THAN_3_5 )
2015-04-17 10:31:12 +03:00
if ( ( IS_CLANG_GREATER_THAN_3_X OR IS_CLANG_GREATER_THAN_3_5 ) AND NOT APPLE )
2015-03-21 14:52:02 +03:00
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-local-typedefs" )
endif ( )
endif ( )
2012-09-05 13:37:39 +04:00
endif ( )
2014-02-21 00:56:13 +04:00
# The package needs to be compiler without RTTI information
if ( MSVC )
add_definitions ( /GR- )
else ( )
add_definitions ( -fno-rtti )
endif ( )
2014-02-19 21:52:42 +04:00
2012-09-05 13:37:39 +04:00
if ( APPLE )
set ( CMAKE_MODULE_LINKER_FLAGS "-Wl,-flat_namespace -Wl,-undefined -Wl,suppress" )
endif ( )
include ( LLVMParseArguments )
macro ( add_cling_library name )
2014-03-08 16:15:48 +04:00
cmake_parse_arguments ( ARG
" "
" "
" A D D I T I O N A L _ H E A D E R S "
$ { A R G N } )
set ( srcs )
2012-09-05 13:37:39 +04:00
if ( MSVC_IDE OR XCODE )
2014-03-08 16:15:48 +04:00
# Add public headers
file ( RELATIVE_PATH lib_path
$ { C L I N G _ S O U R C E _ D I R } / l i b /
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R }
)
if ( NOT lib_path MATCHES "^[.][.]" )
file ( GLOB_RECURSE headers
$ { 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 / $ { l i b _ p a t h } / * . h
$ { 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 / $ { l i b _ p a t h } / * . d e f
)
set_source_files_properties ( ${ headers } PROPERTIES HEADER_FILE_ONLY ON )
file ( GLOB_RECURSE tds
$ { 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 / $ { l i b _ p a t h } / * . t d
)
source_group ( "TableGen descriptions" FILES ${ tds } )
set_source_files_properties ( ${ tds } } PROPERTIES HEADER_FILE_ONLY ON )
if ( headers OR tds )
2014-08-04 04:34:35 +04:00
set ( srcs ${ headers } ${ tds } )
2014-03-08 16:15:48 +04:00
endif ( )
endif ( )
2012-09-05 13:37:39 +04:00
endif ( MSVC_IDE OR XCODE )
2014-03-08 16:15:48 +04:00
if ( srcs OR ARG_ADDITIONAL_HEADERS )
set ( srcs
A D D I T I O N A L _ H E A D E R S
$ { s r c s }
$ { A R G _ A D D I T I O N A L _ H E A D E R S } # It may contain unparsed unknown args.
)
endif ( )
llvm_add_library ( ${ name } ${ ARG_UNPARSED_ARGUMENTS } ${ srcs } )
if ( TARGET ${ name } )
target_link_libraries ( ${ name } ${ cmake_2_8_12_INTERFACE } ${ LLVM_COMMON_LIBS } )
if ( NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${ name } STREQUAL "libcling" )
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 }
R U N T I M E D E S T I N A T I O N b i n )
endif ( )
2012-09-05 13:37:39 +04:00
else ( )
2014-03-08 16:15:48 +04:00
# Add empty "phony" target
add_custom_target ( ${ name } )
2012-09-05 13:37:39 +04:00
endif ( )
2014-03-08 16:15:48 +04:00
2012-09-05 13:37:39 +04:00
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 )
2014-10-02 14:34:09 +04:00
# this is needed when building Cling as part of ROOT:
2012-09-05 13:37:39 +04:00
include_directories ( BEFORE
2014-09-04 19:43:30 +04:00
$ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / . . / l l v m / s r c / t o o l s / 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 } / . . / l l v m / s r c / t o o l s / c l a n g / i n c l u d e
2012-09-05 13:37:39 +04:00
)
2014-10-02 14:34:09 +04:00
# and this when building Cling standalone:
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
)
2012-09-05 13:37:39 +04:00
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 "
)
2014-05-13 18:42:13 +04:00
add_definitions ( -D_GNU_SOURCE
- 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 " )
2014-05-09 16:46:58 +04:00
# Determine cling's version:
file ( STRINGS "VERSION" CLING_VERSION )
2014-09-20 18:19:05 +04:00
set ( CLING_VERSION ROOT_ ${ CLING_VERSION } )
2014-05-09 16:46:58 +04:00
2012-09-05 13:37:39 +04:00
add_subdirectory ( lib )
add_subdirectory ( tools )
# TODO: docs.
#add_subdirectory(test)
2014-01-28 17:30:55 +04:00
option ( CLING_INCLUDE_TESTS
" G e n e r a t e b u i l d t a r g e t s f o r t h e C l i n g u n i t t e s t s . "
$ { L L V M _ I N C L U D E _ T E S T S } )
if ( CLING_INCLUDE_TESTS )
add_subdirectory ( test )
endif ( )
2012-09-05 13:37:39 +04:00
# 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 ( )