NektarCommon.cmake 9.98 KB
Newer Older
1 2 3 4 5 6 7
MACRO(CHANGE_EXTENSION output var new_ext)
    GET_FILENAME_COMPONENT(FileName ${var} NAME_WE)
    GET_FILENAME_COMPONENT(Path ${var} PATH)
    SET(${output} ${Path}/${FileName}.${new_ext})
ENDMACRO()

MACRO(SET_LAPACK_LINK_LIBRARIES name)
8 9 10 11
    # Link FFTW before MKL to ensure FFTW original implementation used.
    IF( NEKTAR_USE_FFTW )    
        TARGET_LINK_LIBRARIES(${name} optimized ${FFTW_LIB} debug ${FFTW_LIB})
    ENDIF( NEKTAR_USE_FFTW )
12

13
    IF( NEKTAR_USE_BLAS_LAPACK )
14
        IF( NEKTAR_USE_MKL AND MKL_FOUND )
15
            TARGET_LINK_LIBRARIES(${name} ${MKL} )
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
        ENDIF( NEKTAR_USE_MKL AND MKL_FOUND )

        IF( NEKTAR_USE_ACML AND ACML_FOUND )
            TARGET_LINK_LIBRARIES(${name} ${ACML_TARGET_LINK_LIBRARIES}  )
        ENDIF( NEKTAR_USE_ACML AND ACML_FOUND )

        IF( NEKTAR_USE_ACCELERATE_FRAMEWORK )
            TARGET_LINK_LIBRARIES(${name} ${ACCELERATE_FRAMEWORK_LINK_FLAGS})
        ENDIF ( NEKTAR_USE_ACCELERATE_FRAMEWORK )

        IF( NEKTAR_USE_CHUD_FRAMEWORK )
            TARGET_LINK_LIBRARIES(${name} ${CHUD_FRAMEWORK_LINK_FLAGS})
        ENDIF ( NEKTAR_USE_CHUD_FRAMEWORK )

        IF( NEKTAR_USE_WIN32_LAPACK )
	        TARGET_LINK_LIBRARIES(${name} ${WIN32_LAPACK} ${WIN32_BLAS})
	        INSTALL(FILES ${WIN32_LAPACK_DLL} ${WIN32_BLAS_DLL}
	            DESTINATION ${NEKTAR_BIN_DIR})
        ENDIF( NEKTAR_USE_WIN32_LAPACK )

        IF( NEKTAR_USE_SYSTEM_BLAS_LAPACK )
37
            TARGET_LINK_LIBRARIES(${name} ${NATIVE_LAPACK} ${NATIVE_BLAS})
38 39 40
        ENDIF( NEKTAR_USE_SYSTEM_BLAS_LAPACK )

    ENDIF( NEKTAR_USE_BLAS_LAPACK )
41 42 43 44 45 46 47 48 49 50 51 52 53 54

    IF( NEKTAR_USE_NIST_SPARSE_BLAS_TOOLKIT AND NIST_SPARSE_BLAS_FOUND )   
        TARGET_LINK_LIBRARIES(${name} ${NIST_SPARSE_BLAS} )
    ENDIF( NEKTAR_USE_NIST_SPARSE_BLAS_TOOLKIT AND NIST_SPARSE_BLAS_FOUND )
        
    IF( NEKTAR_USE_METIS )    
        TARGET_LINK_LIBRARIES(${name} optimized ${METIS_LIB} debug 
            ${METIS_LIB} )
    ENDIF( NEKTAR_USE_METIS )
        
    IF( NEKTAR_USE_ARPACK )
        TARGET_LINK_LIBRARIES(${name} optimized ${ARPACK_LIB} debug 
            ${ARPACK_LIB} )
    ENDIF( NEKTAR_USE_ARPACK )
55 56 57 58 59 60 61 62 63
ENDMACRO(SET_LAPACK_LINK_LIBRARIES name)

