CMakeLists.txt 13.2 KB
Newer Older
jcl's avatar
jcl committed
1
# ============================================================================
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
2
# Copyright Jean-Charles LAMBERT - 2008-2018
jclamber's avatar
jclamber committed
3 4 5 6 7 8 9 10
#           Centre de donneeS Astrophysiques de Marseille (CeSAM)       
# e-mail:   Jean-Charles.Lambert@lam.fr                                      
# address:  Aix Marseille Universite, CNRS, LAM 
#           Laboratoire d'Astrophysique de Marseille                          
#           Pole de l'Etoile, site de Chateau-Gombert                         
#           38, rue Frederic Joliot-Curie                                     
#           13388 Marseille cedex 13 France                                   
#           CNRS UMR 7326    
jcl's avatar
jcl committed
11
# ============================================================================
jclamber's avatar
jclamber committed
12
# CMakeListst.txt file to compile UNSIO library
jcl's avatar
jcl committed
13
# ============================================================================
jclamber's avatar
jclamber committed
14

jcl's avatar
jcl committed
15
cmake_minimum_required(VERSION 2.6)
16

jcl's avatar
jcl committed
17
# project name
18
project (UNSIO2)
jclamber's avatar
jclamber committed
19 20


jcl's avatar
jcl committed
21
SET(CMAKE_VERBOSE_MAKEFILE OFF)
22
# extra cmake path
jclamber's avatar
jclamber committed
23 24 25 26
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)

# load setup flags
include(SetupFlags)
jcl's avatar
jcl committed
27

jclamber's avatar
jclamber committed
28 29
# Check fortran compiler
include(CheckFortranCompiler)
jclamber's avatar
jclamber committed
30

31 32 33 34 35 36 37
# use ccache if any
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
  set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
  set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif(CCACHE_FOUND)

38 39 40
# Cpack Generator detection
include(DetectCpackGenerator)

jclamber's avatar
jclamber committed
41 42 43 44 45 46 47 48 49 50 51 52
# contains the full path to the top level directory of your build tree
MESSAGE( STATUS "PROJECT_BINARY_DIR: " ${PROJECT_BINARY_DIR} )

# contains the full path to the root of your project source directory,
# i.e. to the nearest directory where CMakeLists.txt contains the PROJECT() command
MESSAGE( STATUS "PROJECT_SOURCE_DIR: " ${PROJECT_SOURCE_DIR} )

MESSAGE( STATUS "CMAKE_BUILD_TYPE =" ${CMAKE_BUILD_TYPE} )
MESSAGE( STATUS "CMAKE_CXX_FLAGS  =" ${CMAKE_CXX_FLAGS} )
MESSAGE( STATUS "LIBRARY TYPE     =" ${LIBTYPE} )

MESSAGE( STATUS "core OPT  =" ${OPT} )
jclamber's avatar
jclamber committed
53 54
MESSAGE( STATUS "OSX detected =" ${OSX} )
MESSAGE( STATUS "BUILD_TYPE =" ${RELEASE} )
jclamber's avatar
jclamber committed
55

jcl's avatar
jcl committed
56
FIND_PACKAGE(SQLITE3)
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
57
#set (HDF5_USE_STATIC_LIBRARIES TRUE)
Jcl's avatar
Jcl committed
58
FIND_PACKAGE(HDF5 COMPONENTS CXX REQUIRED)
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
59
MESSAGE( STATUS "1) HDF5_CXX_LIBRARIES=" ${HDF5_CXX_LIBRARIES})
60

LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
61 62 63
if(LINUX_ISSUE MATCHES "Mageia")
  SET(HDF5_CXX_LIBRARIES hdf5_hl_cpp.a hdf5_cpp.a hdf5.a) # use this trick to compile against hdf5 static libs, to keep compatibility between hdf5 libs, works only on mageia...
endif()
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
64
MESSAGE( STATUS "2) HDF5_CXX_LIBRARIES=" ${HDF5_CXX_LIBRARIES})
jcl's avatar
jcl committed
65

66
MESSAGE(STATUS "NEMO LIGHT will be build")
67

