CMakeLists.txt 9.17 KB
Newer Older
jcl's avatar
jcl committed
1
# ============================================================================
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
2
# Copyright Jean-Charles LAMBERT - 2010-2016
jclamber's avatar
jclamber committed
3
# e-mail:   Jean-Charles.Lambert@lam.fr                                      
4 5
# address:  Dynamique des galaxies
#           Centre de donneeS Astrophysique de Marseille (CeSAM)
jcl's avatar
jcl committed
6 7 8 9
#           Laboratoire d'Astrophysique de Marseille                          
#           Pole de l'Etoile, site de Chateau-Gombert                         
#           38, rue Frederic Joliot-Curie                                     
#           13388 Marseille cedex 13 France                                   
jclamber's avatar
jclamber committed
10
#           CNRS U.M.R 7326                                                   
jcl's avatar
jcl committed
11
# ============================================================================
jclamber's avatar
jclamber committed
12
# CMakeListst.txt file 
jcl's avatar
jcl committed
13
# ============================================================================
14

jcl's avatar
jcl committed
15 16 17 18 19
cmake_minimum_required(VERSION 2.6)
 
# project name
project (uns_projects)

20 21
# extra path for NEMO
SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH} )
jcl's avatar
jcl committed
22 23
MESSAGE( STATUS "CMAKE_MODULE_PATH=" ${CMAKE_MODULE_PATH} )

24 25 26
# load setup flags
include(SetupFlags)

27 28 29 30 31 32 33 34 35 36
# 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)

# Cpack Generator detection
include(DetectCpackGenerator)

37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
# 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} )
MESSAGE( STATUS "OSX detected =" ${OSX} )
MESSAGE( STATUS "BUILD_TYPE =" ${RELEASE} )

52 53 54
MESSAGE( STATUS "EXTRA_INCLUDES =" ${EXTRA_INCLUDES} )
MESSAGE( STATUS "EXTRA_LINK_DIRS =" ${EXTRA_LINK_DIRS} )

jcl's avatar
jcl committed
55 56
# require NEMO
FIND_PACKAGE(NEMO REQUIRED)
57 58
# require UNSIO
FIND_PACKAGE(UNSIO REQUIRED)
jcl's avatar
jcl committed
59
# Sqlite3
60
#FIND_PACKAGE(SQLITE3)
61 62
# Boost (deprecated)
FIND_PACKAGE(BOOST)
jcl's avatar
jcl committed
63 64 65 66 67 68 69 70 71 72 73 74 75

#FIND_PACKAGE(NEMO REQUIRED)
MESSAGE( STATUS "NEMOLIB : " ${NEMOLIB} )

# contains the full path to the top level directory of your build tree 
MESSAGE( STATUS "PROJECT_BINARY_DIR: " ${PROJECT_BINARY_DIR} )
#MESSAGE ( STATUS "Boost_LIBRARY_DIRS : " ${Boost_LIBRARY_DIRS}) 
# 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} )


# Find all the sources for the utils LIB
76 77

