Merge pull request #334 from rolk/334_macver

Support configuration on MacOS X using Apple toolchain
This commit is contained in:
Bård Skaflestad
2013-08-26 06:05:38 -07:00
8 changed files with 110 additions and 42 deletions

View File

@@ -43,6 +43,26 @@ else()
endif(CXX_FLAG_CXX0X)
endif(CXX_FLAG_CXX11)
# if we are building with an Apple toolchain in MacOS X,
# we cannot use the old GCC 4.2 fork, but must use the
# new runtime library
set (CXX_STDLIB_FLAGS)
string (TOUPPER "${CMAKE_CXX_COMPILER_ID}" _comp_id)
if (APPLE AND (_comp_id MATCHES "CLANG"))
CHECK_CXX_ACCEPTS_FLAG ("-stdlib=libc++" CXX_FLAG_STDLIB_LIBCXX)
if (CXX_FLAG_STDLIB_LIBCXX)
add_options (CXX ALL_BUILDS "-stdlib=libc++")
set (CXX_STDLIB_FLAGS "-stdlib=libc++")
endif (CXX_FLAG_STDLIB_LIBCXX)
endif (APPLE AND (_comp_id MATCHES "CLANG"))
# to format the command-line options pretty, we have an optional space
if (CXX_STD0X_FLAGS AND CXX_STDLIB_FLAGS)
set (CXX_SPACE " ")
else (CXX_STD0X_FLAGS AND CXX_STDLIB_FLAGS)
set (CXX_SPACE)
endif (CXX_STD0X_FLAGS AND CXX_STDLIB_FLAGS)
# perform tests
include(CheckCXXSourceCompiles)

View File