MACRO(SET_COMMON_PROPERTIES name)
	SET_TARGET_PROPERTIES(${name} PROPERTIES VERSION ${NEKTAR_VERSION})

    SET_TARGET_PROPERTIES(${name} PROPERTIES DEBUG_POSTFIX -g)
    SET_TARGET_PROPERTIES(${name} PROPERTIES MINSIZEREL_POSTFIX -ms)
    SET_TARGET_PROPERTIES(${name} PROPERTIES RELWITHDEBINFO_POSTFIX -rg)
    
64 65 66 67 68 69
    IF( MSVC )
        # Disable the warnings about duplicate copy/assignment methods 
        #   (4521, 4522)
        # Disable the warning that arrays are default intialized (4351)	
        # Disable "forcing value to bool 'true' or 'false' (performance
        #   warning)" warning (4800)
70 71
        # 4250 - Inheritance via dominance.  Nektar appears to be handling the 
        # diamond correctly.
72

73 74 75 76
        # /Za is necessary to prevent temporaries being bound to reference
        #   parameters.
        SET_TARGET_PROPERTIES(${name} PROPERTIES COMPILE_FLAGS 
                            "/wd4521 /wd4522 /wd4351 /wd4018 /wd4800 /wd4250")
77

78 79 80
        # Enable source level parallel builds.
        SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
    ENDIF( MSVC )	
81
    
82
    IF( ${CMAKE_COMPILER_IS_GNUCXX} )
83 84 85 86
	    IF(NEKTAR_ENABLE_PROFILE)
	        SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
	        SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pg")
	        SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -pg")
87 88 89
            SET(LINK_FLAGS "${LINK_FLAGS} -pg")
        ENDIF(NEKTAR_ENABLE_PROFILE)
    ENDIF( ${CMAKE_COMPILER_IS_GNUCXX} )
90

91 92 93
    # Prevent including these common flags multiple times.
    IF (NOT ${CMAKE_CXX_FLAGS_DEBUG} MATCHES ".*DNEKTAR_DEBUG.*")
        SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DNEKTAR_DEBUG")
94 95 96 97

        IF ( NEKTAR_FULL_DEBUG )
            SET(CMAKE_CXX_FLAGS_DEBUG 
                    "${CMAKE_CXX_FLAGS_DEBUG} -DNEKTAR_FULLDEBUG")
98
        ENDIF( NEKTAR_FULL_DEBUG)
99 100 101 102 103
   
        IF( NOT MSVC )
            SET(CMAKE_CXX_FLAGS_DEBUG 
                    "${CMAKE_CXX_FLAGS_DEBUG} -fpermissive -Wno-deprecated")

104
            SET(CMAKE_CXX_FLAGS_RELEASE 
105
                    "${CMAKE_CXX_FLAGS_RELEASE} -Wno-deprecated")
106
        ENDIF( NOT MSVC)
107 108 109
                        
        SET(CMAKE_CXX_FLAGS_RELEASE 
                    "${CMAKE_CXX_FLAGS_RELEASE} -DNEKTAR_RELEASE")
