2017-01-10 10:14:51 +00:00
cmake_minimum_required ( VERSION 3.0 )
PROJECT ( Spintrum )
2017-01-12 17:21:29 +00:00
if ( NOT WIN32 )
string ( ASCII 27 Esc )
set ( ColourReset "${Esc}[m" )
set ( ColourBold "${Esc}[1m" )
set ( Red "${Esc}[31m" )
set ( Green "${Esc}[32m" )
set ( Yellow "${Esc}[33m" )
set ( Blue "${Esc}[34m" )
set ( Magenta "${Esc}[35m" )
set ( Cyan "${Esc}[36m" )
set ( White "${Esc}[37m" )
set ( BoldRed "${Esc}[1;31m" )
set ( BoldGreen "${Esc}[1;32m" )
set ( BoldYellow "${Esc}[1;33m" )
set ( BoldBlue "${Esc}[1;34m" )
set ( BoldMagenta "${Esc}[1;35m" )
set ( BoldCyan "${Esc}[1;36m" )
set ( BoldWhite "${Esc}[1;37m" )
endif ( )
#This allows in-source build in case it's a pip installation.
#This is OK because the directory is temporary and will be removed eventually
if ( NOT DEFINED PythonInstallation )
if ( EXISTS "setup.py" )
message ( FATAL_ERROR "${BoldRed}Error: You cannot make an in-source build. Please create a sub-dir and cmake in it.${ColourReset}" )
endif ( )
endif ( )
#Get rid of warning about unused variable
set ( PythonInstallation "OFF" )
2017-01-10 10:14:51 +00:00
if ( NOT DEFINED SpintrumPath )
2017-01-12 17:21:29 +00:00
set ( SpintrumPath src/ )
2017-01-10 10:14:51 +00:00
endif ( )
if ( NOT DEFINED PolymathPath )
2017-01-12 17:21:29 +00:00
set ( PolymathPath 3rdparty/Polymath/ )
2017-01-10 10:14:51 +00:00
endif ( )
if ( NOT DEFINED OpenBLASPath )
2017-01-12 17:21:29 +00:00
set ( OpenBLASPath spintrum/OpenBLAS_install/ )
endif ( )
if ( NOT DEFINED OptimizationLevel )
set ( OptimizationLevel -Ofast )
2017-01-10 10:14:51 +00:00
endif ( )
set ( CMAKE_BUILD_TYPE Release )
#add_definitions(-DPOLYMATH_DEBUG)
2017-01-13 09:57:12 +00:00
set ( VERSION_GETTER python3 ${ CMAKE_SOURCE_DIR } /get_version.py )
execute_process ( COMMAND ${ VERSION_GETTER }
O U T P U T _ V A R I A B L E V E R S I O N _ G E T _ O U T P U T
E R R O R _ V A R I A B L E V E R S I O N _ G E T _ E R R O R
R E S U L T _ V A R I A B L E V E R S I O N _ G E T _ R E S U L T
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ B I N A R Y _ D I R } )
file ( STRINGS "${CMAKE_BINARY_DIR}/TEMP_VERSION.txt" VERSION )
if ( NOT "${VERSION_GET_RESULT}" STREQUAL "0" )
2017-01-13 10:11:41 +00:00
message ( FATAL_ERROR "${BoldRed}Error: Unable to get version number by executing ${VERSION_GETTER}. Call output is: ${VERSION_GET_OUTPUT}; and call's error output is: ${VERSION_GET_ERROR}${ColourReset}" )
2017-01-13 09:57:12 +00:00
endif ( )
2017-01-10 10:14:51 +00:00
add_definitions ( -DSPINTRUM_VERSION= "${VERSION}" )
2017-01-13 09:57:12 +00:00
message ( "${BoldBlue}Building Spintrum, version: ${VERSION}${ColourReset}" )
2017-01-10 10:14:51 +00:00
INCLUDE_DIRECTORIES ( ${ PolymathPath } /include )
2017-01-13 09:57:12 +00:00
#INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
2017-01-10 10:14:51 +00:00
INCLUDE_DIRECTORIES ( ${ SpintrumPath } )
INCLUDE_DIRECTORIES ( ${ OpenBLASPath } )
file ( GLOB_RECURSE PolymathSrc
" $ { P o l y m a t h P a t h } / s r c / * . c p p "
)
file ( GLOB_RECURSE includesList
" $ { P o l y m a t h P a t h } / i n c l u d e / * . h "
" $ { S p i n t r u m P a t h } / c o m m o n / * . h "
)
OPTION ( BUILD_SHARED_LIBS "turn OFF for .a libs" ON )
SET ( SpintrumMain src/Spintrum.cpp )
ADD_LIBRARY ( spintrum SHARED
$ { S p i n t r u m M a i n }
$ { P o l y m a t h S r c }
$ { i n c l u d e s L i s t }
)
if ( UNIX )
IF ( CMAKE_BUILD_TYPE MATCHES Release )
message ( "${Blue}Building in Release mode${ColourReset}" )
2017-01-12 17:21:29 +00:00
message ( "${Green}Target optimization level: ${OptimizationLevel}${ColourReset}" )
SET ( CMAKE_CXX_FLAGS_RELEASE "${OptimizationLevel}" )
SET ( CMAKE_C_FLAGS_RELEASE "${OptimizationLevel}" )
2017-01-10 10:14:51 +00:00
ELSE ( )
message ( "${BoldRed}Building in Debug mode${ColourReset}" )
SET ( CMAKE_CXX_FLAGS_RELEASE "-g" )
SET ( CMAKE_C_FLAGS_RELEASE "-g" )
ENDIF ( CMAKE_BUILD_TYPE MATCHES Release )
function ( FindOpenBLAS path found )
if ( EXISTS "${path}/lib/libopenblas.so" OR EXISTS "${path}/lib/libopenblas.so.0" )
set ( ${ found } "ON" PARENT_SCOPE )
else ( )
set ( ${ found } "OFF" PARENT_SCOPE )
endif ( )
endfunction ( )
#find OpenBLAS
set ( OpenBLASTestPath ${ OpenBLASPath } )
set ( foundOpenBLAS "OFF" )
FindOpenBLAS ( "${OpenBLASTestPath}" "foundOpenBLAS" )
if ( NOT ${ foundOpenBLAS } )
set ( OpenBLASTestPath "../${OpenBLASTestPath}" )
FindOpenBLAS ( "${OpenBLASTestPath}" "foundOpenBLAS" )
endif ( )
if ( ${ foundOpenBLAS } )
message ( "${BoldGreen}I found a compiled version of OpenBLAS in ${OpenBLASPath}. Everything looks great!${ColourReset}" )
TARGET_LINK_LIBRARIES ( spintrum -L "${OpenBLASPath}/lib" )
TARGET_LINK_LIBRARIES ( spintrum -L "../${OpenBLASPath}/lib" )
else ( )
2017-01-12 17:21:29 +00:00
message ( "${BoldRed}WARNING: OpenBLAS shared library was not found in ${OpenBLASPath}. This may lead to a failure in compilation, unless OpenBLAS is present in the operating system.${ColourReset}" )
2017-01-10 10:14:51 +00:00
message ( "${BoldGreen}I will try to fix this problem by considering that your system may have OpenBLAS installed.${ColourReset}" )
add_definitions ( -DOPENBLAS_FROM_SYSTEM )
endif ( )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC -shared -pedantic-errors" )
file ( MAKE_DIRECTORY ${ CMAKE_SOURCE_DIR } /spintrum/lib/ )
SET ( LIBRARY_OUTPUT_PATH ${ CMAKE_SOURCE_DIR } /spintrum/lib/ ) #output libspintrum.so to this directory
TARGET_LINK_LIBRARIES ( spintrum libopenblas.so )
TARGET_LINK_LIBRARIES ( spintrum )
endif ( UNIX )
if ( MSVC )
include ( GenerateExportHeader )
set ( openblasdir D:/libs/OpenBLAS-0.2.19 )
set ( openblasbuilddir D:/libs/OpenBLAS-0.2.19-build-32/ )
add_definitions ( -DISWIN32 )
TARGET_LINK_LIBRARIES ( spintrum -lopenblas )
TARGET_LINK_LIBRARIES ( spintrum D:/libs/OpenBLAS-0.2.19-build-32/lib/libopenblas.lib )
TARGET_LINK_LIBRARIES ( spintrum )
INCLUDE_DIRECTORIES ( include ${ openblasdir } )
GENERATE_EXPORT_HEADER ( m
B A S E _ N A M E m
E X P O R T _ M A C R O _ N A M E M _ E X P O R T S
E X P O R T _ F I L E _ N A M E m _ e x p o r t s . h
S T A T I C _ D E F I N E S H A R E D _ E X P O R T S _ B U I L T _ A S _ S T A T I C )
endif ( MSVC )