lp_solve / CMakeLists.txt

INCLUDE( "${CMAKE_CURRENT_SOURCE_DIR}/Common.cmake" )

INCLUDE (CheckTypeSize)
INCLUDE (CheckFunctionExists)
INCLUDE (CheckCCompilerFlag)

LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

# This is the equivalent to perform a "make dist"/"make distdir" etc.
SET(CPACK_PACKAGE_NAME "lp_solve")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Linear Programming Solver")
SET(CPACK_PACKAGE_VENDOR "FILL IN")
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.txt")
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING")

# Process and extract the version number.
FILE( READ "ver.txt" VERSION)

CHOMP (VERSION)

STRING (REGEX MATCHALL "([0-9]+)" VERSION_DIGITS "${VERSION}")

LIST(GET VERSION_DIGITS 0 CPACK_PACKAGE_VERSION_MAJOR)
LIST(GET VERSION_DIGITS 1 CPACK_PACKAGE_VERSION_MINOR)
LIST(GET VERSION_DIGITS 2 CPACK_PACKAGE_VERSION_PATCH)
LIST(GET VERSION_DIGITS 3 CPACK_PACKAGE_VERSION_PATCHLET)

SET(CPACK_PACKAGE_INSTALL_DIRECTORY "${CPACK_PACKAGE_DESCRIPTION_SUMMARY} ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}.${CPACK_PACKAGE_VERSION_PATCHLET}")

SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")

SET (base_with_ver "${CPACK_PACKAGE_NAME}-[0-9]+\\\\.[0-9]+\\\\.[0-9]+")

SET(CPACK_SOURCE_IGNORE_FILES
    "/_CPack_Packages/"
    "/CMakeFiles/"
    "/.deps/"
    "${base_with_ver}(-Source|-Linux)/"
    "${base_with_ver}.tar\\\\.(gz|bz2|Z|lzma|xz)$"
    "\\\\.o$"
    "~$"
    "/(fc-solve|freecell-solver-range-parallel-solve|freecell-solver-fc-pro-range-solve|freecell-solver-multi-thread-solve|freecell-solver-fork-solve|measure-depth-dep-tests-order-perf)$"
    "/lib(fcs|freecell-solver)\\\\.(a|la)$"
    "\\\\.so(\\\\.[0-9]+)*$"
    "/\\\\.svn/"
    "\\\\.(pdf|fo)$"
    "/t/t/.*\\\\.exe$"
    "/t/Presets"
    "/CMakeCache\\\\.txt$"
    "/Makefile$"
    "/CTestTestfile\\\\.cmake$"
    "/cmake_install\\\\.cmake$"
    "/CPackConfig\\\\.cmake$"
    "/CPackSourceConfig\\\\.cmake$"
    "/tags$"
    "/freecell-solver-config$"
    "/libfreecell-solver\\\\.pc$"
    "/([0-9]+)\\\\.board$"
    "/config\\\\.h$"
    "/install_manifest\\\\.txt$"
    "/t/card-test-(parse|render)\\\\.c$"
    "/Testing/"
    "ids-whitelist\\\\.txt"
)