68 69 70 71
add_subdirectory(${PROJECT_SOURCE_DIR}/3rdparty/nemolight  ${PROJECT_SOURCE_DIR}/3rdparty/nemolight/build-${CMAKE_BUILD_TYPE} )
set(NEMOLIGHT ${PROJECT_SOURCE_DIR}/3rdparty/nemolight)
set(NEMOLIB ${NEMOLIGHT}/build-${CMAKE_BUILD_TYPE}/lib)
set(NEMOINC ${NEMOLIGHT}/src/inc)
jcl's avatar
jcl committed
72 73

MESSAGE( STATUS "NEMOLIB : " ${NEMOLIB} )
74
MESSAGE( STATUS "NEMOINC : " ${NEMOINC} )
75
MESSAGE( STATUS "LIB_SUFFIX : " ${LIB_SUFFIX} )
jcl's avatar
jcl committed
76 77

# Find all the sources for the LIB
jclamber's avatar
jclamber committed
78
FILE(GLOB LIBSOURCES src/*.cc)
jcl's avatar
jcl committed
79 80

# Destination path for the lib
jclamber's avatar
jclamber committed
81
SET(LIBRARY_OUTPUT_PATH lib)
jcl's avatar
jcl committed
82 83

# compilation options
jclamber's avatar
jclamber committed
84

85 86 87 88
add_definitions(${OPT} -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE ${DNOSQLITE3})
SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} ${WARNCPP} )
SET(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} ${WARNC} )
SET(CMAKE_Fortran_FLAGS ${CMAKE_Fortran_FLAGS} ${WARNF})
jcl's avatar
jcl committed
89

90 91 92
# remove -DNDEBUG in RElease mode to keep activated assert calls
STRING(REPLACE "-DNDEBUG" ""  CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})

jcl's avatar
jcl committed
93
# create library "uns"
94
add_library (unsio ${LIBTYPE} ${LIBSOURCES})
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
95 96 97 98 99
# special flags for MacOSX
if (OSX)
  set(CMAKE_MACOSX_RPATH ON) 
endif()
#
100

101 102
SET(DEP_NEMO_LIB "nemo")
#ENDIF (NOT NEMO_INSTALLED)
103

LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
104
target_link_libraries(unsio ${DEP_NEMO_LIB} ${HDF5_CXX_LIBRARIES} sqlite3 z )
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
105 106 107
if (OSX)
    set_target_properties(unsio PROPERTIES LINK_FLAGS "-undefined suppress -flat_namespace")
endif()
jcl's avatar
jcl committed
108

jclamber's avatar
jclamber committed
109 110 111 112 113 114
# ----------------------------------------------------------
# Install SETUP
# ----------------------------------------------------------

mark_as_advanced(CMAKE_INSTALL_PREFIX)

115 116 117 118 119
SET(PREFIX_LIB ${LIB_SUFFIX})
SET(PREFIX_INC "include")
SET(PREFIX_MAN "share/man")
SET(PREFIX_SCR "share/uns/scripts")

jclamber's avatar
jclamber committed
120
IF (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
121
  set   (CMAKE_INSTALL_PREFIX "$ENV{HOME}/local/unsio" CACHE PATH "" FORCE)  #if NEMO NOT exist => default install into ${HOME}/local/unsio
jclamber's avatar
jclamber committed
122 123 124
ENDIF ()#NOT CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)

MESSAGE( STATUS "--------> CMAKE_INSTALL_PREFIX =" ${CMAKE_INSTALL_PREFIX})
jclamber's avatar
jclamber committed
125 126 127
if (OSX)
  MESSAGE(STATUS "\nAfter running \"make install\", do not forget to set your environment variable DYLD_LIBRARY_PATH using command:\n\n export DYLD_LIBRARY_PATH=${CMAKE_INSTALL_PREFIX}/lib\n")
endif(OSX)
jclamber's avatar
jclamber committed
128 129 130 131 132 133 134

# 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)

135
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${PREFIX_LIB}")
jclamber's avatar
jclamber committed
136 137 138 139 140 141

# 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)

# the RPATH to be used when installing, but only if it's not a system directory
142
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/${PREFIX_LIB}" isSystemDir)
jclamber's avatar
jclamber committed
143
IF("${isSystemDir}" STREQUAL "-1")
144
   SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${PREFIX_LIB}")
jclamber's avatar
jclamber committed
145 146 147 148
ENDIF("${isSystemDir}" STREQUAL "-1")


# ----------------------------------------------------------
jcl's avatar
jcl committed
149
# Executbale output path
jclamber's avatar
jclamber committed
150
set(EXECUTABLE_OUTPUT_PATH bin)
jcl's avatar
jcl committed
151 152 153
MESSAGE( STATUS "EXECUTABLE_OUTPUT_PATH: " ${EXECUTABLE_OUTPUT_PATH} )

# Make sure the compiler can find include files from our Hello library.
154
include_directories (${UNSIO2_SOURCE_DIR}/src ${NEMOINC} ${NEMOLIB} ${SQLITE3_H_PATH})
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
155
include_directories (/usr/include/malloc ${HDF5_INCLUDE_DIRS})
jcl's avatar
jcl committed
156 157

# Make sure the linker can find the Hello library once it is built.
158 159
link_directories (${UNSIO2_BINARY_DIR}/lib /usr/X11/lib ${SQLITE3_LIB_PATH} )
link_directories ( ${NEMOLIB} ${FC_GFORT_PATH} ${FC_G77_PATH} )
jcl's avatar
jcl committed
160 161

# Find all LIB's sources files
jclamber's avatar
jclamber committed
162
FILE(GLOB exe_sources test_src/*.F)
jcl's avatar
jcl committed
163 164 165


# ----------------------------------------------------------
jclamber's avatar
jclamber committed
166
# compile CC programs
jcl's avatar
jcl committed
167
# Find all LIB's sources files
jclamber's avatar
jclamber committed
168
FILE(GLOB execpp_sources test_src/*.cc)
jcl's avatar
jcl committed
169 170 171 172 173 174 175 176 177

# build cpp executables according to the source
FOREACH(exe_cpp ${execpp_sources})

  get_filename_component(exe ${exe_cpp} NAME_WE)
  MESSAGE( STATUS "New executable ==> " ${exe})
  add_executable (${exe} ${exe_cpp})

  # Link the executable to the Hello library.
178
  target_link_libraries (${exe} unsio ) # ${FC_GFORT_LIB} ${FC_G77_LIB} stdc++)
jclamber's avatar
jclamber committed
179 180 181
  IF (${exe} STREQUAL "uns_info")
    INSTALL(TARGETS ${exe} RUNTIME  DESTINATION bin)
  ENDIF()
jcl's avatar
jcl committed
182 183 184 185 186

ENDFOREACH(exe_cpp ${execpp_sources})

# build Fortran executables according to the source
# compilation options
187
if (CMAKE_Fortran_COMPILER)
jclamber's avatar
jclamber committed
188

jcl's avatar
jcl committed
189 190 191 192 193 194 195 196
FOREACH(exe_f ${exe_sources})

  get_filename_component(exe ${exe_f} NAME_WE)
  MESSAGE( STATUS "New executable ==> " ${exe})
  add_executable (${exe} ${exe_f})

  # Link the executable to the Hello library.
  #target_link_libraries (${exe} unsio nemomaing77 nemo g2c sqlite3 stdc++)
Jcl's avatar
Jcl committed
197
  target_link_libraries (${exe} unsio nemomaing77 ${FC_LIB} stdc++)
jcl's avatar
jcl committed
198 199 200 201 202

  SET_TARGET_PROPERTIES(${exe} PROPERTIES LINKER_LANGUAGE Fortran)
  # add "-lstdc++"
  #SET(CMAKE_Fortran_LINK_FLAGS "-L${NEMOLIB} ") #-lstdc++")
ENDFOREACH(exe_f ${exe_sources})
203
endif()
jclamber's avatar
jclamber committed
204 205 206 207


# ----------------------------------------------------------
# Install procedure
jcl's avatar
jcl committed
208 209
# ----------------------------------------------------------
  
jclamber's avatar
jclamber committed
210
# UNS specific includes
211
INSTALL(FILES  ${UNSIO2_BINARY_DIR}/../src/uns.h DESTINATION ${PREFIX_INC}/uns)
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
212
INSTALL(FILES  ${UNSIO2_BINARY_DIR}/../src/version.h DESTINATION ${PREFIX_INC}/uns)
213 214 215 216 217
INSTALL(FILES  ${UNSIO2_BINARY_DIR}/../src/unsdebug.h DESTINATION ${PREFIX_INC}/uns)
INSTALL(FILES  ${UNSIO2_BINARY_DIR}/../src/snapshotinterface.h DESTINATION ${PREFIX_INC}/uns)
INSTALL(FILES  ${UNSIO2_BINARY_DIR}/../src/componentrange.h DESTINATION ${PREFIX_INC}/uns)
INSTALL(FILES  ${UNSIO2_BINARY_DIR}/../src/ctools.h DESTINATION ${PREFIX_INC}/uns)
INSTALL(FILES  ${UNSIO2_BINARY_DIR}/../src/userselection.h DESTINATION ${PREFIX_INC}/uns)
218 219 220 221
# unsio lib
INSTALL(FILES  ${UNSIO2_BINARY_DIR}/lib/libunsio.${LIBEXT} DESTINATION ${PREFIX_LIB})
# man
INSTALL(FILES  ${UNSIO2_BINARY_DIR}/../man/man3/unsiof.3 DESTINATION ${PREFIX_MAN}/man3)
jclamber's avatar
jclamber committed
222

223 224 225
#
# NEMO specific lib and includes 
#
jclamber's avatar
jclamber committed
226

227 228
#INSTALL(FILES  ${NEMOLIB}/libnemo.a DESTINATION ${PREFIX_LIB})
INSTALL(FILES  ${NEMOLIB}/libnemomaing77.a DESTINATION ${PREFIX_LIB})
jclamber's avatar
jclamber committed
229

230 231 232 233 234
# Find all NEMOLIGHT header files
FILE(GLOB nlight_files ${NEMOLIGHT}/src/*.h ${NEMOLIGHT}/src/inc/*.h)
FOREACH(source_header ${nlight_files})
  INSTALL(FILES  ${source_header} DESTINATION ${PREFIX_INC}/nemo)
ENDFOREACH()
jclamber's avatar
jclamber committed
235

236 237 238 239
FILE(GLOB nlight_files ${NEMOLIGHT}/src/inc/snapshot/*.c ${NEMOLIGHT}/src/inc/snapshot/*.h)
FOREACH(source_header ${nlight_files})
  INSTALL(FILES  ${source_header} DESTINATION ${PREFIX_INC}/nemo/snapshot)
ENDFOREACH()
jclamber's avatar
jclamber committed
240 241


242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307

if (NOT CMAKE_INSTALL_PREFIX STREQUAL "/usr")
  # I man using this hack otherwise the RPM package created fails to install because an unresolve dependency on Tools::Sqlite3 
  # module though which comes with this install....
  
  # install sqlite3 database files
  INSTALL(FILES  ${UNSIO2_BINARY_DIR}/../scripts/perl/lib/Tools/Tools.pm DESTINATION "${PREFIX_SCR}/perl/lib/Tools")
  INSTALL(FILES  ${UNSIO2_BINARY_DIR}/../scripts/perl/lib/Tools/Sqlite3.pm DESTINATION "${PREFIX_SCR}/perl/lib/Tools")
  INSTALL(FILES  ${UNSIO2_BINARY_DIR}/../scripts/sql/create_unsio_db.sql DESTINATION "${PREFIX_SCR}/sql")
  INSTALL(FILES  ${UNSIO2_BINARY_DIR}/../scripts/sql/README DESTINATION "${PREFIX_SCR}/sql")

  # some binaries
  INSTALL(PROGRAMS  ${UNSIO2_BINARY_DIR}/../scripts/perl/mains/unsio_sql3_get_info.pl DESTINATION bin)
  INSTALL(PROGRAMS  ${UNSIO2_BINARY_DIR}/../scripts/perl/mains/unsio_sql3_update_info.pl DESTINATION bin)
  INSTALL(PROGRAMS  ${UNSIO2_BINARY_DIR}/../scripts/perl/mains/unsio_sql3_update_nemorange.pl DESTINATION bin)
  INSTALL(PROGRAMS  ${UNSIO2_BINARY_DIR}/../scripts/perl/mains/unsio_sql3_create_db.pl DESTINATION bin)
endif()

# ----------
# PACKAGING
# ----------
# VERSION
if (EXISTS "${PROJECT_SOURCE_DIR}/src/version.h") # detect version from "version.h" file
  set(CURRENT_VERSION "")
  file(READ "${PROJECT_SOURCE_DIR}/src/version.h" CURRENT_VERSION_H)

  # UNSIO_MAJOR
  string(REGEX MATCH "UNSIO_MAJOR \"([a-zA-Z0-9.-]+)\"" XXXX "${CURRENT_VERSION_H}")
  set(PROJECT_VERSION_MAJOR ${CMAKE_MATCH_1})

  # UNSIO_MINOR
  string(REGEX MATCH "UNSIO_MINOR \"([a-zA-Z0-9.-]+)\"" XXXX "${CURRENT_VERSION_H}")
  set(PROJECT_VERSION_MINOR ${CMAKE_MATCH_1})

  #  UNSIO_PATCH
  string(REGEX MATCH "UNSIO_PATCH \"([a-zA-Z0-9.-]+)\"" XXXX "${CURRENT_VERSION_H}")
  set(PROJECT_VERSION_PATCH ${CMAKE_MATCH_1})

  # UNSIO_EXTRA
  string(REGEX MATCH "UNSIO_EXTRA \"([_a-zA-Z0-9.-]+)\"" XXXX "${CURRENT_VERSION_H}")
  set(PROJECT_VERSION_EXTRA ${CMAKE_MATCH_1})

  # PROJECT_VERSION
  set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}${PROJECT_VERSION_EXTRA}")

  message(STATUS "Project Version = " ${PROJECT_VERSION})
endif()

# CPACK infos
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_PACKAGE_NAME "unsio")
set(CPACK_PACKAGE_RELEASE 1)
set(CPACK_PACKAGE_CONTACT "Jean-Charles LAMBERT")
set(CPACK_PACKAGE_VENDOR "LAM - CeSAM")
set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.${LINUX_NAME}.${CMAKE_SYSTEM_PROCESSOR}")
#set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_PACKAGE_RELEASE}.${LINUX_NAME}.${CMAKE_SYSTEM_PROCESSOR}")

# CPACK RPM specific
set(CPACK_RPM_CHANGELOG_FILE "${PROJECT_SOURCE_DIR}/ChangeLog")
set(CPACK_RPM_PACKAGE_LICENSE "CeCILL2")
set(CPACK_RPM_PACKAGE_DESCRIPTION "UNSIO - Universal Nbody Snapshot Input Output")

# CPACK debian specific
set(CPACK_DEBIAN_PACKAGE_NAME ${CPACK_PACKAGE_NAME})
set(CPACK_DEBIAN_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION}-${CPACK_PACKAGE_RELEASE}.${LINUX_NAME})
308 309
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS ON)
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
IF(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
  SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE amd64)
ELSEIF(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
  SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE i386)
ENDIF(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${CPACK_RPM_PACKAGE_DESCRIPTION})


if (APPLE)
  set(CMAKE_INSTALL_PREFIX "/Applications")
  set(CPACK_GENERATOR "DragNDrop")
  set(CPACK_DMG_FORMAT "UDBZ")
  set(CPACK_DMG_VOLUME_NAME "${PROJECT_NAME}")
  set(CPACK_SYSTEM_NAME "OSX")
  set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}")
 #set(CPACK_PACKAGE_ICON "${ICONS_DIR}/DMG.icns")
  #set(CPACK_DMG_DS_STORE "${ICONS_DIR}/DMGDSStore")
  #set(CPACK_DMG_BACKGROUND_IMAGE "${ICONS_DIR}/DMGBackground.png")
endif()

if (NOT WIN32)
  #SET(CPACK_STRIP_FILES {CMAKE_INSTALL_PREFIX}/bin/glnemo2)
  #SET(CPACK_STRIP_FILES "True")
  #SET(CPACK_SET_DESTDIR On)
        set(CMAKE_INSTALL_DO_STRIP TRUE)
  #SET(CPACK_INSTALL_PREFIX "/usr")
  #SET(CMAKE_INSTALL_PREFIX ${CPACK_INSTALL_PREFIX})
endif()

set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION "${BIN_INSTALL_DIR}")
include(InstallRequiredSystemLibraries)

# This must always be last!
include(CPack)