@@ -265,12 +265,6 @@ if (SuiteSparse_LIBRARIES)
list (REVERSE SuiteSparse_LIBRARIES)
endif (SuiteSparse_LIBRARIES)
# on MacOS X the libraries are in a framework directory and an option must be
# added on the compile line to relate headers to that directory
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
list (APPEND SuiteSparse_DEFINITIONS "-framework Accelerate")
endif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# print a message to indicate status of this package
include (FindPackageHandleStandardArgs)
find_package_handle_standard_args (SuiteSparse

View File

@@ -35,19 +35,19 @@ macro (opm_install opm)
option (SYSTEM_DEBUG "Put .debug files in GDB debug file directory" ${_sys_dbg_def})
set (DEBUG_FILE_DIRECTORY /usr/lib/debug CACHE LOCATION "GDB debug file directory")
mark_as_advanced (DEBUG_FILE_DIRECTORY)
if (SYSTEM_DEBUG)
if (SYSTEM_DEBUG AND NOT APPLE)
set (_dbg_prefix "${DEBUG_FILE_DIRECTORY}/")
else (SYSTEM_DEBUG)
else (SYSTEM_DEBUG AND NOT APPLE)
set (_dbg_prefix "")
endif (SYSTEM_DEBUG)
endif (SYSTEM_DEBUG AND NOT APPLE)
# static libraries don't have their debug info stripped, so there is
# only a separate file when we are building shared objects
if (${opm}_LIBRARY_TYPE STREQUAL "SHARED" AND ${opm}_TARGET)
if (${opm}_LIBRARY_TYPE STREQUAL "SHARED" AND ${opm}_TARGET AND ${opm}_DEBUG)
install (
FILES ${PROJECT_BINARY_DIR}/${${opm}_DEBUG}
DESTINATION ${_dbg_prefix}${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}
)
endif (${opm}_LIBRARY_TYPE STREQUAL "SHARED" AND ${opm}_TARGET)
endif (${opm}_LIBRARY_TYPE STREQUAL "SHARED" AND ${opm}_TARGET AND ${opm}_DEBUG)
install (
FILES ${PROJECT_SOURCE_DIR}/dune.module
DESTINATION ${CMAKE_INSTALL_LIBDIR_NOARCH}/dunecontrol/${${opm}_NAME}

View File

@@ -29,10 +29,20 @@ if (CXX_COMPAT_GCC)
# extracting the debug info is done by a separate utility in the GNU
# toolchain. check that this is actually installed.
message (STATUS "Looking for strip utility")
find_program (OBJCOPY
objcopy
${CYGWIN_INSTALL_PATH}/bin /usr/bin /usr/local/bin
)
if (APPLE)
# MacOS X has a duo of utilities; we need both
find_program (OBJCOPY strip)
find_program (DSYMUTIL dsymutil)
mark_as_advanced (DSYMUTIL)
if (NOT DSYMUTIL)
set (OBJCOPY dsymutil-NOTFOUND)
endif (NOT DSYMUTIL)
else (APPLE)
find_program (OBJCOPY
objcopy
${CYGWIN_INSTALL_PATH}/bin /usr/bin /usr/local/bin
)
endif (APPLE)
mark_as_advanced (OBJCOPY)
if (OBJCOPY)
message (STATUS "Looking for strip utility - found")
@@ -71,28 +81,48 @@ function (strip_debug_symbols targets)
# again)
get_target_property (_full ${target} LOCATION)
get_filename_component (_dir ${_full} PATH)
get_filename_component (_name ${_full} NAME)
if (NOT (("${_dir}" STREQUAL "") OR ("${_dir}" MATCHES ".*/$")))
set (_dir "${_dir}/")
endif (NOT (("${_dir}" STREQUAL "") OR ("${_dir}" MATCHES ".*/$")))
get_filename_component (_name ${_full} NAME_WE)
get_filename_component (_ext ${_full} EXT)
# only libraries have soversion property attached
get_target_property (_target_soversion ${target} SOVERSION)
get_target_property (_target_version ${target} VERSION)
if (_target_soversion)
set (_target_file "${_full}.${_target_version}")
set (_target_file_name "${_name}.${_target_version}")
# MacOS X puts the version number before the extension
if (APPLE)
set (_target_file_name "${_name}.${_target_version}${_ext}")
else (APPLE)
set (_target_file_name "${_name}${_ext}.${_target_version}")
endif (APPLE)
else (_target_soversion)
set (_target_file "${_full}")
set (_target_file_name "${_name}")
set (_target_file_name "${_name}${_ext}")
endif (_target_soversion)
set (_target_file "${_dir}${_target_file_name}")
# do without generator expressions (which doesn't work everywhere)
add_custom_command (TARGET ${target}
POST_BUILD
WORKING_DIRECTORY ${_dir}
COMMAND ${OBJCOPY} ARGS --only-keep-debug ${_target_file} ${_target_file}.debug
COMMAND ${OBJCOPY} ARGS ${_strip_args} ${_target_file}
COMMAND ${OBJCOPY} ARGS --add-gnu-debuglink=${_target_file_name}.debug ${_target_file}
VERBATIM
)
if (APPLE)
set (_debug_ext ".dSYM")
add_custom_command (TARGET ${target}
POST_BUILD
WORKING_DIRECTORY ${_dir}
COMMAND ${DSYMUTIL} ARGS --flat --out=${_target_file}${_debug_ext} ${_target_file}
COMMAND ${OBJCOPY} ARGS -S ${_target_file}
VERBATIM
)
else (APPLE)
set (_debug_ext ".debug")
add_custom_command (TARGET ${target}
POST_BUILD
WORKING_DIRECTORY ${_dir}
COMMAND ${OBJCOPY} ARGS --only-keep-debug ${_target_file} ${_target_file}${_debug_ext}
COMMAND ${OBJCOPY} ARGS ${_strip_args} ${_target_file}
COMMAND ${OBJCOPY} ARGS --add-gnu-debuglink=${_target_file_name}${_debug_ext} ${_target_file}
VERBATIM
)
endif (APPLE)
# add this .debug file to the list
file (RELATIVE_PATH _this_debug_file "${PROJECT_BINARY_DIR}" "${_target_file}.debug")
file (RELATIVE_PATH _this_debug_file "${PROJECT_BINARY_DIR}" "${_target_file}${_debug_ext}")
set (_debug_files ${_debug_files} ${_this_debug_file})
endforeach (target)
# if optional debug list was requested, then copy to output parameter

View File

@@ -5,6 +5,9 @@ function (system_info)
if (CMAKE_SYSTEM MATCHES "Linux")
distro_name (DISTRO_NAME)
message (STATUS "Linux distribution: ${DISTRO_NAME}")
elseif (CMAKE_SYSTEM MATCHES "Darwin")
sw_vers (OS_VERSION)
message (STATUS "${OS_VERSION}")
else (CMAKE_SYSTEM MATCHES "Linux")
message (STATUS "Operating system: ${CMAKE_SYSTEM}")
endif (CMAKE_SYSTEM MATCHES "Linux")
@@ -13,6 +16,24 @@ function (system_info)
message (STATUS "Target architecture: ${TARGET_CPU}")
endfunction (system_info)
function (sw_vers varname)
# query operating system for information
exec_program (sw_vers OUTPUT_VARIABLE _vers)
# split multi-line into various fields
string (REPLACE "\n" ";" _vers "${_vers}")
string (REPLACE ":" ";" _vers "${_vers}")
# get the various fields
list (GET _vers 1 _prod_name)
list (GET _vers 3 _prod_vers)
list (GET _vers 5 _prod_build)
# remove extraneous whitespace
string (STRIP "${_prod_name}" _prod_name)
string (STRIP "${_prod_vers}" _prod_vers)
string (STRIP "${_prod_build}" _prod_build)
# assemble result variable
set (${varname} "${_prod_name} version: ${_prod_vers} (${_prod_build})" PARENT_SCOPE)
endfunction (sw_vers varname)
# probe various system files that may be found
function (distro_name varname)
file (GLOB has_os_release /etc/os-release)

View File

@@ -139,6 +139,11 @@ if [ "${CMAKE_COMMAND}" = "" ]; then
fi
fi
# helper routine
uppercase () {
echo "$@" | tr [a-z-] [A-Z_]
}
for OPT in "$@"; do
case "$OPT" in
--*)
@@ -207,7 +212,7 @@ for OPT in "$@"; do
dune |\
dune-* |\
zlib)
rootvar="${pkgname^^}_ROOT"
rootvar="$(uppercase ${pkgname})_ROOT"
rootvar="${rootvar/-/_}"
;;
*)
@@ -225,15 +230,6 @@ for OPT in "$@"; do
pkgname=$OPTARG
pkgname=${pkgname#disable-}
pkgname=${pkgname#without-}
# special aliases
case "${pkgname}" in
umfpack)
pkgname="SuiteSparse"
;;
tinyxml)
pkgname="TinyXML"
;;
esac
# casing is of course different
case "${pkgname}" in
option-checking)
@@ -291,7 +287,7 @@ for OPT in "$@"; do
;;
ert |\
superlu)
pkgname="${pkgname^^}"
pkgname="$(uppercase ${pkgname})"
;;
openmp)
pkgname="OpenMP"
@@ -299,6 +295,12 @@ for OPT in "$@"; do
gxx11check)
pkgname="CXX11Features"
;;
umfpack)
pkgname="SuiteSparse"
;;
tinyxml)
pkgname="TinyXML"
;;
*)
invalid_opt --disable-${pkgname}
pkgname=""