IF(WIN32 AND NOT UNIX)
    # There is a bug in NSI that does not handle full unix paths properly. Make
    # sure there is at least one set of four (4) backlasshes.
    SET(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}\\\\lp_solve.bmp")
    SET(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\lp_solve.exe")
    SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\lpsolve.sourceforge.net")
    SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\lpsolve.sourceforge.net")
    SET(CPACK_NSIS_DISPLAY_NAME "LP Solve")
    SET(CPACK_NSIS_CONTACT "FILL IN")
    SET(CPACK_NSIS_MODIFY_PATH ON)
    # Setting for NSIS :
    SET(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\lp_solve.ico")
    SET(CPACK_NSIS_MUI_UNIICON ${CPACK_NSIS_MUI_ICON})
    SET(CPACK_PACKAGE_ICON ${CPACK_NSIS_MUI_ICON})
    SET(CPACK_NSIS_MODIFY_PATH "ON")
ELSE(WIN32 AND NOT UNIX)
  SET(CPACK_STRIP_FILES "lp_solve")
  SET(CPACK_SOURCE_STRIP_FILES "")
ENDIF(WIN32 AND NOT UNIX)

SET(CPACK_PACKAGE_EXECUTABLES
    "lp_solve" "Linear Programming Solver"
)

### This is to set the RPATH correctly, so when installed under a prefix
### the executables will find the libraries.
### 
### See:
###
### http://www.cmake.org/Wiki/CMake_RPATH_handling
###
### (Taken from that wiki page)

# use, i.e. don't skip the full RPATH for the build tree
SET(CMAKE_SKIP_BUILD_RPATH  FALSE)

# when building, don't use the install RPATH already
# (but later on when installing)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) 

# the RPATH to be used when installing
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")

# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

SET (LP_SOLVE_LIB_MODULES lp_MDO.c shared/commonlib.c colamd/colamd.c shared/mmio.c shared/myblas.c ini.c fortify.c lp_rlp.c lp_crash.c bfp/bfp_LUSOL/lp_LUSOL.c bfp/bfp_LUSOL/LUSOL/lusol.c lp_Hash.c lp_lib.c lp_wlp.c lp_matrix.c lp_mipbb.c lp_MPS.c lp_params.c lp_presolve.c lp_price.c lp_pricePSE.c lp_report.c lp_scale.c lp_simplex.c lp_solve/lp_solve.c lp_SOS.c lp_utils.c yacc_read.c)

CHECK_TYPE_SIZE("void *" PTR_SIZE_IN_BYTES)
MATH(EXPR PTR_SIZE_IN_BITS "8 * ${PTR_SIZE_IN_BYTES}")
SET (PLATFORM "ux${PTR_SIZE_IN_BYTES}")

CHECK_FUNCTION_EXISTS(isnan HAS_ISNAN)

IF (NOT HAS_ISNAN)
    ADD_DEFINITIONS("-DNOISNAN")
ENDIF (NOT HAS_ISNAN)

ADD_DEFINITIONS(
    "-I${CMAKE_CURRENT_SOURCE_DIR}"
    "-I${CMAKE_CURRENT_SOURCE_DIR}/bfp"
    "-I${CMAKE_CURRENT_SOURCE_DIR}/bfp/bfp_LUSOL"
    "-I${CMAKE_CURRENT_SOURCE_DIR}/bfp/bfp_LUSOL/LUSOL"
    "-I${CMAKE_CURRENT_SOURCE_DIR}/colamd"
    "-I${CMAKE_CURRENT_SOURCE_DIR}/shared"
    "-DYY_NEVER_INTERACTIVE"
    "-DPARSER_LP"
    "-DINVERSE_ACTIVE=INVERSE_LUSOL"
    "-DRoleIsExternalInvEngine"
)

SET (MY_LINK_FLAGS )
SET (MY_TO_PROFILE "")
IF (CMAKE_BUILD_TYPE STREQUAL profile)
    SET (MY_TO_PROFILE "1")
    SET (CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_DEBUG} -pg")
    LIST (APPEND MY_LINK_FLAGS "-pg" "-static-libgcc")
    SET (BUILD_STATIC_LIBRARY "1")
    SET (MY_TARGET_LINK_LIBS "m_p" "c_p")
ELSE (CMAKE_BUILD_TYPE STREQUAL profile)
    IF (FCS_LINK_TO_STATIC)
        SET (BUILD_STATIC_LIBRARY "1")
        # SET (MY_TARGET_LINK_LIBS "${CPACK_PACKAGE_NAME}-static")
    ELSE (FCS_LINK_TO_STATIC)
        # SET (MY_TARGET_LINK_LIBS "${CPACK_PACKAGE_NAME}")
    ENDIF(FCS_LINK_TO_STATIC)
ENDIF (CMAKE_BUILD_TYPE STREQUAL profile)


INCLUDE(CPack)

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)

SET(COMPILER_FLAGS_TO_CHECK 
    "-Wall" "-Werror=implicit-function-declaration"
)

IF (CPU_ARCH)
    LIST(APPEND COMPILER_FLAGS_TO_CHECK "-march=${CPU_ARCH}")
ENDIF(CPU_ARCH)

IF (OPTIMIZATION_OMIT_FRAME_POINTER)
    LIST(APPEND COMPILER_FLAGS_TO_CHECK "-fomit-frame-pointer")
ENDIF(OPTIMIZATION_OMIT_FRAME_POINTER)

IF (CMAKE_BUILD_TYPE STREQUAL debug)
    LIST(APPEND COMPILER_FLAGS_TO_CHECK "-DFCS_COMPILE_DEBUG_FUNCTIONS=1")
ENDIF (CMAKE_BUILD_TYPE STREQUAL debug)

IF (CMAKE_BUILD_TYPE STREQUAL release)
    LIST(APPEND COMPILER_FLAGS_TO_CHECK "-flto")
ENDIF (CMAKE_BUILD_TYPE STREQUAL release)

SET (IDX 1)
FOREACH (CFLAG_TO_CHECK ${COMPILER_FLAGS_TO_CHECK})
    SET (FLAG_EXISTS_VAR "FLAG_EXISTS_${IDX}")
    MATH (EXPR IDX "${IDX} + 1")
    CHECK_C_COMPILER_FLAG("${CFLAG_TO_CHECK}" ${FLAG_EXISTS_VAR})
    IF (${FLAG_EXISTS_VAR})
        ADD_DEFINITIONS(${CFLAG_TO_CHECK})
        LIST(APPEND MY_LINK_FLAGS "${CFLAG_TO_CHECK}")
    ENDIF (${FLAG_EXISTS_VAR})
ENDFOREACH(CFLAG_TO_CHECK)

SET (MY_EXE_FLAGS)
FOREACH (CFLAG_TO_CHECK "-fwhole-program")
    SET (FLAG_EXISTS_VAR "FLAG_EXISTS_${IDX}")
    MATH (EXPR IDX "${IDX} + 1")
    CHECK_C_COMPILER_FLAG("${CFLAG_TO_CHECK}" ${FLAG_EXISTS_VAR})
    IF (${FLAG_EXISTS_VAR})
        LIST(APPEND MY_EXE_FLAGS "${CFLAG_TO_CHECK}")
    ENDIF (${FLAG_EXISTS_VAR})
ENDFOREACH(CFLAG_TO_CHECK)

# So it can find config.h
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_BINARY_DIR})

