CMakeLists.txt 8.67 KB
Newer Older
jcl's avatar
jcl committed
1
# ============================================================================
jclamber's avatar
jclamber committed
2 3 4 5 6 7 8 9 10
# Copyright Jean-Charles LAMBERT - 2008-2014
#           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 16 17 18
cmake_minimum_required(VERSION 2.6)
#INCLUDE(CPack) 
# project name
project (UNSIO)
jclamber's avatar
jclamber committed
19 20


jcl's avatar
jcl committed
21 22
SET(CMAKE_VERBOSE_MAKEFILE OFF)
# extra path for NEMO
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

jclamber's avatar
jclamber committed
31 32 33 34 35 36 37 38 39 40 41 42
# 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
43 44
MESSAGE( STATUS "OSX detected =" ${OSX} )
MESSAGE( STATUS "BUILD_TYPE =" ${RELEASE} )
jclamber's avatar
jclamber committed
45

jcl's avatar
jcl committed
46 47 48
FIND_PACKAGE(NEMO)
FIND_PACKAGE(SQLITE3)

49
#set (NEMO_INSTALLED FALSE) # fore NEMO not installed
jcl's avatar
jcl committed
50
IF (NOT NEMO_INSTALLED) 
51 52
  MESSAGE(STATUS "NEMO LIGHT will be build")

jclamber's avatar
jclamber committed
53
  add_subdirectory(${PROJECT_SOURCE_DIR}/3rdparty/nemolight  ${PROJECT_SOURCE_DIR}/3rdparty/nemolight/build-${CMAKE_BUILD_TYPE} )
jclamber's avatar
jclamber committed
54
  set(NEMOLIGHT ${PROJECT_SOURCE_DIR}/3rdparty/nemolight)
jclamber's avatar
jclamber committed
55
  set(NEMOLIB ${NEMOLIGHT}/build-${CMAKE_BUILD_TYPE}/lib)
56 57
  set(NEMOINC ${NEMOLIGHT}/src/inc)

jcl's avatar
jcl committed
58 59 60 61 62 63
ELSE (NOT NEMO_INSTALLED) 
  set(NEMOLIB $ENV{NEMOLIB})
  set(NEMOINC $ENV{NEMOINC})
ENDIF (NOT NEMO_INSTALLED) 

MESSAGE( STATUS "NEMOLIB : " ${NEMOLIB} )
64
MESSAGE( STATUS "NEMOINC : " ${NEMOINC} )
jcl's avatar
jcl committed
65 66

