Revision 3df61d16c51c6cbbe49ca3faabd2215e6061887f authored by Alexander Kruppa on 20 February 2014, 16:47:44 UTC, committed by Alexander Kruppa on 20 February 2014, 16:47:44 UTC
1 parent 744a265
Raw File
CMakeLists.txt

project(CADO_NFS)

set(CADO_VERSION_MAJOR  2)
set(CADO_VERSION_MINOR  0)
set(CADO_VERSION_STRING  "${CADO_VERSION_MAJOR}.${CADO_VERSION_MINOR}")

# CADO_DIST_ARCHIVE_NAME may be overridden by environment.
set(CADO_DIST_ARCHIVE_NAME "cado-nfs-${CADO_VERSION_STRING}")

#####################################################################
# cmake version -- set_property requires 2.6. Note that haters of progress
# report things (this include me, casually) have to wait for cmake 2.7, since
# it has only recently become possible to (only partially) disable them:
# http://public.kitware.com/Bug/view.php?id=8726
# set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
# set(CMAKE_COLOR_MAKEFILE OFF)

# Unfortunately cmake 2.6.0 at least seems to have some bugs with the
# find_program command, which prevent mpi from being properly detected.
# version 2.6.3 is known to work
cmake_minimum_required(VERSION 2.6.3)
if(COMMAND cmake_policy)
        cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)

#####################################################################
# What are we building ?

execute_process(COMMAND scripts/version.sh
        WORKING_DIRECTORY ${CADO_NFS_SOURCE_DIR}
        OUTPUT_STRIP_TRAILING_WHITESPACE
        OUTPUT_VARIABLE CADO_REV)
message(STATUS "Configuring CADO revision ${CADO_REV}")

#####################################################################
# Allow building unit test programs with "make test"
enable_testing()
# Also allow testing with "make check", but building all required
# dependencies (las for the sieve test, etc.) as well. We also add the
# "verbose" command line option here to get more meaningful output
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} -V $(ARGS))

#####################################################################
# Get some overrides from the environment.

macro(get_override extname intname)
string(COMPARE NOTEQUAL "$ENV{${extname}}" "" HAS_${intname}_OVERRIDE)
if(HAS_${intname}_OVERRIDE)
    set(${intname} "$ENV{${extname}}")
    message(STATUS "${extname}=${${intname}}")
endif(HAS_${intname}_OVERRIDE)
endmacro(get_override varname)

# Syntax is (user-friendly name) (cmake name)
# Make sure everything is exported from scripts/call_cmake.sh
get_override(PREFIX               CMAKE_INSTALL_PREFIX)
get_override(CFLAGS               CMAKE_C_FLAGS)
get_override(CXXFLAGS             CMAKE_CXX_FLAGS)
get_override(CC                   CMAKE_C_COMPILER)
get_override(CXX                  CMAKE_CXX_COMPILER)
get_override(CADO_DIST_ARCHIVE_NAME         CADO_DIST_ARCHIVE_NAME)
get_override(MPI                  MPI)
get_override(LDFLAGS              CMAKE_EXE_LINKER_FLAGS)
get_override(LDFLAGS              CMAKE_SHARED_LINKER_FLAGS)
get_override(FLAGS_SIZE           CMAKE_FLAGS_SIZE)

if(EXISTS ${CADO_NFS_SOURCE_DIR}/files.dist)
    set(EXCLUDE_FROM_RELEASE_BUILD )
else(EXISTS ${CADO_NFS_SOURCE_DIR}/files.dist)
    set(EXCLUDE_FROM_RELEASE_BUILD EXCLUDE_FROM_ALL)
endif(EXISTS ${CADO_NFS_SOURCE_DIR}/files.dist)

#####################################################################
# Add the CFLAGS that are needed in all cases.
# Append them at the *end* of the parameter list so as to allow tweaking
# of e.g. warnings by the user-defined overrides.
set (CMAKE_C_FLAGS      "${CMAKE_C_FLAGS} ${CMAKE_FLAGS_SIZE}")
set (CMAKE_CXX_FLAGS    "${CMAKE_CXX_FLAGS} ${CMAKE_FLAGS_SIZE}")