SET (FREECELL_SOLVER_LIBS)

SET (LIBNAME "lpsolve55")

ADD_LIBRARY (${LIBNAME}
    SHARED
    ${LP_SOLVE_LIB_MODULES}
    )

LIST (APPEND FREECELL_SOLVER_LIBS ${LIBNAME})
IF (BUILD_STATIC_LIBRARY)
    SET (STATICLIB "${LIBNAME}-static")
    ADD_LIBRARY (
        ${STATICLIB}
        STATIC
        ${LP_SOLVE_LIB_MODULES}
    )
    LIST (APPEND FREECELL_SOLVER_LIBS ${STATICLIB})

    SET_TARGET_PROPERTIES(
        ${STATICLIB}
        PROPERTIES OUTPUT_NAME ${LIBNAME}
    )
    SET_TARGET_PROPERTIES(
        ${FREECELL_SOLVER_LIBS}
        PROPERTIES CLEAN_DIRECT_OUTPUT 1
    )
ENDIF (BUILD_STATIC_LIBRARY)

SET_TARGET_PROPERTIES(${LIBNAME}
    PROPERTIES VERSION 0.5.0 SOVERSION 0
    )

IF (UNIX)
    SET(MATH_LIB "m")
    SET(DL_LIB "dl")
ELSE(UNIX)
    SET(MATH_LIB )
    SET(DL_LIB )
ENDIF(UNIX)

SET(LIBTCMALLOC_LIB_LIST)

IF (NOT CMAKE_BUILD_TYPE STREQUAL debug)

    # Optionally link against Google's TCMalloc if it's available:
    # http://goog-perftools.sourceforge.net/
    # This gives better performance for the threaded programs.
    FIND_LIBRARY(LIBTCMALLOC_LIB tcmalloc)

    IF(LIBTCMALLOC_LIB STREQUAL "LIBTCMALLOC_LIB-NOTFOUND")
        # Do nothing.
    ELSE(LIBTCMALLOC_LIB STREQUAL "LIBTCMALLOC_LIB-NOTFOUND")
        # Cancelling for now to see if it helps with the valgrind problem.
        # TODO : restore
        SET(LIBTCMALLOC_LIB_LIST ${LIBTCMALLOC_LIB})
    ENDIF(LIBTCMALLOC_LIB STREQUAL "LIBTCMALLOC_LIB-NOTFOUND")
    
ENDIF (NOT CMAKE_BUILD_TYPE STREQUAL debug)

INSTALL(
    FILES
        "lp_lib.h"
        "lp_types.h"
        "lp_utils.h"
        "lp_Hash.h"
        "lp_matrix.h"
        "lp_mipbb.h"
        "lp_SOS.h"
    DESTINATION
        "include"
)

INSTALL(
    TARGETS ${LIBNAME}
    DESTINATION "lib"
)

SET(FREECELL_SOLVER_EXECUTABLES )
MACRO(FCS_ADD_EXEC_NO_INSTALL target)
    SET(modules ${ARGV})
    LIST(REMOVE_AT modules 0)
    ADD_EXECUTABLE(${target} ${modules})
    LIST(APPEND FREECELL_SOLVER_EXECUTABLES ${target})
    TARGET_LINK_LIBRARIES (${target} ${MY_TARGET_LINK_LIBS})
ENDMACRO(FCS_ADD_EXEC_NO_INSTALL target)

MACRO(FCS_ADD_EXEC target)
    FCS_ADD_EXEC_NO_INSTALL(${ARGV})
    INSTALL (TARGETS ${target} DESTINATION "bin")
ENDMACRO(FCS_ADD_EXEC)


FCS_ADD_EXEC(${CPACK_PACKAGE_NAME} ${LP_SOLVE_LIB_MODULES})

FOREACH (TGT "${CPACK_PACKAGE_NAME}" "${LIBNAME}")
    TARGET_LINK_LIBRARIES (${TGT}
        ${MATH_LIB} ${DL_LIB} ${LIBTCMALLOC_LIB_LIST} ${LIBREDBLACK_LIB} ${LIBJUDY_LIB}
    )
ENDFOREACH (TGT)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.