View File

@@ -42,8 +42,9 @@ endif (NOT "@opm-project_TARGET@" STREQUAL "")
# ensure that we build with support for C++11 to preserve ABI
string (REPLACE "@CXX_STD0X_FLAGS@" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string (REPLACE "@CXX_STDLIB_FLAGS@" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string (STRIP "${CMAKE_CXX_FLAGS}" CMAKE_CXX_FLAGS)
set (CMAKE_CXX_FLAGS "@CXX_STD0X_FLAGS@ ${CMAKE_CXX_FLAGS}")
set (CMAKE_CXX_FLAGS "@CXX_STD0X_FLAGS@@CXX_SPACE@@CXX_STDLIB_FLAGS@ ${CMAKE_CXX_FLAGS}")
# same as above, but for C99
string (REPLACE "@C_STD99_FLAGS@" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")

View File

@@ -1,7 +1,7 @@
prefix=@prefix@
libdir=@libdir@
includedir=@includedir@
CXX=@CMAKE_CXX_COMPILER@ @CXX_STD0X_FLAGS@ @OpenMP_CXX_FLAGS@
CXX=@CMAKE_CXX_COMPILER@ @CXX_STD0X_FLAGS@@CXX_SPACE@@CXX_STDLIB_FLAGS@ @OpenMP_CXX_FLAGS@
CC=@CMAKE_C_COMPILER@ @C_STD99_FLAGS@ @OpenMP_C_FLAGS@
DEPENDENCIES=