if(CMAKE_COMPILER_IS_GNUCC)
    # gcc defines __STRICT_ANSI__ with -std=c99, which under MinGW
    # causes many prototypes and macros not to be defined. Using gnu99
    # prevents the definition of __STRICT_ANSI__
    #
    # Ditto for C++, with the c++98/gnu++98 subtlety.
    if (MINGW)
        set (CMAKE_C_FLAGS   "-std=gnu99 -g -W -Wall ${CMAKE_C_FLAGS}")
        set (CMAKE_CXX_FLAGS "-std=gnu++98 -g -W -Wall ${CMAKE_CXX_FLAGS}")
    else (MINGW)
        set (CMAKE_C_FLAGS   "-std=c99 -g -W -Wall ${CMAKE_C_FLAGS}")
        set (CMAKE_CXX_FLAGS "-std=c++98 -g -W -Wall ${CMAKE_CXX_FLAGS}")
    endif (MINGW)
endif(CMAKE_COMPILER_IS_GNUCC)

#####################################################################
# Set dependencies for external software.

set(some_mpir_variable "$ENV{MPIR}$ENV{MPIR_INCDIR}$ENV{MPIR_LIBDIR}")
if(some_mpir_variable)
# locates gmp. Obeys the env variables GMP GMP_LIBDIR GMP_INCDIR
include(${CADO_NFS_SOURCE_DIR}/config/mpir.cmake)
set(GF2X_C_FLAGS "${CMAKE_C_FLAGS} -I${MPIR_INCDIR} -I${CADO_NFS_SOURCE_DIR}")
set(GF2X_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I${MPIR_INCDIR} -I${CADO_NFS_SOURCE_DIR}")
else(some_mpir_variable)
# locates gmp. Obeys the env variables GMP GMP_LIBDIR GMP_INCDIR
include(${CADO_NFS_SOURCE_DIR}/config/gmp.cmake)
set(GF2X_C_FLAGS "${CMAKE_C_FLAGS} -I${GMP_INCDIR} -I${CADO_NFS_SOURCE_DIR}")
set(GF2X_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I${GMP_INCDIR} -I${CADO_NFS_SOURCE_DIR}")
endif(some_mpir_variable)

#####

set(GF2X_CONFIGURE_FLAGS --disable-shared --disable-dependency-tracking CFLAGS=${GF2X_C_FLAGS} CXXFLAGS=${GF2X_CXX_FLAGS} $ENV{GF2X_CONFIGURE_EXTRA_FLAGS})
get_override(GF2X_CONFIGURE_FLAGS GF2X_CONFIGURE_FLAGS)

#####################################################################
# Obtain information from the host.

include("${CADO_NFS_SOURCE_DIR}/config/sse2.cmake")
include("${CADO_NFS_SOURCE_DIR}/config/sse3.cmake")
include("${CADO_NFS_SOURCE_DIR}/config/ssse3.cmake")
include("${CADO_NFS_SOURCE_DIR}/config/sse41.cmake")
include("${CADO_NFS_SOURCE_DIR}/config/gcc-inline-assembly.cmake")
include("${CADO_NFS_SOURCE_DIR}/config/gcc-bugs.cmake")
include("${CADO_NFS_SOURCE_DIR}/config/gas-assembly.cmake")
include("${CADO_NFS_SOURCE_DIR}/config/curl.cmake")
include("${CADO_NFS_SOURCE_DIR}/config/alloca.cmake")
include("${CADO_NFS_SOURCE_DIR}/config/math.cmake")
include("${CADO_NFS_SOURCE_DIR}/config/posix.cmake")
include("${CADO_NFS_SOURCE_DIR}/config/rusage_thread.cmake")
include("${CADO_NFS_SOURCE_DIR}/config/sync_fetch.cmake")
include("${CADO_NFS_SOURCE_DIR}/config/asprintf.cmake")
include("${CADO_NFS_SOURCE_DIR}/config/mingw.cmake")
include("${CADO_NFS_SOURCE_DIR}/config/test-rand.cmake")
include("${CADO_NFS_SOURCE_DIR}/config/odd_address_io_int.cmake")
include("${CADO_NFS_SOURCE_DIR}/config/strlcpy.cmake")
include("${CADO_NFS_SOURCE_DIR}/config/linux.cmake")
IF (NOT DEFINED ENV{NO_PYTHON_CHECK})
  include("${CADO_NFS_SOURCE_DIR}/config/python.cmake")
endif()

string(COMPARE NOTEQUAL "$ENV{ENABLE_SHARED}" "" ENABLE_SHARED)

unset(BUILD_DYNAMICALLY_LINKABLE_BWC)
set(CADO_SHARED)

if(ENABLE_SHARED)
    if(MINGW)
        message(FATAL_ERROR "ENABLE_SHARED is not supported with MINGW")
    endif(MINGW)
    # Dynamically linkable bwc needs shared libs.
    set(BUILD_DYNAMICALLY_LINKABLE_BWC 1)
    # having both shared and static is possible but messy. One needs two
    # add_library calls, and then I'm not sure whether
    # target_link_libraries picks the static or shared ones...
    set(CADO_SHARED SHARED)
    message(STATUS "Building with dynamic libraries (ENABLE_SHARED)")
else(ENABLE_SHARED)
    message(STATUS "Building with static libraries")
endif(ENABLE_SHARED)




######################################################################
# Try to detect whether pthreads and/or MPI are available.
# This checks the MPI and PTHREADS environment variables.
# As a result:
# - If pthreads are available:
#   * WITH_PTHREADS is defined to 1 as a cmake variable.
#   * -DWITH_PTHREADS is added for the compilation of every file (because
#     it can't hurt).
#   In fact, in recent versions, pthread support is mandatory. Still,
#   this piece of cmake checks the avaibility of the function
#   pthread_barrier_wait, which is optional.
# - If mpi is available:
#   * WITH_MPI is defined to 1 as a cmake variable.
#   * _NOTHING_ from the build environment is changed by default, because
#     we do not want everything to be compiled with mpicc. Thus, relevant
#     code parts should check for WITH_MPI in the CMakeLists.txt file,
#     and, if relevant, use the MPI_C_COMPILER, MPI_CXX_COMPILER, MPIEXEC
#     variables (which are guaranteed to be defined).
#   * The cado_mpi_config.h file is possibly modified in order to trigger
#     a rebuild of all mpi sources whenever the mpi library gets changed.

include (${CADO_NFS_SOURCE_DIR}/config/pthreads.cmake)
include (${CADO_NFS_SOURCE_DIR}/config/mpi.cmake)

# The code in linalg/bwc/mpfq/ is 64-bit only, and relies on GNU CC
# idioms. As it is not used in production yet, we don't want to expose it
# on 32-bit platforms.
set(ENABLE_MPFQ_PRIME_FIELDS_FOR_DLOG ${HAVE_GCC_STYLE_AMD64_INLINE_ASM})

message(STATUS "Using libs: ${math_libs} (math) ${pthread_libs} (pthreads)")

configure_file(cado_mpi_config_h.in cado_mpi_config.h ESCAPE_QUOTES @ONLY)

#####################################################################
# OK, it's freakin ugly. Don't look.

# there would have been ways to do it without a generated helper script,
# I guess -- unfortunately I couldn't find one ;-((
configure_file(config/ccwrap.pl.in ccwrap.pl ESCAPE_QUOTES @ONLY)
set(CMAKE_C_COMPILER "${CADO_NFS_BINARY_DIR}/ccwrap.pl")

configure_file(config/cxxwrap.pl.in cxxwrap.pl ESCAPE_QUOTES @ONLY)
set(CMAKE_CXX_COMPILER "${CADO_NFS_BINARY_DIR}/cxxwrap.pl")

# It's weird. This thing does not seem to apply, or at least not always. I've
# cured the problem by tweaking ccwrap, and let it decide whether it's linking
# or not. If yes, then it uses g++ rather than gcc (or mpic++ vs mpicc)
set(CMAKE_C_LINKER_PREFERENCE "${CADO_NFS_BINARY_DIR}/cxxwrap.pl")
set(CMAKE_CXX_LINKER_PREFERENCE "${CADO_NFS_BINARY_DIR}/cxxwrap.pl")

#####################################################################
# now the real stuff.

# First, create the config file gathering everything we've got so far.
configure_file(cado_config_h.in cado_config.h ESCAPE_QUOTES @ONLY)

include_directories (${CADO_NFS_SOURCE_DIR})
include_directories (${CADO_NFS_SOURCE_DIR}/utils)
include_directories (${CADO_NFS_BINARY_DIR})

# link_directories (${CADO_NFS_BINARY_DIR}/utils)
# link_directories (${CADO_NFS_BINARY_DIR}/gf2x/.libs)
# link_directories (${CADO_NFS_BINARY_DIR}/gf2x/gf2x-fft/.libs)

include_directories(${CADO_NFS_SOURCE_DIR}/gf2x)
include_directories(${CADO_NFS_BINARY_DIR}/gf2x)


############################################################

set(package_basename ${CADO_DIST_ARCHIVE_NAME})
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib/${package_basename}")
set(example_subdir share/${package_basename}/examples)

# These refer only to the place where files are put in the *build tree* !
# set(LIBRARY_OUTPUT_DIRECTORY "${CMAKE_INSTALL_PREFIX}/lib/${package_basename}")
# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_INSTALL_PREFIX}/bin")


add_custom_command(OUTPUT ${CADO_NFS_BINARY_DIR}/gf2x/Makefile
    COMMAND mkdir -p ${CADO_NFS_BINARY_DIR}/gf2x
    COMMAND echo Configuring gf2x with options ${GF2X_CONFIGURE_FLAGS}
    COMMAND cd gf2x && ${CADO_NFS_SOURCE_DIR}/gf2x/configure ${GF2X_CONFIGURE_FLAGS}
    COMMENT "Configuring gf2x"
)

add_custom_target(gf2x-build ALL
    DEPENDS ${CADO_NFS_BINARY_DIR}/gf2x/Makefile
    WORKING_DIRECTORY gf2x
    COMMAND ${CMAKE_BUILD_TOOL}
    COMMENT "Building gf2x"
)

# set(GF2X_LIB_FILE  ${CADO_NFS_BINARY_DIR}/gf2x/.libs/libgf2x.a)
# set(GF2X-FFT_LIB_FILE ${CADO_NFS_BINARY_DIR}/gf2x/gf2x-fft/.libs/libgf2x-fft.a)
# set(CANTOR128_LIB_FILE ${CADO_NFS_BINARY_DIR}/gf2x/gf2x-fft/.libs/libcantor128.a)


# add_subdirectory (gf2x-fft)
add_subdirectory (utils)
add_subdirectory (polyselect)
add_subdirectory (sieve)
add_subdirectory (sqrt)
add_subdirectory (linalg)
add_subdirectory (filter)
add_subdirectory (linalg/bwc)
add_subdirectory (misc)
add_subdirectory (scripts/cadofactor)
add_subdirectory (tests EXCLUDE_FROM_ALL)

add_custom_target(dist
    COMMAND scripts/dist.sh ${package_basename}
    WORKING_DIRECTORY ${CADO_NFS_SOURCE_DIR}
)

install(DIRECTORY params/ DESTINATION ${example_subdir} FILES_MATCHING PATTERN "params.*")

configure_file(
    ${CADO_NFS_SOURCE_DIR}/factor.sh
    ${CADO_NFS_BINARY_DIR}/factor.sh
    ESCAPE_QUOTES
    @ONLY)

# Copy magma scripts, to make our life easier; this should be removed 
# once everything will be rewritten in C.
foreach(script magma-linalg-wrapper.sh magma-nmbrthry-wrapper.sh
        badideals.mag  linalg.mag)
    configure_file(
        ${CADO_NFS_SOURCE_DIR}/scripts/${script}
        ${CADO_NFS_BINARY_DIR}/scripts/${script}
        COPYONLY)
endforeach(script)


install(PROGRAMS ${CADO_NFS_BINARY_DIR}/factor.sh DESTINATION bin)

IF (DEFINED ENV{CMAKE_DUMP_VARIABLES})
  include("${CADO_NFS_SOURCE_DIR}/config/variables.cmake")
ENDIF(DEFINED ENV{CMAKE_DUMP_VARIABLES})
back to top