if ( NEMO_INSTALLED )
jclamber's avatar
jclamber committed
78
   FILE(GLOB LIBUTILS ${PROJECT_SOURCE_DIR}/lib/utils/*.cc ${PROJECT_SOURCE_DIR}/lib/utils/*.c ${PROJECT_SOURCE_DIR}/lib/utils/nemodep/*.cc)
79
else ()
jclamber's avatar
jclamber committed
80
   FILE(GLOB LIBUTILS ${PROJECT_SOURCE_DIR}/lib/utils/*.cc ${PROJECT_SOURCE_DIR}/lib/utils/*.c)
81
endif ()
jcl's avatar
jcl committed
82 83 84 85 86 87
# create the library "JCLutils"
add_library (JCLutils SHARED ${LIBUTILS})
if(OSX)
set_target_properties(JCLutils PROPERTIES LINK_FLAGS "-undefined suppress -flat_namespace")
endif(OSX)
# Find all the sources for the projects LIB
88 89 90 91 92
if ( NEMO_INSTALLED )
   FILE(GLOB LIBPROJECTS ${PROJECT_SOURCE_DIR}/lib/projects/*.cc ${PROJECT_SOURCE_DIR}/lib/projects/nemodep/*.cc)
else ()
   FILE(GLOB LIBPROJECTS ${PROJECT_SOURCE_DIR}/lib/projects/*.cc)
endif ()
jcl's avatar
jcl committed
93 94 95 96 97 98
# create the library "JCLutils"
add_library (JCLprojects SHARED ${LIBPROJECTS})
if(OSX)
set_target_properties(JCLprojects PROPERTIES LINK_FLAGS "-undefined suppress -flat_namespace")
endif(OSX)
# Destination path for the lib
99
SET(LIBRARY_OUTPUT_PATH lib)
jcl's avatar
jcl committed
100 101 102


# compilation options
103 104
#add_definitions(${OPT} -DNO_CUDA -DfalcON_NEMO -DfalcON_SINGLE  -funroll-loops -Wall ${DNOBOOST})
add_definitions(${OPT} -DNO_CUDA -DfalcON_NEMO -DfalcON_SINGLE  -Wall ${DNOBOOST})
105 106 107
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
108

109 110 111 112
# remove -DNDEBUG in RElease mode to keep activated assert calls
STRING(REPLACE "-DNDEBUG" ""  CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
message (STATUS "CMAKE_CXX_FLAGS_RELEASE = " ${CMAKE_CXX_FLAGS_RELEASE}  )

jcl's avatar
jcl committed
113
# Executbale output path
114
set(EXECUTABLE_OUTPUT_PATH bin)
jcl's avatar
jcl committed
115 116 117
MESSAGE( STATUS "EXECUTABLE_OUTPUT_PATH: " ${EXECUTABLE_OUTPUT_PATH} )

# Make sure the compiler can find include files from our Hello library.
118 119 120
include_directories (${PROJECT_SOURCE_DIR}/src )
include_directories (${PROJECT_SOURCE_DIR}/lib/utils ${PROJECT_SOURCE_DIR}/lib/utils/nemodep )
include_directories (${PROJECT_SOURCE_DIR}/lib/projects ${PROJECT_SOURCE_DIR}/lib/projects/nemodep)
121
include_directories (/usr/include/CCfits /usr/include/cfitsio)
122
include_directories (${EXTRA_INCLUDES})
123 124 125
if ( FALCON_INSTALLED )
  include_directories (${DEHNEN}/falcON/utils/inc ${DEHNEN}/falcON/inc)
endif()
126
include_directories (${UNSIOPATH}/lib ${UNSIOPATH}/include ${UNSIOPATH}/include/uns $ENV{NEMO}/inc $ENV{NEMO}/lib)
127
include_directories (/usr/include/malloc)
jcl's avatar
jcl committed
128 129

# Make sure the linker can find the Hello library once it is built.
130
link_directories ( ${UNSIOPATH}/${LIB_SUFFIX} ${UNSIOPATH}/lib ${UNSIOPATH}/lib64 ${DEHNEN}/falcON/lib ${DEHNEN}/utils/lib $ENV{PGPLOT_DIR}  ${G2C_DIR} ${PROJECT_BINARY_DIR}/lib /usr/lib64 /usr/X11/lib ${FC_GFORT_PATH} ${FC_G77_PATH} ${EXTRA_LINK_DIRS})
jcl's avatar
jcl committed
131

jclamber's avatar
jclamber committed
132 133 134 135 136 137
# ----------------------------------------------------------
# Install SETUP
# ----------------------------------------------------------

mark_as_advanced(CMAKE_INSTALL_PREFIX)

138 139 140 141 142
if (CMAKE_INSTALL_PREFIX STREQUAL $ENV{NEMO} )
  SET(PREFIX_LIB lib)
else()
  SET(PREFIX_LIB ${LIB_SUFFIX})
endif()
143 144 145
if (NOT CMAKE_INSTALL_PREFIX) 
  set (CMAKE_INSTALL_PREFIX ${UNSIOPATH})
endif()
jclamber's avatar
jclamber committed
146 147
MESSAGE( STATUS "--------> CMAKE_INSTALL_PREFIX =" ${CMAKE_INSTALL_PREFIX})

jclamber's avatar
jclamber committed
148 149 150 151
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
152 153 154 155 156 157
# 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)

158
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${PREFIX_LIB}")
jclamber's avatar
jclamber committed
159 160 161 162 163 164

# 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
165
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/${PREFIX_LIB}" isSystemDir)
jclamber's avatar
jclamber committed
166
IF("${isSystemDir}" STREQUAL "-1")
167
   SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${PREFIX_LIB}")
jclamber's avatar
jclamber committed
168
ENDIF("${isSystemDir}" STREQUAL "-1")
jcl's avatar
jcl committed
169 170 171 172 173

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

174
# Find all exes sources files
jcl's avatar
jcl committed
175

176 177 178 179 180
if ( NEMO_INSTALLED )
   FILE(GLOB execpp_sources ${PROJECT_SOURCE_DIR}/src/*.cc ${PROJECT_SOURCE_DIR}/src/nemodep/*.cc)
else ()
   FILE(GLOB execpp_sources ${PROJECT_SOURCE_DIR}/src/*.cc)
endif ()
jcl's avatar
jcl committed
181 182 183 184 185 186 187
# 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})

188 189
 #
  if ( NEMO_INSTALLED )
190
         target_link_libraries (${exe} JCLprojects JCLutils cpgplot pgplot.a ${FC_GFORT_LIB} ${FC_G77_LIB}  CCfits cfitsio X11 nemo unsio WDutils falcON gomp ${LIBBOOST} pthread dl)
191
  else ()
192
	  target_link_libraries (${exe} JCLprojects JCLutils ${FC_GFORT_LIB} ${FC_G77_LIB} CCfits cfitsio nemo unsio gomp ${LIBBOOST} dl)
193
  endif ()
jclamber's avatar
jclamber committed
194
  INSTALL(TARGETS ${exe} RUNTIME  DESTINATION bin)
jcl's avatar
jcl committed
195 196 197 198 199 200

ENDFOREACH(exe_cpp ${execpp_sources})

# ----------------------------------------------------------
# install target                                            

jclamber's avatar
jclamber committed
201

jcl's avatar
jcl committed
202 203 204 205 206 207 208 209 210 211 212

IF   (OSX) # Mac OSX
  SET(SOEXT "dylib")
ELSE (OSX) # Linux
  SET(SOEXT "so")
ENDIF(OSX)
# 
# install bin targets
FOREACH(exe_cpp ${execpp_sources})

  get_filename_component(exe ${exe_cpp} NAME_WE)
jclamber's avatar
jclamber committed
213
  #INSTALL(PROGRAMS  ${PROJECT_BINARY_DIR}/bin/${exe}     DESTINATION bin)
jcl's avatar
jcl committed
214
ENDFOREACH(exe_cpp ${execpp_sources})
215 216 217

INSTALL(FILES  ${PROJECT_BINARY_DIR}/lib/libJCLutils.${SOEXT} DESTINATION ${PREFIX_LIB})
INSTALL(FILES  ${PROJECT_BINARY_DIR}/lib/libJCLprojects.${SOEXT} DESTINATION ${PREFIX_LIB})
jclamber's avatar
jclamber committed
218 219 220
INSTALL(FILES  ${PROJECT_SOURCE_DIR}/man/uns_2dplot.1 DESTINATION man/man1)
INSTALL(FILES  ${PROJECT_SOURCE_DIR}/man/uns_stack.1 DESTINATION man/man1)
INSTALL(FILES  ${PROJECT_SOURCE_DIR}/man/uns2uns.1 DESTINATION man/man1)
jclamber's avatar
jclamber committed
221
INSTALL(FILES  ${PROJECT_SOURCE_DIR}/man/uns_projects.1 DESTINATION man/man1)
jclamber's avatar
jclamber committed
222 223
INSTALL(FILES  ${PROJECT_SOURCE_DIR}/lib/utils/nemodep/cfalcon.h DESTINATION inc/uns)
INSTALL(FILES  ${PROJECT_SOURCE_DIR}/lib/utils/csnaptools.h DESTINATION inc/uns)
jclamber's avatar
jclamber committed
224
INSTALL(FILES  ${PROJECT_SOURCE_DIR}/lib/projects/nemodep/crectify.h DESTINATION inc/uns)
jclamber's avatar
jclamber committed
225
INSTALL(FILES  ${PROJECT_SOURCE_DIR}/lib/utils/ctimer.h DESTINATION inc/uns)
jcl's avatar
jcl committed
226
#