1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-11-10 20:10:05 +00:00

Added packaging option. Fixing some linking problems with gflags

This commit is contained in:
Carles Fernandez 2014-11-11 23:50:38 +01:00
parent b0a87def18
commit 826a150e3f
3 changed files with 222 additions and 60 deletions

View File

@ -41,6 +41,11 @@ option(ENABLE_RTLSDR "Enable the use of RTL dongles as signal source (experiment
option(ENABLE_OPENCL "Enable building of processing blocks implemented with OpenCL (experimental)" OFF) option(ENABLE_OPENCL "Enable building of processing blocks implemented with OpenCL (experimental)" OFF)
option(ENABLE_GPERFTOOLS "Enable linking to Gperftools libraries (tcmalloc and profiler)" OFF) option(ENABLE_GPERFTOOLS "Enable linking to Gperftools libraries (tcmalloc and profiler)" OFF)
option(ENABLE_GENERIC_ARCH "Builds a portable binary" OFF) option(ENABLE_GENERIC_ARCH "Builds a portable binary" OFF)
option(ENABLE_PACKAGING "Enable software packaging" OFF)
if(${ENABLE_PACKAGING})
set(ENABLE_GENERIC_ARCH ON)
endif(${ENABLE_PACKAGING})
############################### ###############################
@ -458,7 +463,7 @@ endif(NOT GFlags_FOUND)
################################################################################ ################################################################################
find_package(GLOG) find_package(GLOG)
set(glog_RELEASE 0.3.3) set(glog_RELEASE 0.3.3)
if (NOT GLOG_FOUND OR LOCAL_GFLAGS) if (NOT GLOG_FOUND OR ${LOCAL_GFLAGS})
message (STATUS " glog library has not been found") message (STATUS " glog library has not been found")
if(NOT GFlags_FOUND) if(NOT GFlags_FOUND)
message(STATUS " or it is likely not linked to gflags.") message(STATUS " or it is likely not linked to gflags.")
@ -473,6 +478,7 @@ if (NOT GLOG_FOUND OR LOCAL_GFLAGS)
set(glog_MD5 "a6fd2c22f8996846e34c763422717c18") set(glog_MD5 "a6fd2c22f8996846e34c763422717c18")
if(${LOCAL_GFLAGS}) if(${LOCAL_GFLAGS})
set(TARGET_GFLAGS ${gflags})
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/glog-${glog_RELEASE}/tmp/configure_with_gflags file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/glog-${glog_RELEASE}/tmp/configure_with_gflags
"#!/bin/sh "#!/bin/sh
@ -501,7 +507,8 @@ export LIBS=${GFlags_SHARED_LIBS}
endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
else(${LOCAL_GFLAGS}) else(${LOCAL_GFLAGS})
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") set(TARGET_GFLAGS gflags-${gflags_RELEASE})
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/glog-${glog_RELEASE}/tmp/configure_with_gflags file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/glog-${glog_RELEASE}/tmp/configure_with_gflags
"#!/bin/sh "#!/bin/sh
export CPPFLAGS=-I${GFlags_INCLUDE_DIRS} export CPPFLAGS=-I${GFlags_INCLUDE_DIRS}
@ -515,36 +522,25 @@ export CXX=clang++
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/glog-${glog_RELEASE} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/glog-${glog_RELEASE}
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ
GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
else("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") else("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/glog-${glog_RELEASE}/tmp/configure_with_gflags file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/glog-${glog_RELEASE}/tmp/configure_with_gflags
"#!/bin/sh "#!/bin/sh
export CPPFLAGS=-I${GFlags_INCLUDE_DIRS} export CPPFLAGS=-I${GFlags_INCLUDE_DIRS}
export LDFLAGS=-L${CMAKE_CURRENT_BINARY_DIR}/gflags-${gflags_RELEASE}/.libs export LDFLAGS=-L${CMAKE_CURRENT_BINARY_DIR}/gflags-${gflags_RELEASE}/.libs
export LIBS=${GFlags_SHARED_LIBS} export LIBS=${GFlags_SHARED_LIBS}
../../thirdparty/glog/glog-${glog_RELEASE}/configure") ../../thirdparty/glog/glog-${glog_RELEASE}/configure")
file(COPY ${CMAKE_CURRENT_BINARY_DIR}/glog-${glog_RELEASE}/tmp/configure_with_gflags file(COPY ${CMAKE_CURRENT_BINARY_DIR}/glog-${glog_RELEASE}/tmp/configure_with_gflags
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/glog-${glog_RELEASE} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/glog-${glog_RELEASE}
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ
GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
else(LOCAL_GFLAGS)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/glog-${glog_RELEASE}/tmp/configure_with_gflags
"#!/bin/sh
export CPPFLAGS=-I${GFlags_INCLUDE_DIRS}
export LDFLAGS=-L${GFlags_LIBRARY_DIRS}
export LIBS=${GFlags_LIBS}
../../thirdparty/glog/glog-${glog_RELEASE}/configure")
file(COPY ${CMAKE_CURRENT_BINARY_DIR}/glog-${glog_RELEASE}/tmp/configure_with_gflags
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/glog-${glog_RELEASE}
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ
GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
endif(${LOCAL_GFLAGS}) endif(${LOCAL_GFLAGS})
set(GLOG_CONFIGURE ${CMAKE_CURRENT_BINARY_DIR}/glog-${glog_RELEASE}/configure_with_gflags) set(GLOG_CONFIGURE ${CMAKE_CURRENT_BINARY_DIR}/glog-${glog_RELEASE}/configure_with_gflags)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
ExternalProject_Add( ExternalProject_Add(
glog-${glog_RELEASE} glog-${glog_RELEASE}
DEPENDS gflags-${gflags_RELEASE} DEPENDS ${TARGET_GFLAGS}
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/glog-${glog_RELEASE} PREFIX ${CMAKE_CURRENT_BINARY_DIR}/glog-${glog_RELEASE}
SVN_REPOSITORY http://google-glog.googlecode.com/svn/trunk SVN_REPOSITORY http://google-glog.googlecode.com/svn/trunk
SVN_REVISION -r "142" SVN_REVISION -r "142"
@ -560,7 +556,7 @@ export LIBS=${GFlags_SHARED_LIBS}
else("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") else("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
ExternalProject_Add( ExternalProject_Add(
glog-${glog_RELEASE} glog-${glog_RELEASE}
DEPENDS gflags-${gflags_RELEASE} DEPENDS ${TARGET_GFLAGS}
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/glog-${glog_RELEASE} PREFIX ${CMAKE_CURRENT_BINARY_DIR}/glog-${glog_RELEASE}
URL http://google-glog.googlecode.com/files/glog-${glog_RELEASE}.tar.gz URL http://google-glog.googlecode.com/files/glog-${glog_RELEASE}.tar.gz
DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR}/download/glog-${glog_RELEASE} DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR}/download/glog-${glog_RELEASE}
@ -583,10 +579,10 @@ export LIBS=${GFlags_SHARED_LIBS}
${CMAKE_CURRENT_BINARY_DIR}/glog-${glog_RELEASE}/.libs/${CMAKE_FIND_LIBRARY_PREFIXES}glog.a ${CMAKE_CURRENT_BINARY_DIR}/glog-${glog_RELEASE}/.libs/${CMAKE_FIND_LIBRARY_PREFIXES}glog.a
) )
set(LOCAL_GLOG true CACHE STRING "Glog downloaded and built automatically" FORCE) set(LOCAL_GLOG true CACHE STRING "Glog downloaded and built automatically" FORCE)
else(NOT GLOG_FOUND OR LOCAL_GFLAGS) else(NOT GLOG_FOUND OR ${LOCAL_GFLAGS})
add_library(glog-${glog_RELEASE} UNKNOWN IMPORTED) add_library(glog-${glog_RELEASE} UNKNOWN IMPORTED)
set_property(TARGET glog-${glog_RELEASE} PROPERTY IMPORTED_LOCATION "${GLOG_LIBRARIES}") set_property(TARGET glog-${glog_RELEASE} PROPERTY IMPORTED_LOCATION "${GLOG_LIBRARIES}")
endif(NOT GLOG_FOUND OR LOCAL_GFLAGS) endif(NOT GLOG_FOUND OR ${LOCAL_GFLAGS})
@ -1044,4 +1040,8 @@ add_custom_target(uninstall
######################################################################## ########################################################################
add_subdirectory(src) add_subdirectory(src)
include(GnssSdrPackaging) if(${ENABLE_PACKAGING})
include(GnssSdrPackaging)
endif(${ENABLE_PACKAGING})

View File

@ -8,8 +8,17 @@
# GFlags_INCLUDE_DIRS # GFlags_INCLUDE_DIRS
# GFlags_LIBS # GFlags_LIBS
# GFlags_LIBRARY_DIRS # GFlags_LIBRARY_DIRS
# - Try to find GFlags
#
#
# The following are set after configuration is done:
# GFlags_FOUND
# GFlags_INCLUDE_DIRS
# GFlags_LIBS
# GFlags_LIBRARY_DIRS
cmake_minimum_required(VERSION 2.6) cmake_minimum_required(VERSION 2.6)
cmake_policy(SET CMP0011 OLD) #cmake_policy(SET CMP0011 OLD)
set(GFlags_ROOT_DIR) set(GFlags_ROOT_DIR)
if (WIN32) if (WIN32)
@ -17,14 +26,15 @@ if (WIN32)
src/gflags.cc src/gflags.cc
HINTS HINTS
$ENV{GFLAGS_ROOT}) $ENV{GFLAGS_ROOT})
else (WIN32) endif (WIN32)
if (APPLE)
FIND_PATH(GFlags_ROOT_DIR FIND_PATH(GFlags_ROOT_DIR
libgflags.dylib libgflags.dylib
HINTS HINTS
/opt/local/lib /opt/local/lib
/usr/local/lib /usr/local/lib
) )
endif (WIN32) endif (APPLE)
if (UNIX) if (UNIX)
FIND_PATH(GFlags_ROOT_DIR FIND_PATH(GFlags_ROOT_DIR
@ -91,6 +101,7 @@ IF(GFlags_ROOT_DIR)
ELSE(GFlags_ROOT_DIR) ELSE(GFlags_ROOT_DIR)
FIND_PATH(GFlags_ROOT_DIR src) FIND_PATH(GFlags_ROOT_DIR src)
MARK_AS_ADVANCED(GFlags_ROOT_DIR) MARK_AS_ADVANCED(GFlags_ROOT_DIR)
MESSAGE(STATUS "Cannot find Root directory of gflags") MESSAGE(STATUS "Cannot find gflags")
SET(GFlags_FOUND false) SET(GFlags_FOUND false)
ENDIF(GFlags_ROOT_DIR) ENDIF(GFlags_ROOT_DIR)

View File

@ -27,17 +27,25 @@ set( __INCLUDED_GNSS_SDR_PACKAGE_CMAKE TRUE)
if(CPACK_GENERATOR) if(CPACK_GENERATOR)
#already set by user #already set by user
elseif(APPLE) elseif(APPLE)
set(CPACK_GENERATOR PackageMaker) set(PACKAGE_GENERATOR "TGZ")
elseif(WIN32) set(PACKAGE_SOURCE_GENERATOR "TGZ;ZIP")
set(CPACK_GENERATOR NSIS) elseif(UNIX)
elseif(DEBIAN) if(${LINUX_DISTRIBUTION} MATCHES "Debian" OR ${LINUX_DISTRIBUTION} MATCHES "Ubuntu")
set(CPACK_GENERATOR DEB) set (PACKAGE_GENERATOR "DEB")
elseif(REDHAT) endif(${LINUX_DISTRIBUTION} MATCHES "Debian" OR ${LINUX_DISTRIBUTION} MATCHES "Ubuntu")
set(CPACK_GENERATOR RPM) if(${LINUX_DISTRIBUTION} MATCHES "Red Hat" OR
${LINUX_DISTRIBUTION} MATCHES "Fedora")
set (PACKAGE_GENERATOR "DEB")
endif(${LINUX_DISTRIBUTION} MATCHES "Red Hat" OR ${LINUX_DISTRIBUTION} MATCHES "Fedora")
set (PACKAGE_SOURCE_GENERATOR "TGZ;ZIP")
else() else()
set(CPACK_GENERATOR TGZ) set(PACKAGE_GENERATOR "TGZ")
set(PACKAGE_SOURCE_GENERATOR "TGZ")
endif() endif()
# used package generators
set (CPACK_GENERATOR "${PACKAGE_GENERATOR}" CACHE STRING "List of binary package generators (CPack).")
set (CPACK_SOURCE_GENERATOR "${PACKAGE_SOURCE_GENERATOR}" CACHE STRING "List of source package generators (CPack).")
######################################################################## ########################################################################
@ -45,6 +53,8 @@ endif()
######################################################################## ########################################################################
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "GNSS-SDR - An Open Source GNSS Software Defined Receiver") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "GNSS-SDR - An Open Source GNSS Software Defined Receiver")
set(CPACK_PACKAGE_VENDOR "Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)") set(CPACK_PACKAGE_VENDOR "Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)")
set(CPACK_PACKAGE_NAME "gnss-sdr")
set(CPACK_PACKAGE_VERSION "${VERSION}")
set(CPACK_PACKAGE_CONTACT "Carles Fernandez-Prades <carles.fernandez@cttc.cat>") set(CPACK_PACKAGE_CONTACT "Carles Fernandez-Prades <carles.fernandez@cttc.cat>")
set(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/docs/doxygen/images/gnss-sdr_logo_round.png") set(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/docs/doxygen/images/gnss-sdr_logo_round.png")
set(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_INFO_MAJOR_VERSION}") set(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_INFO_MAJOR_VERSION}")
@ -53,7 +63,8 @@ set(CPACK_PACKAGE_VERSION_PATCH "${VERSION_INFO_MINOR_VERSION}")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING") set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md") set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_SOURCE_DIR}/README.md") set(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_SOURCE_DIR}/README.md")
set(CPACK_SOURCE_GENERATOR "TGZ;TZ")
# Debian-specific settings
set(CPACK_DEBIAN_PACKAGE_SECTION "Science") set(CPACK_DEBIAN_PACKAGE_SECTION "Science")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libboost-dev (>= 1.45), set(CPACK_DEBIAN_PACKAGE_DEPENDS "libboost-dev (>= 1.45),
libstdc++6 (>= 4.7), libstdc++6 (>= 4.7),
@ -66,29 +77,169 @@ set(CPACK_DEBIAN_PACKAGE_DEPENDS "libboost-dev (>= 1.45),
libssl-dev (>= 1.0), libssl-dev (>= 1.0),
libgflags-dev (>= 2.0) ") libgflags-dev (>= 2.0) ")
#find_program(LSB_RELEASE_EXECUTABLE lsb_release)
#if((DEBIAN OR REDHAT) AND LSB_RELEASE_EXECUTABLE) # system/architecture
#extract system information by executing the commands if (APPLE)
# execute_process( set (CPACK_PACKAGE_ARCHITECTURE darwin)
# COMMAND ${LSB_RELEASE_EXECUTABLE} --short --id else(APPLE)
# OUTPUT_VARIABLE LSB_ID OUTPUT_STRIP_TRAILING_WHITESPACE string (TOLOWER "${CMAKE_SYSTEM_NAME}" CPACK_SYSTEM_NAME)
# ) if(CMAKE_CXX_FLAGS MATCHES "-m32")
set (CPACK_PACKAGE_ARCHITECTURE i386)
else(CMAKE_CXX_FLAGS MATCHES "-m32")
execute_process (
COMMAND dpkg --print-architecture
RESULT_VARIABLE RV
OUTPUT_VARIABLE CPACK_PACKAGE_ARCHITECTURE
)
if(RV EQUAL 0)
string (STRIP "${CPACK_PACKAGE_ARCHITECTURE}" CPACK_PACKAGE_ARCHITECTURE)
else(RV EQUAL 0)
execute_process (COMMAND uname -m OUTPUT_VARIABLE CPACK_PACKAGE_ARCHITECTURE)
if(CPACK_PACKAGE_ARCHITECTURE MATCHES "x86_64")
set (CPACK_PACKAGE_ARCHITECTURE amd64)
endif(CPACK_PACKAGE_ARCHITECTURE MATCHES "x86_64")
if(CPACK_PACKAGE_ARCHITECTURE MATCHES "i386")
set (CPACK_PACKAGE_ARCHITECTURE i386)
endif(CPACK_PACKAGE_ARCHITECTURE MATCHES "i386")
endif(RV EQUAL 0)
endif(CMAKE_CXX_FLAGS MATCHES "-m32")
endif(APPLE)
# execute_process(
# COMMAND ${LSB_RELEASE_EXECUTABLE} --short --release
# OUTPUT_VARIABLE LSB_RELEASE OUTPUT_STRIP_TRAILING_WHITESPACE
# )
#set a more sensible package name for this system if(NOT CPACK_PACKAGE_ARCHITECTURE)
# SET(CPACK_PACKAGE_FILE_NAME "gnss-sdr_${CPACK_PACKAGE_VERSION}_${LSB_ID}-${LSB_RELEASE}-${CMAKE_SYSTEM_PROCESSOR}") # Code from https://qt.gitorious.org/qt/qtbase/source/src/corelib/global/qprocessordetection.h
set(archdetect_c_code "
#if defined(__arm__) || defined(__TARGET_ARCH_ARM) || defined(_M_ARM) || defined(__arm64__)
#if defined(__arm64__)
#error cmake_ARCH arm64
#endif
#now try to include the component based dependencies #if defined(__arm__) || defined(__TARGET_ARCH_ARM)
# set(package_deps_file "${CMAKE_SOURCE_DIR}/cmake/Packaging/${LSB_ID}-${LSB_RELEASE}.cmake") #if defined(__ARM_ARCH_8__) \\
# if (EXISTS ${package_deps_file}) || defined(__ARM_ARCH_8A__) \\
# include(${package_deps_file}) || defined(__ARM_ARCH_8R__) \\
# endif() || (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 8)
#endif() #error cmake_ARCH armv8
#elif defined(__ARM_ARCH_7__) \\
|| defined(__ARM_ARCH_7A__) \\
|| defined(__ARM_ARCH_7R__) \\
|| defined(__ARM_ARCH_7M__) \\
|| (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 7)
#error cmake_ARCH armv7
#elif defined(__ARM_ARCH_6__) \\
|| defined(__ARM_ARCH_6J__) \\
|| defined(__ARM_ARCH_6T2__) \\
|| defined(__ARM_ARCH_6Z__) \\
|| defined(__ARM_ARCH_6K__) \\
|| defined(__ARM_ARCH_6ZK__) \\
|| defined(__ARM_ARCH_6M__) \\
|| (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 6)
#error cmake_ARCH armv6
#elif defined(__ARM_ARCH_5TEJ__) \\
|| (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 5)
#error cmake_ARCH armv5
#else
#error cmake_ARCH arm
#endif
#elif defined(__i386) || defined(__i386__) || defined(_M_IX86)
#error cmake_ARCH i386
#elif defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64)
#error cmake_ARCH x86_64
#elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
#error cmake_ARCH ia64
#elif defined(__ppc__) || defined(__ppc) || defined(__powerpc__) \\
|| defined(_ARCH_COM) || defined(_ARCH_PWR) || defined(_ARCH_PPC) \\
|| defined(_M_MPPC) || defined(_M_PPC)
#if defined(__ppc64__) || defined(__powerpc64__) || defined(__64BIT__)
#error cmake_ARCH ppc64
#else
#error cmake_ARCH ppc
#endif
#endif
#error cmake_ARCH unknown
")
function(target_architecture output_var)
if(APPLE AND CMAKE_OSX_ARCHITECTURES)
# On OS X we use CMAKE_OSX_ARCHITECTURES *if* it was set
# On OS X 10.6+ the default is x86_64 if the CPU supports it, i386 otherwise.
foreach(osx_arch ${CMAKE_OSX_ARCHITECTURES})
if("${osx_arch}" STREQUAL "i386")
set(osx_arch_i386 TRUE)
elseif("${osx_arch}" STREQUAL "x86_64")
set(osx_arch_x86_64 TRUE)
else()
message(FATAL_ERROR "Invalid OS X arch name: ${osx_arch}")
endif()
endforeach()
# Now add all the architectures in our normalized order
if(osx_arch_i386)
list(APPEND ARCH i386)
endif()
if(osx_arch_x86_64)
list(APPEND ARCH x86_64)
endif()
else()
file(WRITE "${CMAKE_BINARY_DIR}/arch.c" "${archdetect_c_code}")
enable_language(C)
# Detect the architecture in a rather creative way...
# This compiles a small C program which is a series of ifdefs that selects a
# particular #error preprocessor directive whose message string contains the
# target architecture. The program will always fail to compile (both because
# file is not a valid C program, and obviously because of the presence of the
# #error preprocessor directives... but by exploiting the preprocessor in this
# way, we can detect the correct target architecture even when cross-compiling,
# since the program itself never needs to be run (only the compiler/preprocessor)
try_run(
run_result_unused
compile_result_unused
"${CMAKE_BINARY_DIR}"
"${CMAKE_BINARY_DIR}/arch.c"
COMPILE_OUTPUT_VARIABLE ARCH
CMAKE_FLAGS CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
)
# Parse the architecture name from the compiler output
string(REGEX MATCH "cmake_ARCH ([a-zA-Z0-9_]+)" ARCH "${ARCH}")
# Get rid of the value marker leaving just the architecture name
string(REPLACE "cmake_ARCH " "" ARCH "${ARCH}")
# If we are compiling with an unknown architecture this variable should
# already be set to "unknown" but in the case that it's empty (i.e. due
# to a typo in the code), then set it to unknown
if (NOT ARCH)
set(ARCH unknown)
endif()
endif()
set(${output_var} "${ARCH}" PARENT_SCOPE)
endfunction()
# Set target architectures
target_architecture(CMAKE_TARGET_ARCHITECTURES)
endif(NOT CPACK_PACKAGE_ARCHITECTURE)
if(APPLE)
list(LENGTH CMAKE_TARGET_ARCHITECTURES cmake_target_arch_len)
if(NOT "${cmake_target_arch_len}" STREQUAL "1")
set(CMAKE_TARGET_ARCHITECTURE_UNIVERSAL TRUE)
set(CMAKE_TARGET_ARCHITECTURE_CODE "universal")
else()
set(CMAKE_TARGET_ARCHITECTURE_UNIVERSAL FALSE)
set(CMAKE_TARGET_ARCHITECTURE_CODE "${CMAKE_TARGET_ARCHITECTURES}")
endif()
endif(APPLE)
# source package settings
#set (CPACK_SOURCE_TOPLEVEL_TAG "source")
set (CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
set (CPACK_SOURCE_IGNORE_FILES "/\\\\.git/;\\\\.swp$;\\\\.#;/#;\\\\.*~;cscope\\\\.*;/[Bb]uild[.+-_a-zA-Z0-9]*/")
# default binary package settings
set (CPACK_INCLUDE_TOPLEVEL_DIRECTORY TRUE)
set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}")
if (CPACK_PACKAGE_ARCHITECTURE)
set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}_${CPACK_PACKAGE_ARCHITECTURE}")
endif ()
include(CPack) include(CPack)