CMakeLists.txt 7.68 KB
Newer Older
jcl's avatar
jcl committed
1
# ============================================================================
jclamber's avatar
jclamber committed
2
# Copyright Jean-Charles LAMBERT - 2008-2013
jcl's avatar
jcl committed
3
# e-mail:   Jean-Charles.Lambert@oamp.fr
jclamber's avatar
jclamber committed
4 5 6 7 8 9
# address:  Dynamique des galaxies
#           Centre de donneeS Astrophysique de Marseille (CeSAM)
#           Laboratoire d'Astrophysique de Marseille
#           Pole de l'Etoile, site de Chateau-Gombert
#           38, rue Frederic Joliot-Curie
#           13388 Marseille cedex 13 France
jcl's avatar
jcl committed
10 11
#           CNRS U.M.R 6110
# ============================================================================
jclamber's avatar
jclamber committed
12
# CMakeListst.txt file for nemo 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 30 31 32 33 34 35 36 37 38 39
# 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
40 41
MESSAGE( STATUS "OSX detected =" ${OSX} )
MESSAGE( STATUS "BUILD_TYPE =" ${RELEASE} )
jclamber's avatar
jclamber committed
42

jcl's avatar
jcl committed
43 44 45
FIND_PACKAGE(NEMO)
FIND_PACKAGE(SQLITE3)

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

jclamber's avatar
jclamber committed
50 51
  add_subdirectory(${PROJECT_SOURCE_DIR}/3rdparty/nemolight/build  ${PROJECT_BINARY_DIR}/../3rdparty/nemolight/build )
  set(NEMOLIGHT ${PROJECT_SOURCE_DIR}/3rdparty/nemolight)
52 53 54
  set(NEMOLIB ${NEMOLIGHT}/lib)
  set(NEMOINC ${NEMOLIGHT}/src/inc)

jcl's avatar
jcl committed
55 56 57 58 59 60
ELSE (NOT NEMO_INSTALLED) 
  set(NEMOLIB $ENV{NEMOLIB})
  set(NEMOINC $ENV{NEMOINC})
ENDIF (NOT NEMO_INSTALLED) 

MESSAGE( STATUS "NEMOLIB : " ${NEMOLIB} )
61
MESSAGE( STATUS "NEMOINC : " ${NEMOINC} )
jcl's avatar
jcl committed
62 63