110
    ENDIF(NOT ${CMAKE_CXX_FLAGS_DEBUG} MATCHES ".*DNEKTAR_DEBUG.*")
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
        
    IF( CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" )
        # The static libraries must be compiled with position independent
        # code on 64 bit Linux.
        SET_PROPERTY(TARGET ${name} APPEND PROPERTY COMPILE_FLAGS "-fPIC")
    ENDIF( CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" )
ENDMACRO(SET_COMMON_PROPERTIES name)

MACRO(SETUP_PRECOMPILED_HEADERS sourceFiles precompiledHeader)
    IF( NEKTAR_USE_PRECOMPILED_HEADERS )
        IF( MSVC )	
            # /Yu"stdafx.h" 
            #MESSAGE(${${precompiledHeader}})
    	    #MESSAGE(${${sourceFiles}})
            SET_SOURCE_FILES_PROPERTIES(${${sourceFiles}} 
                PROPERTIES COMPILE_FLAGS "/Yu\"${${precompiledHeader}}\"")
            LIST(GET ${sourceFiles} 0 OUTVAR)
            #MESSAGE(${OUTVAR})
            SET_SOURCE_FILES_PROPERTIES(${OUTVAR} 
                PROPERTIES COMPILE_FLAGS "/Yc\"${${precompiledHeader}}\"")
            
        ENDIF()	
    ENDIF()
ENDMACRO()

136 137
MACRO(ADD_NEKTAR_EXECUTABLE name component sources)
    IF( ${ARGC} LESS 4 )
138
        ADD_EXECUTABLE(${name} ${${sources}})
139 140 141
    ELSE( ${ARGC} LESS 4 )
        ADD_EXECUTABLE(${name} ${${sources}} ${${ARGV3}})
    ENDIF( ${ARGC} LESS 4)
142 143 144 145
	
    SET_COMMON_PROPERTIES(${name})
    
    IF( NEKTAR_USE_MKL AND MKL_FOUND )
146 147 148
        TARGET_LINK_LIBRARIES(${name} ${MKL} )
        SET_TARGET_PROPERTIES(${name}
                PROPERTIES COMPILE_FLAGS "${THE_COMPILE_FLAGS} -DMKL_ILP64")
149 150 151 152 153 154 155 156 157
    ENDIF( NEKTAR_USE_MKL AND MKL_FOUND )
        

    TARGET_LINK_LIBRARIES(${name}
        optimized LibUtilities debug LibUtilities-g
        ${Boost_THREAD_LIBRARY} 
        ${Boost_IOSTREAMS_LIBRARY} 
        ${Boost_DATE_TIME_LIBRARY} 
        ${Boost_FILESYSTEM_LIBRARY} 
158 159
        ${Boost_SYSTEM_LIBRARY}
        ${Boost_PROGRAM_OPTIONS_LIBRARY} 
160
        ${Boost_ZLIB_LIBRARY} 
161
        optimized ${TINYXML_LIB} debug ${TINYXML_LIB}
162
	)
163
    ADD_DEPENDENCIES(${name} boost tinyxml zlib)
164 165 166 167 168 169 170 171 172 173

    IF( NEKTAR_USE_MPI )
        TARGET_LINK_LIBRARIES(${name} ${MPI_LIBRARY} ${MPI_EXTRA_LIBRARY})
        SET_PROPERTY(TARGET ${name} 
                     APPEND PROPERTY COMPILE_FLAGS ${MPI_COMPILE_FLAGS})
        SET_PROPERTY(TARGET ${name}
                     APPEND PROPERTY LINK_FLAGS ${MPI_LINK_FLAGS})
    ENDIF( NEKTAR_USE_MPI )

    IF( ${CMAKE_SYSTEM} MATCHES "Linux.*" )
174 175
		TARGET_LINK_LIBRARIES(${name} optimized rt debug rt)

176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
        # The boost thread library needs pthread on linux.
        GET_TARGET_PROPERTY(THE_COMPILE_FLAGS ${name} COMPILE_FLAGS)
        GET_TARGET_PROPERTY(THE_LINK_FLAGS ${name} LINK_FLAGS)

        # It is possible these flags have not been set yet.
        IF(NOT THE_COMPILE_FLAGS)
            SET(THE_COMPILE_FLAGS "")
        ENDIF(NOT THE_COMPILE_FLAGS)

        IF(NOT THE_LINK_FLAGS )
	        SET(THE_LINK_FLAGS "")
        ENDIF(NOT THE_LINK_FLAGS)

        SET_TARGET_PROPERTIES(${name} 
                PROPERTIES COMPILE_FLAGS "${THE_COMPILE_FLAGS} -pthread")
        SET_TARGET_PROPERTIES(${name} 
                PROPERTIES LINK_FLAGS "${THE_LINK_FLAGS} -pthread")
	
    ENDIF( ${CMAKE_SYSTEM} MATCHES "Linux.*" )

    IF( ${CMAKE_SYSTEM} MATCHES "Darwin-*")
        SET_TARGET_PROPERTIES(${name} 
198
            PROPERTIES LINK_FLAGS "-Wl,-undefined,dynamic_lookup -Wl,-rpath,${CMAKE_INSTALL_PREFIX}/${LIB_DIR} -Wl,-rpath,${Boost_LIBRARY_DIRS}")
199 200
    ENDIF( ${CMAKE_SYSTEM} MATCHES "Darwin-*")
    
201 202 203 204
	INSTALL(TARGETS ${name} 
		RUNTIME DESTINATION ${NEKTAR_BIN_DIR} COMPONENT ${component} OPTIONAL
		ARCHIVE DESTINATION ${NEKTAR_LIB_DIR} COMPONENT ${component} OPTIONAL
		LIBRARY DESTINATION ${NEKTAR_LIB_DIR} COMPONENT ${component} OPTIONAL)
205

206
ENDMACRO(ADD_NEKTAR_EXECUTABLE name component sources)
207

208
MACRO(ADD_NEKTAR_LIBRARY name component type)
209
    ADD_LIBRARY(${name} ${type} ${ARGN})
210

211 212
    # NIST Sparse BLAS only static, so link into Nektar libraries directly.
    TARGET_LINK_LIBRARIES( ${name} ${NIST_SPARSE_BLAS} ${METIS_LIB})
Chris Cantwell's avatar
Chris Cantwell committed
213
    ADD_DEPENDENCIES(${name} spblastk0.9b modmetis-4.0 boost tinyxml zlib)
214 215

    IF (NEKTAR_USE_MPI)
216
        TARGET_LINK_LIBRARIES( ${name} ${GSMPI_LIBRARY} )
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
    ENDIF (NEKTAR_USE_MPI)
    
    SET_COMMON_PROPERTIES(${name})

    # Set properties for building shared libraries
    IF( ${type} STREQUAL "SHARED" )
        # Properties specific to Mac OSX
        IF( ${CMAKE_SYSTEM} MATCHES "Darwin-*")
            # We allow undefined symbols to be looked up dynamically at runtime
            # from the boost libraries linked by the executables.
            SET_TARGET_PROPERTIES(${name} 
                PROPERTIES LINK_FLAGS "-Wl,-undefined,dynamic_lookup")
        ENDIF( ${CMAKE_SYSTEM} MATCHES "Darwin-*")
    ENDIF( ${type} STREQUAL "SHARED" )

232 233
    INSTALL(TARGETS ${name} 
        EXPORT Nektar++Libraries 
234 235 236 237 238 239
		RUNTIME DESTINATION ${NEKTAR_BIN_DIR} COMPONENT ${component} OPTIONAL
		ARCHIVE DESTINATION ${NEKTAR_LIB_DIR} COMPONENT ${component} OPTIONAL
		LIBRARY DESTINATION ${NEKTAR_LIB_DIR} COMPONENT ${component} OPTIONAL) 

ENDMACRO(ADD_NEKTAR_LIBRARY name component type)

240 241 242 243 244
# Adds a test with a given name.
# The Test Definition File should be in a subdirectory called Tests relative
# to the CMakeLists.txt file calling this macros. The test file should be called
# NAME.tst, where NAME is given as a parameter to this macro.
MACRO(ADD_NEKTAR_TEST name)
245 246
    GET_FILENAME_COMPONENT(dir ${CMAKE_CURRENT_SOURCE_DIR} NAME)
    ADD_TEST(NAME ${dir}_${name}
247 248
         COMMAND Tester ${CMAKE_CURRENT_SOURCE_DIR}/Tests/${name}.tst)
ENDMACRO(ADD_NEKTAR_TEST)