From 3d01fc7de86c75926e4e5ac7cc49f0116018893d Mon Sep 17 00:00:00 2001 From: Oscar Fuentes Date: Mon, 22 Sep 2008 01:08:49 +0000 Subject: Initial support for the CMake build system. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56419 91177308-0d34-0410-b5e6-96231b3b80d8 --- cmake/config-ix.cmake | 93 ++++++++++++++++++++++++++++ cmake/config-w32.cmake | 9 +++ cmake/modules/AddLLVM.cmake | 39 ++++++++++++ cmake/modules/AddPartiallyLinkedObject.cmake | 21 +++++++ cmake/modules/CheckCxxHashmap.cmake | 53 ++++++++++++++++ cmake/modules/CheckCxxHashset.cmake | 52 ++++++++++++++++ cmake/modules/FindBison.cmake | 52 ++++++++++++++++ cmake/modules/LLVMConfig.cmake | 57 +++++++++++++++++ 8 files changed, 376 insertions(+) create mode 100755 cmake/config-ix.cmake create mode 100755 cmake/config-w32.cmake create mode 100755 cmake/modules/AddLLVM.cmake create mode 100755 cmake/modules/AddPartiallyLinkedObject.cmake create mode 100755 cmake/modules/CheckCxxHashmap.cmake create mode 100755 cmake/modules/CheckCxxHashset.cmake create mode 100755 cmake/modules/FindBison.cmake create mode 100755 cmake/modules/LLVMConfig.cmake (limited to 'cmake') diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake new file mode 100755 index 0000000000..6cd88da0bc --- /dev/null +++ b/cmake/config-ix.cmake @@ -0,0 +1,93 @@ + +# include checks +include(CheckIncludeFile) +check_include_file(argz.h HAVE_ARGZ_H) +check_include_file(assert.h HAVE_ASSERT_H) +check_include_file(dirent.h HAVE_DIRENT_H) +check_include_file(dl.h HAVE_DL_H) +check_include_file(dld.h HAVE_DLD_H) +check_include_file(dlfcn.h HAVE_DLFCN_H) +check_include_file(errno.h HAVE_ERRNO_H) +check_include_file(execinfo.h HAVE_EXECINFO_H) +check_include_file(fcntl.h HAVE_FCNTL_H) +check_include_file(inttypes.h HAVE_INTTYPES_H) +check_include_file(limits.h HAVE_LIMITS_H) +check_include_file(link.h HAVE_LINK_H) +check_include_file(malloc.h HAVE_MALLOC_H) +check_include_file(malloc/malloc.h HAVE_MALLOC_MALLOC_H) +check_include_file(memory.h HAVE_MEMORY_H) +check_include_file(ndir.h HAVE_NDIR_H) +check_include_file(pthread.h HAVE_PTHREAD_H) +check_include_file(setjmp.h HAVE_SETJMP_H) +check_include_file(signal.h HAVE_SIGNAL_H) +check_include_file(stdint.h HAVE_STDINT_H) +check_include_file(stdio.h HAVE_STDIO_H) +check_include_file(stdlib.h HAVE_STDLIB_H) +check_include_file(sys/dir.h HAVE_SYS_DIR_H) +check_include_file(sys/dl.h HAVE_SYS_DL_H) +check_include_file(sys/mman.h HAVE_SYS_MMAN_H) +check_include_file(sys/ndir.h HAVE_SYS_NDIR_H) +check_include_file(sys/param.h HAVE_SYS_PARAM_H) +check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H) +check_include_file(sys/stat.h HAVE_SYS_STAT_H) +check_include_file(sys/time.h HAVE_SYS_TIME_H) +check_include_file(sys/types.h HAVE_SYS_TYPES_H) +check_include_file(unistd.h HAVE_UNISTD_H) +check_include_file(utime.h HAVE_UTIME_H) + +# function checks +include(CheckSymbolExists) +check_symbol_exists(getpagesize unistd.h HAVE_GETPAGESIZE) +check_symbol_exists(getrusage sys/resource.h HAVE_GETRUSAGE) +check_symbol_exists(setrlimit sys/resource.h HAVE_SETRLIMIT) +check_symbol_exists(isinf cmath HAVE_ISINF_IN_CMATH) +check_symbol_exists(isinf math.h HAVE_ISINF_IN_MATH_H) +check_symbol_exists(isnan cmath HAVE_ISNAN_IN_CMATH) +check_symbol_exists(isnan math.h HAVE_ISNAN_IN_MATH_H) +check_symbol_exists(mallinfo malloc.h HAVE_MALLINFO) +check_symbol_exists(pthread_mutex_lock pthread.h HAVE_PTHREAD_MUTEX_LOCK) + +if( MINGW ) + # tbi: Comprobar que existen las librerias: + set(HAVE_LIBIMAGEHLP 1) + set(HAVE_LIBPSAPI 1) + # include(CheckLibraryExists) + # CHECK_LIBRARY_EXISTS(imagehlp ??? . HAVE_LIBIMAGEHLP) +endif( MINGW ) + +# Classes +include(CheckCxxHashmap) +include(CheckCxxHashset) +check_hashmap() +check_hashset() + +# FIXME: Signal handler return type, currently hardcoded to 'void' +set(RETSIGTYPE void) + +# Disable multithreading for now +set(ENABLE_THREADS 0) + +configure_file( + ${LLVM_MAIN_INCLUDE_DIR}/Config/config.h.cmake + ${LLVM_BINARY_DIR}/include/llvm/Config/config.h + ) + +configure_file( + ${LLVM_MAIN_INCLUDE_DIR}/ADT/iterator.cmake + ${LLVM_BINARY_DIR}/include/llvm/ADT/iterator.h + ) + +configure_file( + ${LLVM_MAIN_INCLUDE_DIR}/Support/DataTypes.h.cmake + ${LLVM_BINARY_DIR}/include/llvm/Support/DataTypes.h + ) + +configure_file( + ${LLVM_MAIN_INCLUDE_DIR}/ADT/hash_map.cmake + ${LLVM_BINARY_DIR}/include/llvm/ADT/hash_map.h + ) + +configure_file( + ${LLVM_MAIN_INCLUDE_DIR}/ADT/hash_set.cmake + ${LLVM_BINARY_DIR}/include/llvm/ADT/hash_set.h + ) diff --git a/cmake/config-w32.cmake b/cmake/config-w32.cmake new file mode 100755 index 0000000000..208e77628c --- /dev/null +++ b/cmake/config-w32.cmake @@ -0,0 +1,9 @@ +# tbi: Configurar ficheros. +configure_file(${llvm_include_path}/llvm/ADT/hash_map.h.in ${llvm_builded_incs_dir}/ADT/hash_map.h) +configure_file(${llvm_include_path}/llvm/ADT/hash_set.h.in ${llvm_builded_incs_dir}/ADT/hash_set.h) +configure_file(${llvm_include_path}/llvm/ADT/iterator.h.in ${llvm_builded_incs_dir}/ADT/iterator.h) +configure_file(${llvm_include_path}/llvm/Support/DataTypes.h.in ${llvm_builded_incs_dir}/Support/DataTypes.h) +configure_file(${llvm_include_path}/llvm/Config/config.h.in ${llvm_builded_incs_dir}/Config/config.h) + +file(READ ${llvm_include_path}/../win32/config.h vc_config_text) +file(APPEND ${llvm_builded_incs_dir}/Config/config.h ${vc_config_text}) diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake new file mode 100755 index 0000000000..c3641eacd2 --- /dev/null +++ b/cmake/modules/AddLLVM.cmake @@ -0,0 +1,39 @@ +include(LLVMConfig) + +macro(add_llvm_library name) + add_library( ${name} ${ARGN} ) + set( llvm_libs ${llvm_libs} ${name} PARENT_SCOPE) +endmacro(add_llvm_library name) + + +macro(add_llvm_executable name) + add_executable(${name} ${ARGN}) + if( LLVM_LINK_COMPONENTS ) + llvm_config(${name} ${LLVM_LINK_COMPONENTS}) + endif( LLVM_LINK_COMPONENTS ) + if( MSVC ) + target_link_libraries(${name} ${llvm_libs}) + else( MSVC ) + add_dependencies(${name} llvm-config.target) + set_target_properties(${name} + PROPERTIES + LINK_FLAGS "-L ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}") + if( MINGW ) + target_link_libraries(${name} DbgHelp psapi) + elseif( CMAKE_HOST_UNIX ) + target_link_libraries(${name} dl) + endif( MINGW ) + endif( MSVC ) +endmacro(add_llvm_executable name) + + +macro(add_llvm_tool name) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR}) + add_llvm_executable(${name} ${ARGN}) +endmacro(add_llvm_tool name) + + +macro(add_llvm_example name) +# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_EXAMPLES_BINARY_DIR}) + add_llvm_executable(${name} ${ARGN}) +endmacro(add_llvm_example name) diff --git a/cmake/modules/AddPartiallyLinkedObject.cmake b/cmake/modules/AddPartiallyLinkedObject.cmake new file mode 100755 index 0000000000..b985b3eb28 --- /dev/null +++ b/cmake/modules/AddPartiallyLinkedObject.cmake @@ -0,0 +1,21 @@ + +macro(add_partially_linked_object lib) + if( MSVC ) + add_llvm_library( ${lib} ${ARGN}) + else( MSVC ) + set(pll ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${lib}.o) + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/temp_lib) + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/temp_lib) + add_library( ${lib} STATIC ${ARGN}) + add_custom_command(OUTPUT ${pll} + MESSAGE "Building ${lib}.o..." + DEPENDS ${lib} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/temp_lib + COMMAND ar x ${CMAKE_STATIC_LIBRARY_PREFIX}${lib}${CMAKE_STATIC_LIBRARY_SUFFIX} + COMMAND ld -r *${CMAKE_CXX_OUTPUT_EXTENSION} -o ${pll} + COMMAND rm -f *${CMAKE_CXX_OUTPUT_EXTENSION} + ) + add_custom_target(${lib}_pll ALL DEPENDS ${pll}) + set( llvm_libs ${llvm_libs} ${pll} PARENT_SCOPE) + endif( MSVC ) +endmacro(add_partially_linked_object lib) diff --git a/cmake/modules/CheckCxxHashmap.cmake b/cmake/modules/CheckCxxHashmap.cmake new file mode 100755 index 0000000000..5f16c0ac44 --- /dev/null +++ b/cmake/modules/CheckCxxHashmap.cmake @@ -0,0 +1,53 @@ +# - Check if for hash_map. +# CHECK_HASHMAP () +# + +include(CheckCXXSourceCompiles) + +macro(CHECK_HASHMAP) + message(STATUS "Checking for C++ hash_map implementation...") + check_cxx_source_compiles(" + #include + int main() { + __gnu_cxx::hash_map t; + } +" + HAVE_GNU_EXT_HASH_MAP + ) + if(HAVE_GNU_EXT_HASH_MAP) + message(STATUS "C++ hash_map found in 'ext' dir in namespace __gnu_cxx::") + endif(HAVE_GNU_EXT_HASH_MAP) + + check_cxx_source_compiles(" + #include + int main() { + std::hash_map t; + } +" + HAVE_STD_EXT_HASH_MAP + ) + if(HAVE_STD_EXT_HASH_MAP) + message(STATUS "C++ hash_map found in 'ext' dir in namespace std::") + endif(HAVE_STD_EXT_HASH_MAP) + + check_cxx_source_compiles(" + #include + int main() { + hash_map t; + } +" + HAVE_GLOBAL_HASH_MAP + ) + if(HAVE_GLOBAL_HASH_MAP) + message(STATUS "C++ hash_map found in global namespace") + endif(HAVE_GLOBAL_HASH_MAP) + + if(NOT HAVE_GNU_EXT_HASH_MAP) + if(NOT HAVE_STD_EXT_HASH_MAP) + if(NOT HAVE_GLOBAL_HASH_MAP) + message(STATUS "C++ hash_map not found") + endif(NOT HAVE_GLOBAL_HASH_MAP) + endif(NOT HAVE_STD_EXT_HASH_MAP) + endif(NOT HAVE_GNU_EXT_HASH_MAP) + +endmacro(CHECK_HASHMAP) diff --git a/cmake/modules/CheckCxxHashset.cmake b/cmake/modules/CheckCxxHashset.cmake new file mode 100755 index 0000000000..940c388127 --- /dev/null +++ b/cmake/modules/CheckCxxHashset.cmake @@ -0,0 +1,52 @@ +# - Check if for hash_set. +# CHECK_HASHSET () +# + +include(CheckCXXSourceCompiles) + +macro(CHECK_HASHSET) + message(STATUS "Checking for C++ hash_set implementation...") + check_cxx_source_compiles(" + #include + int main() { + __gnu_cxx::hash_set t; + } +" + HAVE_GNU_EXT_HASH_SET + ) + if(HAVE_GNU_EXT_HASH_SET) + message(STATUS "C++ hash_set found in 'ext' dir in namespace __gnu_cxx::") + endif(HAVE_GNU_EXT_HASH_SET) + + check_cxx_source_compiles(" + #include + int main() { + std::hash_set t; + } +" + HAVE_STD_EXT_HASH_SET + ) + if(HAVE_STD_EXT_HASH_SET) + message(STATUS "C++ hash_set found in 'ext' dir in namespace std::") + endif(HAVE_STD_EXT_HASH_SET) + + check_cxx_source_compiles(" + #include + int main() { + hash_set t; + } +" + HAVE_GLOBAL_HASH_SET + ) + if(HAVE_GLOBAL_HASH_SET) + message(STATUS "C++ hash_set found in global namespace") + endif(HAVE_GLOBAL_HASH_SET) + + if(NOT HAVE_GNU_EXT_HASH_SET) + if(NOT HAVE_STD_EXT_HASH_SET) + if(NOT HAVE_GLOBAL_HASH_SET) + message(STATUS "C++ hash_set not found") + endif(NOT HAVE_GLOBAL_HASH_SET) + endif(NOT HAVE_STD_EXT_HASH_SET) + endif(NOT HAVE_GNU_EXT_HASH_SET) +endmacro(CHECK_HASHSET) diff --git a/cmake/modules/FindBison.cmake b/cmake/modules/FindBison.cmake new file mode 100755 index 0000000000..0320ae3ce1 --- /dev/null +++ b/cmake/modules/FindBison.cmake @@ -0,0 +1,52 @@ +# - Try to find Bison +# Once done this will define +# +# BISON_FOUND - system has Bison +# BISON_EXECUTABLE - path of the bison executable +# BISON_VERSION - the version string, like "2.5.31" +# + +MACRO(FIND_BISON) + FIND_PROGRAM(BISON_EXECUTABLE NAMES bison) + + IF(BISON_EXECUTABLE) + SET(BISON_FOUND TRUE) + + EXECUTE_PROCESS(COMMAND ${BISON_EXECUTABLE} --version + OUTPUT_VARIABLE _BISON_VERSION + ) + string (REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" BISON_VERSION "${_bison_VERSION}") + ENDIF(BISON_EXECUTABLE) + + IF(BISON_FOUND) + IF(NOT Bison_FIND_QUIETLY) + MESSAGE(STATUS "Found Bison: ${BISON_EXECUTABLE}") + ENDIF(NOT Bison_FIND_QUIETLY) + ELSE(BISON_FOUND) + IF(Bison_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could not find Bison") + ENDIF(Bison_FIND_REQUIRED) + ENDIF(BISON_FOUND) +ENDMACRO(FIND_BISON) + +MACRO(BISON_GENERATOR _PREFIX _Y_INPUT _H_OUTPUT _CPP_OUTPUT) + IF(BISON_EXECUTABLE) + GET_FILENAME_COMPONENT(_Y_DIR ${_Y_INPUT} PATH) + ADD_CUSTOM_COMMAND( + OUTPUT ${_CPP_OUTPUT} + OUTPUT ${_H_OUTPUT} + DEPENDS ${_Y_INPUT} + COMMAND ${BISON_EXECUTABLE} + ARGS + -p ${_PREFIX} -o"${_CPP_OUTPUT}" + --defines="${_H_OUTPUT}" ${_Y_INPUT} + WORKING_DIRECTORY ${_Y_DIR} + ) + SET_SOURCE_FILES_PROPERTIES( + ${_CPP_OUTPUT} ${_H_OUTPUT} + GENERATED + ) + ELSE(BISON_EXECUTABLE) + MESSAGE(SEND_ERROR "Can't find bison program, and it's required") + ENDIF(BISON_EXECUTABLE) +ENDMACRO(BISON_GENERATOR) diff --git a/cmake/modules/LLVMConfig.cmake b/cmake/modules/LLVMConfig.cmake new file mode 100755 index 0000000000..f87d16cd1f --- /dev/null +++ b/cmake/modules/LLVMConfig.cmake @@ -0,0 +1,57 @@ +macro(llvm_config executable link_components) + if( MSVC ) + msvc_llvm_config(${executable} ${link_components}) + else( MSVC ) + nix_llvm_config(${executable} ${link_components}) + endif( MSVC ) +endmacro(llvm_config executable link_components) + + +macro(msvc_llvm_config executable link_components) + foreach(c ${link_components}) + message(STATUS ${c}) + if( c STREQUAL "jit" ) + message(STATUS "linking jit") + set_target_properties(${executable} + PROPERTIES + LINK_FLAGS "/INCLUDE:_X86TargetMachineModule") + endif( c STREQUAL "jit" ) + endforeach(c) + target_link_libraries(${executable} ${llvm_libs}) +endmacro(msvc_llvm_config executable link_components) + + +macro(nix_llvm_config executable link_components) + set(lc "") + foreach(c ${LLVM_LINK_COMPONENTS}) + set(lc "${lc} ${c}") + endforeach(c) + if( NOT HAVE_LLVM_CONFIG ) + target_link_libraries(${executable} + "`${LLVM_TOOLS_BINARY_DIR}/llvm-config --libs ${lc}`") + else( NOT HAVE_LLVM_CONFIG ) + # tbi: Error handling. + if( NOT PERL_FOUND ) + message(FATAL_ERROR "Perl required but not found!") + endif( NOT PERL_FOUND ) + execute_process( + COMMAND sh -c "${PERL_EXECUTABLE} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/llvm-config --libs ${lc}" + RESULT_VARIABLE rv + OUTPUT_VARIABLE libs + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(NOT rv EQUAL 0) + message(FATAL_ERROR "llvm-config failed for executable ${executable}") + endif(NOT rv EQUAL 0) + string(REPLACE " " ";" libs ${libs}) + foreach(c ${libs}) + if(c MATCHES ".*\\.o") + get_filename_component(fn ${c} NAME) + target_link_libraries(${executable} + ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${fn}) + else(c MATCHES ".*\\.o") + string(REPLACE "-l" "" fn ${c}) + target_link_libraries(${executable} ${fn}) + endif(c MATCHES ".*\\.o") + endforeach(c) + endif( NOT HAVE_LLVM_CONFIG ) +endmacro(nix_llvm_config executable link_components) -- cgit v1.2.3