# Find all the sources for the LIB
jclamber's avatar
jclamber committed
67
FILE(GLOB LIBSOURCES src/*.cc)
jcl's avatar
jcl committed
68 69

# Destination path for the lib
jclamber's avatar
jclamber committed
70
SET(LIBRARY_OUTPUT_PATH lib)
jcl's avatar
jcl committed
71 72

# compilation options
jclamber's avatar
jclamber committed
73

74 75 76 77
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
78

79 80 81
# 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
82
# create library "uns"
jclamber's avatar
jclamber committed
83
add_library (unsio ${LIBTYPE} ${LIBSOURCES} )
jcl's avatar
jcl committed
84 85

if(OSX) 
jclamber's avatar
jclamber committed
86
  set_target_properties(unsio PROPERTIES LINK_FLAGS "-undefined suppress -flat_namespace -L${NEMOLIB} -lnemo -lsqlite3")
jcl's avatar
jcl committed
87
endif(OSX)
jclamber's avatar
jclamber committed
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125

# ----------------------------------------------------------
# Install SETUP
# ----------------------------------------------------------

mark_as_advanced(CMAKE_INSTALL_PREFIX)

IF (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  IF (NEMO_INSTALLED)
     set   (CMAKE_INSTALL_PREFIX "$ENV{NEMO}"  CACHE PATH "" FORCE)        #if NEMO exist  => default install into NEMO path
  ELSE()
     set   (CMAKE_INSTALL_PREFIX "$ENV{HOME}/local/unsio" CACHE PATH "" FORCE)  #if NEMO NOT exist => default install into ${HOME}/local/unsio
  ENDIF()
ENDIF ()#NOT CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)

MESSAGE( STATUS "--------> CMAKE_INSTALL_PREFIX =" ${CMAKE_INSTALL_PREFIX})


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

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)

# the RPATH to be used when installing, but only if it's not a system directory
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
IF("${isSystemDir}" STREQUAL "-1")
   SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
ENDIF("${isSystemDir}" STREQUAL "-1")


# ----------------------------------------------------------
jcl's avatar
jcl committed
126
# Executbale output path
jclamber's avatar
jclamber committed
127
set(EXECUTABLE_OUTPUT_PATH bin)
jcl's avatar
jcl committed
128 129 130
MESSAGE( STATUS "EXECUTABLE_OUTPUT_PATH: " ${EXECUTABLE_OUTPUT_PATH} )

# Make sure the compiler can find include files from our Hello library.
jclamber's avatar
jclamber committed
131
include_directories (${UNSIO_SOURCE_DIR}/src ${NEMOINC} ${NEMOLIB} ${SQLITE3_H_PATH} /usr/include/malloc)
jcl's avatar
jcl committed
132 133 134 135 136

# Make sure the linker can find the Hello library once it is built.
link_directories (${UNSIO_BINARY_DIR}/lib /usr/X11/lib ${SQLITE3_LIB_PATH} ${NEMOLIB} ${FC_GFORT_PATH} ${FC_G77_PATH})

# Find all LIB's sources files
jclamber's avatar
jclamber committed
137
FILE(GLOB exe_sources test_src/*.F)
jcl's avatar
jcl committed
138 139 140


# ----------------------------------------------------------
jclamber's avatar
jclamber committed
141
# compile CC programs
jcl's avatar
jcl committed
142
# Find all LIB's sources files
jclamber's avatar
jclamber committed
143
FILE(GLOB execpp_sources test_src/*.cc)
jcl's avatar
jcl committed
144 145 146 147 148 149 150 151 152

# 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.
153
  target_link_libraries (${exe} unsio nemo ${SQLITE3_LIB} ${FC_GFORT_LIB} ${FC_G77_LIB} stdc++)
jclamber's avatar
jclamber committed
154 155 156
  IF (${exe} STREQUAL "uns_info")
    INSTALL(TARGETS ${exe} RUNTIME  DESTINATION bin)
  ENDIF()
jcl's avatar
jcl committed
157 158 159 160 161

ENDFOREACH(exe_cpp ${execpp_sources})

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

jcl's avatar
jcl committed
164 165 166 167 168 169 170 171 172 173 174 175 176 177
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++)
  target_link_libraries (${exe} unsio nemomaing77 nemo ${SQLITE3_LIB}  ${FC_LIB} stdc++)

  SET_TARGET_PROPERTIES(${exe} PROPERTIES LINKER_LANGUAGE Fortran)
  # add "-lstdc++"
  #SET(CMAKE_Fortran_LINK_FLAGS "-L${NEMOLIB} ") #-lstdc++")
ENDFOREACH(exe_f ${exe_sources})
178
endif()
jclamber's avatar
jclamber committed
179 180 181 182


# ----------------------------------------------------------
# Install procedure
jcl's avatar
jcl committed
183 184
# ----------------------------------------------------------
  
jclamber's avatar
jclamber committed
185 186 187 188 189 190 191 192 193 194
# UNS specific includes
INSTALL(FILES  ${UNSIO_BINARY_DIR}/../src/uns.h DESTINATION inc/uns)
INSTALL(FILES  ${UNSIO_BINARY_DIR}/../src/unsdebug.h DESTINATION inc/uns)
INSTALL(FILES  ${UNSIO_BINARY_DIR}/../src/snapshotinterface.h DESTINATION inc/uns)
INSTALL(FILES  ${UNSIO_BINARY_DIR}/../src/componentrange.h DESTINATION inc/uns)
INSTALL(FILES  ${UNSIO_BINARY_DIR}/../src/ctools.h DESTINATION inc/uns)
INSTALL(FILES  ${UNSIO_BINARY_DIR}/../src/userselection.h DESTINATION inc/uns)

# NEMO specific includes
IF (NOT NEMO_INSTALLED)
jclamber's avatar
jclamber committed
195 196

  # install nemo lib
jclamber's avatar
jclamber committed
197 198
  INSTALL(FILES  ${NEMOLIB}/libnemo.a DESTINATION lib)
  INSTALL(FILES  ${NEMOLIB}/libnemomaing77.a DESTINATION lib)
jclamber's avatar
jclamber committed
199 200 201 202 203 204 205

  # 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 inc)
  ENDFOREACH()

206
  FILE(GLOB nlight_files ${NEMOLIGHT}/src/inc/snapshot/*.{c,h})
jclamber's avatar
jclamber committed
207 208 209 210 211
  FOREACH(source_header ${nlight_files})
     INSTALL(FILES  ${source_header} DESTINATION inc/snapshot)
  ENDFOREACH()

ENDIF()
jclamber's avatar
jclamber committed
212 213 214 215

# unsio lib
INSTALL(FILES  ${UNSIO_BINARY_DIR}/lib/libunsio.${LIBEXT} DESTINATION lib)

jcl's avatar
jcl committed
216 217
# man
INSTALL(FILES  ${UNSIO_BINARY_DIR}/../man/man3/unsiof.3 DESTINATION man/man3)
jclamber's avatar
jclamber committed
218
# some binaries
jcl's avatar
jcl committed
219

jclamber's avatar
jclamber committed
220 221 222 223 224 225 226 227 228 229
# install sqlite3 database files
INSTALL(PROGRAMS  ${UNSIO_BINARY_DIR}/../scripts/perl/mains/unsio_sql3_get_info.pl DESTINATION bin)
INSTALL(PROGRAMS  ${UNSIO_BINARY_DIR}/../scripts/perl/mains/unsio_sql3_update_info.pl DESTINATION bin)
INSTALL(PROGRAMS  ${UNSIO_BINARY_DIR}/../scripts/perl/mains/unsio_sql3_update_nemorange.pl DESTINATION bin)
INSTALL(PROGRAMS  ${UNSIO_BINARY_DIR}/../scripts/perl/mains/unsio_sql3_create_db.pl DESTINATION bin)

INSTALL(FILES  ${UNSIO_BINARY_DIR}/../scripts/perl/lib/Tools/Tools.pm DESTINATION scripts/perl/lib/Tools)
INSTALL(FILES  ${UNSIO_BINARY_DIR}/../scripts/perl/lib/Tools/Sqlite3.pm DESTINATION scripts/perl/lib/Tools)
INSTALL(FILES  ${UNSIO_BINARY_DIR}/../scripts/sql/create_unsio_db.sql DESTINATION scripts/sql)
INSTALL(FILES  ${UNSIO_BINARY_DIR}/../scripts/sql/README DESTINATION scripts/sql)