# Find all the sources for the LIB
jclamber's avatar
jclamber committed
64
FILE(GLOB LIBSOURCES src/*.cc)
jcl's avatar
jcl committed
65 66

# Destination path for the lib
jclamber's avatar
jclamber committed
67
SET(LIBRARY_OUTPUT_PATH lib)
jcl's avatar
jcl committed
68 69

# compilation options
70 71 72 73 74
#dd_definitions(-Wall ${OPT} -Wswitch -Wcast-align -Wreturn-type -Wno-unused-function  -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE ${DNOSQLITE3})
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
75

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

if(OSX) 
  set_target_properties(unsio PROPERTIES LINK_FLAGS "-L${NEMOLIB} -lnemo -lsqlite3")
endif(OSX)
#
# ------------------
# TEST PROGRAM      
# ------------------
89 90 91 92 93
if(DEFINED CMAKE_Fortran_COMPILER AND CMAKE_Fortran_COMPILER MATCHES "^$")
    set(CMAKE_Fortran_COMPILER CMAKE_Fortran_COMPILER-NOTFOUND)
endif(DEFINED CMAKE_Fortran_COMPILER AND CMAKE_Fortran_COMPILER MATCHES "^$")
enable_language(Fortran OPTIONAL)
message(STATUS "CMAKE_Fortran_COMPILER_WORKS = ${CMAKE_Fortran_COMPILER_WORKS}")
jclamber's avatar
jclamber committed
94 95 96 97
if (CMAKE_Fortran_COMPILER)
  SET(CMAKE_Fortran_COMPILER gfortran)
  MESSAGE(STATUS "Fortran compiler : " ${CMAKE_Fortran_COMPILER})
endif()
98

jcl's avatar
jcl committed
99
# Enable Fortran support
100 101 102 103 104 105
#ENABLE_LANGUAGE(Fortran)
#if (${CMAKE_Fortran_COMPILER} STREQUAL CMAKE_Fortran_COMPILER-NOTFOUND)
#  MESSAGE(STATUS "NO FORTRAN")
#else ()
#  SET(CMAKE_Fortran_COMPILER gfortran)
#endif()
jcl's avatar
jcl committed
106 107

# Executbale output path
jclamber's avatar
jclamber committed
108
set(EXECUTABLE_OUTPUT_PATH bin)
jcl's avatar
jcl committed
109 110 111
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
112
include_directories (${UNSIO_SOURCE_DIR}/src ${NEMOINC} ${NEMOLIB} ${SQLITE3_H_PATH} /usr/include/malloc)
jcl's avatar
jcl committed
113 114 115 116 117

# 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
118
FILE(GLOB exe_sources test_src/*.F)
jcl's avatar
jcl committed
119 120 121 122 123 124 125


# ----------------------------------------------------------
# Make sure the compiler can find include files from our Hello library.
#include_directories (${UNS_SOURCE_DIR}/src $ENV{NEMOINC} ${NEMOLIB})

# Find all LIB's sources files
jclamber's avatar
jclamber committed
126
FILE(GLOB execpp_sources test_src/*.cc)
jcl's avatar
jcl committed
127 128 129 130 131 132 133 134 135

# 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.
136
  target_link_libraries (${exe} unsio nemo ${SQLITE3_LIB} ${FC_GFORT_LIB} ${FC_G77_LIB} stdc++)
jcl's avatar
jcl committed
137 138 139 140 141

ENDFOREACH(exe_cpp ${execpp_sources})

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

jcl's avatar
jcl committed
144 145 146 147 148 149 150 151 152 153 154 155 156 157
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})
158
endif()
jclamber's avatar
jclamber committed
159 160 161 162


# ----------------------------------------------------------
# Install procedure
jcl's avatar
jcl committed
163
# ----------------------------------------------------------
jclamber's avatar
jclamber committed
164 165 166 167 168 169 170 171 172 173 174 175
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})

jclamber's avatar
jclamber committed
176
# unsio lib
jclamber's avatar
jclamber committed
177
INSTALL(FILES  ${UNSIO_BINARY_DIR}/lib/libunsio.${LIBEXT} DESTINATION lib)
jclamber's avatar
jclamber committed
178

jcl's avatar
jcl committed
179
  
jclamber's avatar
jclamber committed
180 181 182 183 184 185 186 187 188 189
# 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
190 191 192 193

  # install nemo lib
  INSTALL(FILES  ${NEMOLIGHT}/lib/libnemo.${LIBEXT} DESTINATION lib)
  INSTALL(FILES  ${NEMOLIGHT}/lib/libnemomaing77.${LIBEXT} DESTINATION lib)
jclamber's avatar
jclamber committed
194 195 196 197 198 199 200

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

201
  FILE(GLOB nlight_files ${NEMOLIGHT}/src/inc/snapshot/*.{c,h})
jclamber's avatar
jclamber committed
202 203 204 205 206
  FOREACH(source_header ${nlight_files})
     INSTALL(FILES  ${source_header} DESTINATION inc/snapshot)
  ENDFOREACH()

ENDIF()
jcl's avatar
jcl committed
207 208
# man
INSTALL(FILES  ${UNSIO_BINARY_DIR}/../man/man3/unsiof.3 DESTINATION man/man3)
jclamber's avatar
jclamber committed
209
# some binaries
jcl's avatar
jcl committed
210 211

#set (CMAKE_INSTALL_PREFIX $ENV{NEMOBIN})
jclamber's avatar
jclamber committed
212
INSTALL(PROGRAMS  ${UNSIO_BINARY_DIR}/bin/uns_info DESTINATION bin)