1+
12cmake_minimum_required (VERSION 3.18)
23
34if (POLICY CMP0042)
@@ -8,43 +9,43 @@ if(POLICY CMP0025)
89 cmake_policy (SET CMP0025 NEW) # CMake 3.0
910endif ()
1011
11- PROJECT (spimage)
12+ project (spimage)
1213
13- INCLUDE (CTest)
14- ENABLE_TESTING ()
15- IF (BUILD_TESTING)
16- SET (BUILDNAME "${BUILDNAME} " CACHE STRING "Name of build on the dashboard" )
17- MARK_AS_ADVANCED (BUILDNAME)
18- ENDIF (BUILD_TESTING )
14+ include (CTest)
15+ enable_testing ()
16+ if (BUILD_TESTING)
17+ set (BUILDNAME "${BUILDNAME} " CACHE STRING "Name of build on the dashboard" )
18+ mark_as_advanced (BUILDNAME)
19+ endif ( )
1920
2021
21- SET (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR} /cmake/Modules/" )
22+ set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR} /cmake/Modules/" )
2223
2324# Make sure that while building this library the include files are not
2425# built with export prefix
25- ADD_DEFINITIONS (-D SPIMAGE_NO_DLL)
26+ add_definitions (-D SPIMAGE_NO_DLL)
2627
27- IF (WIN32 )
28- # ADD_DEFINITIONS (-D_HDF5USEDLL_)
29- ADD_DEFINITIONS (-D_CRT_SECURE_NO_DEPRECATE)
28+ if (WIN32 )
29+ # add_definitions (-D_HDF5USEDLL_)
30+ add_definitions (-D_CRT_SECURE_NO_DEPRECATE)
3031# Required for compilign with MSVC as documented in
3132# USING_HDF5_VS.txt from the hdf group
3233add_definitions (-DH5_BUILT_AS_DYNAMIC_LIB)
33- ENDIF ( WIN32 )
34+ endif ( )
3435
35- IF (CMAKE_COMPILER_IS_GNUCC)
36- SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=c99" )
37- ENDIF (CMAKE_COMPILER_IS_GNUCC )
36+ if (CMAKE_COMPILER_IS_GNUCC)
37+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=c99" )
38+ endif ( )
3839
39-
40+
4041
41- SET (BUILD_STATIC_LIB CACHE BOOL "If ON output static library. Otherwise output shared libraries." )
42- SET (INCLUDE_DEPENDENCIES CACHE BOOL "[EXPERIMENTAL] If ON embed dependent libraries." )
43- SET (DMALLOC_USE OFF CACHE BOOL "If ON link to dmalloc library if possible." )
44- SET (DOUBLE_PRECISION OFF CACHE BOOL "If ON use double precision. Otherwise use single precision" )
45- SET (SP_MEM_DEBUG OFF CACHE BOOL "If ON use memory debugging code." )
46- SET (USE_CUDA ON CACHE BOOL "If ON try to use CUDA." )
47- SET (PYTHON_WRAPPERS ON CACHE BOOL "If ON try to build python wrappers." )
42+ set (BUILD_STATIC_LIB CACHE BOOL "If ON output static library. Otherwise output shared libraries." )
43+ set (INCLUDE_DEPENDENCIES CACHE BOOL "[EXPERIMENTAL] If ON embed dependent libraries." )
44+ set (DMALLOC_USE OFF CACHE BOOL "If ON link to dmalloc library if possible." )
45+ set (DOUBLE_PRECISION OFF CACHE BOOL "If ON use double precision. Otherwise use single precision" )
46+ set (SP_MEM_DEBUG OFF CACHE BOOL "If ON use memory debugging code." )
47+ set (USE_CUDA ON CACHE BOOL "If ON try to use CUDA." )
48+ set (PYTHON_WRAPPERS ON CACHE BOOL "If ON try to build python wrappers." )
4849
4950find_package (TIFF)
5051find_package (FFTW3 REQUIRED)
@@ -68,20 +69,20 @@ if(PYTHON_WRAPPERS)
6869 endif ()
6970 find_package (SWIG)
7071 if (PYTHON_LIBRARIES AND SWIG_FOUND AND PYTHON_EXECUTABLE AND PYTHON_NUMPY_FOUND)
71- SET (PYTHON_INSTDIR ${Python3_SITELIB} CACHE PATH "Installation directory for python module." )
72+ set (PYTHON_INSTDIR ${Python3_SITELIB} CACHE PATH "Installation directory for python module." )
7273 mark_as_advanced (PYTHON_INSTDIR)
7374 endif ()
74- endif (PYTHON_WRAPPERS )
75- IF (USE_CUDA)
75+ endif ()
76+ if (USE_CUDA)
7677 find_package (CUDAToolkit)
77- IF (CUDAToolkit_BIN_DIR)
78- SET (CUDA_FOUND TRUE )
79- ELSE (CUDAToolkit_BIN_DIR )
80- SET (CUDA_FOUND FALSE )
81- ENDIF (CUDAToolkit_BIN_DIR )
82- IF (CUDA_FOUND)
78+ if (CUDAToolkit_BIN_DIR)
79+ set (CUDA_FOUND TRUE )
80+ else ( )
81+ set (CUDA_FOUND FALSE )
82+ endif ( )
83+ if (CUDA_FOUND)
8384 enable_language (CUDA)
84- ADD_DEFINITIONS (-D_USE_CUDA)
85+ add_definitions (-D_USE_CUDA)
8586 # Set a reasonable minimum arch
8687 if (CUDAToolkit_VERSION_MAJOR GREATER 11)
8788 set (CMAKE_CUDA_ARCHITECTURES "50" CACHE STRING "CUDA architectures to build for" )
@@ -91,95 +92,95 @@ IF(USE_CUDA)
9192 set (CMAKE_CUDA_ARCHITECTURES "30" CACHE STRING "CUDA architectures to build for" )
9293 endif ()
9394 message (STATUS "CUDA found. Using CUDA." )
94- ELSE (CUDA_FOUND)
95+ else (CUDA_FOUND)
9596 message (STATUS "CUDA not found. Not using CUDA." )
96- ENDIF (CUDA_FOUND)
97- ELSE (USE_CUDA)
98- UNSET (CUDA_FOUND)
99- ENDIF (USE_CUDA)
97+ endif (CUDA_FOUND)
98+ else (USE_CUDA)
99+ unset (CUDA_FOUND)
100+ endif (USE_CUDA)
100101
101102# Offer the user the choice of overriding the installation directories
102- INCLUDE (GNUInstallDirs)
103- IF (NOT DEFINED CMAKE_INSTALL_LIBDIR)
104- SET (CMAKE_INSTALL_LIBDIR lib)
105- ENDIF (NOT DEFINED CMAKE_INSTALL_LIBDIR)
106-
107- IF (DOUBLE_PRECISION)
108- ADD_DEFINITIONS (-D_SP_DOUBLE_PRECISION)
109- ELSE (DOUBLE_PRECISION)
110- ADD_DEFINITIONS (-D_SP_SINGLE_PRECISION)
111- ENDIF (DOUBLE_PRECISION)
112-
113- IF (SP_MEM_DEBUG)
114- ADD_DEFINITIONS (-D_SP_MEM_DEBUG)
115- ENDIF (SP_MEM_DEBUG)
116-
117-
118- IF (DMALLOC_USE)
119- FIND_LIBRARY (DMALLOC_LIBRARY dmalloc /usr/lib /sw/lib)
120- FIND_PATH (DMALLOC_INCLUDE_DIR dmalloc.h PATHS /usr/include /sw/include )
121- IF (DMALLOC_LIBRARY)
122- ADD_DEFINITIONS (-D_USE_DMALLOC)
123- SET (LINK_TO_DMALLOC 1)
124- ENDIF (DMALLOC_LIBRARY)
125- ENDIF (DMALLOC_USE)
103+ include (GNUInstallDirs)
104+ if (NOT DEFINED CMAKE_INSTALL_LIBDIR)
105+ set (CMAKE_INSTALL_LIBDIR lib)
106+ endif ()
107+
108+ if (DOUBLE_PRECISION)
109+ add_definitions (-D_SP_DOUBLE_PRECISION)
110+ else (DOUBLE_PRECISION)
111+ add_definitions (-D_SP_SINGLE_PRECISION)
112+ endif (DOUBLE_PRECISION)
113+
114+ if (SP_MEM_DEBUG)
115+ add_definitions (-D_SP_MEM_DEBUG)
116+ endif (SP_MEM_DEBUG)
117+
118+ if (DMALLOC_USE)
119+ find_library (DMALLOC_LIBRARY dmalloc /usr/lib /sw/lib)
120+ find_path (DMALLOC_INCLUDE_DIR dmalloc.h PATHS /usr/include /sw/include )
121+ if (DMALLOC_LIBRARY)
122+ add_definitions (-D_USE_DMALLOC)
123+ set (LINK_TO_DMALLOC 1)
124+ endif (DMALLOC_LIBRARY)
125+ endif (DMALLOC_USE)
126126
127127
128128# when building, don't use the install RPATH already
129129# (but later on when installing)
130- SET (CMAKE_BUILD_WITH_INSTALL_RPATH FALSE )
130+ set (CMAKE_BUILD_WITH_INSTALL_RPATH FALSE )
131131
132- IF (APPLE )
132+ if (APPLE )
133133 # There's a problem with install_name_tool which cannot
134134 # handle duplicate rpaths, so we'll take the calculated risk
135135 # of not including rpaths in the build on macosx
136- SET (CMAKE_SKIP_BUILD_RPATH TRUE )
137- ELSE (APPLE )
138- SET (CMAKE_SKIP_BUILD_RPATH FALSE )
139- ENDIF (APPLE )
136+ set (CMAKE_SKIP_BUILD_RPATH TRUE )
137+ else (APPLE )
138+ set (CMAKE_SKIP_BUILD_RPATH FALSE )
139+ endif (APPLE )
140140
141141# add the automatically determined parts of the RPATH
142142# which point to directories outside the build tree to the install RPATH
143- SET (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE )
143+ set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE )
144144
145145# the RPATH to be used when installing, but only if it's not a system directory
146- LIST (FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES ${CMAKE_INSTALL_LIBDIR} isSystemDir)
147- IF ("${isSystemDir} " STREQUAL "-1" )
148- SET (CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_LIBDIR} )
149- ENDIF ("${isSystemDir} " STREQUAL "-1" )
146+ list (FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES ${CMAKE_INSTALL_LIBDIR} isSystemDir)
147+ if ("${isSystemDir} " STREQUAL "-1" )
148+ set (CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_LIBDIR} )
149+ endif ("${isSystemDir} " STREQUAL "-1" )
150150
151151
152152configure_file (${PROJECT_SOURCE_DIR} /include /config.h.in
153153 ${PROJECT_BINARY_DIR} /config.h)
154154include_directories ("${PROJECT_BINARY_DIR} " )
155155
156156
157- INCLUDE_DIRECTORIES (${FFTW3_INCLUDE_DIR} ${PNG_INCLUDE_DIR} ${TIFF_INCLUDE_DIR} ${HDF5_INCLUDE_DIR} ${GSL_INCLUDE_DIR} )
158- INCLUDE_DIRECTORIES (BEFORE "${CMAKE_SOURCE_DIR} /include/" )
159- IF (CUDA_FOUND)
160- INCLUDE_DIRECTORIES (${CUDA_INCLUDE_DIRS} )
161- ENDIF (CUDA_FOUND)
162-
163- LIST (APPEND TESTS_LIBRARIES ${TIFF_LIBRARIES} ${FFTW3_LIBRARIES} ${PNG_LIBRARIES} ${HDF5_LIBRARIES} ${GSL_LIBRARIES} )
164- LIST (APPEND SPIMAGE_LIBRARIES ${TIFF_LIBRARIES} ${FFTW3_LIBRARIES} ${PNG_LIBRARIES} ${HDF5_LIBRARIES} )
165-
166- IF (LINK_TO_DMALLOC)
167- LIST (APPEND SPIMAGE_LIBRARIES ${DMALLOC_LIBRARY} )
168- LIST (APPEND TESTS_LIBRARIES ${DMALLOC_LIBRARY} )
169- ENDIF (LINK_TO_DMALLOC)
170-
171- LIST (APPEND SPIMAGE_SRC "${CMAKE_SOURCE_DIR} /src/image_util.c" "${CMAKE_SOURCE_DIR} /src/fft.c" "${CMAKE_SOURCE_DIR} /src/linear_alg.c" )
172- LIST (APPEND SPIMAGE_SRC "${CMAKE_SOURCE_DIR} /src/mem_util.c" "${CMAKE_SOURCE_DIR} /src/image_sphere.c" "${CMAKE_SOURCE_DIR} /src/sperror.c" )
173- LIST (APPEND SPIMAGE_SRC "${CMAKE_SOURCE_DIR} /src/gaussianinv.c" "${CMAKE_SOURCE_DIR} /src/image_noise.c" "${CMAKE_SOURCE_DIR} /src/hashtable.c" )
174- LIST (APPEND SPIMAGE_SRC "${CMAKE_SOURCE_DIR} /src/interpolation_kernels.c" "${CMAKE_SOURCE_DIR} /src/time_util.c" )
175- LIST (APPEND SPIMAGE_SRC "${CMAKE_SOURCE_DIR} /src/list.c" "${CMAKE_SOURCE_DIR} /src/prtf.c" "${CMAKE_SOURCE_DIR} /src/phasing.c" )
176- LIST (APPEND SPIMAGE_SRC "${CMAKE_SOURCE_DIR} /src/colormap.c" "${CMAKE_SOURCE_DIR} /src/cuda_util.c" "${CMAKE_SOURCE_DIR} /src/support_update.c" )
177- LIST (APPEND SPIMAGE_SRC "${CMAKE_SOURCE_DIR} /src/image_io.c" "${CMAKE_SOURCE_DIR} /src/image_filter.c" )
178- LIST (APPEND SPIMAGE_SRC "${CMAKE_SOURCE_DIR} /src/find_center.c" )
179-
180- ADD_SUBDIRECTORY (src)
181- ADD_SUBDIRECTORY (include )
157+ include_directories (${FFTW3_INCLUDE_DIR} ${PNG_INCLUDE_DIR} ${TIFF_INCLUDE_DIR} ${HDF5_INCLUDE_DIR} ${GSL_INCLUDE_DIR} )
158+ include_directories (BEFORE "${CMAKE_SOURCE_DIR} /include/" )
159+ if (CUDA_FOUND)
160+ include_directories (${CUDA_INCLUDE_DIRS} )
161+ endif ()
162+
163+
164+ list (APPEND TESTS_LIBRARIES ${TIFF_LIBRARIES} ${FFTW3_LIBRARIES} ${PNG_LIBRARIES} ${HDF5_LIBRARIES} ${GSL_LIBRARIES} )
165+ list (APPEND SPIMAGE_LIBRARIES ${TIFF_LIBRARIES} ${FFTW3_LIBRARIES} ${PNG_LIBRARIES} ${HDF5_LIBRARIES} )
166+
167+ if (LINK_TO_DMALLOC)
168+ list (APPEND SPIMAGE_LIBRARIES ${DMALLOC_LIBRARY} )
169+ list (APPEND TESTS_LIBRARIES ${DMALLOC_LIBRARY} )
170+ endif ()
171+
172+ list (APPEND SPIMAGE_SRC "${CMAKE_SOURCE_DIR} /src/image_util.c" "${CMAKE_SOURCE_DIR} /src/fft.c" "${CMAKE_SOURCE_DIR} /src/linear_alg.c" )
173+ list (APPEND SPIMAGE_SRC "${CMAKE_SOURCE_DIR} /src/mem_util.c" "${CMAKE_SOURCE_DIR} /src/image_sphere.c" "${CMAKE_SOURCE_DIR} /src/sperror.c" )
174+ list (APPEND SPIMAGE_SRC "${CMAKE_SOURCE_DIR} /src/gaussianinv.c" "${CMAKE_SOURCE_DIR} /src/image_noise.c" "${CMAKE_SOURCE_DIR} /src/hashtable.c" )
175+ list (APPEND SPIMAGE_SRC "${CMAKE_SOURCE_DIR} /src/interpolation_kernels.c" "${CMAKE_SOURCE_DIR} /src/time_util.c" )
176+ list (APPEND SPIMAGE_SRC "${CMAKE_SOURCE_DIR} /src/list.c" "${CMAKE_SOURCE_DIR} /src/prtf.c" "${CMAKE_SOURCE_DIR} /src/phasing.c" )
177+ list (APPEND SPIMAGE_SRC "${CMAKE_SOURCE_DIR} /src/colormap.c" "${CMAKE_SOURCE_DIR} /src/cuda_util.c" "${CMAKE_SOURCE_DIR} /src/support_update.c" )
178+ list (APPEND SPIMAGE_SRC "${CMAKE_SOURCE_DIR} /src/image_io.c" "${CMAKE_SOURCE_DIR} /src/image_filter.c" )
179+ list (APPEND SPIMAGE_SRC "${CMAKE_SOURCE_DIR} /src/find_center.c" )
180+
181+ add_subdirectory (src)
182+ add_subdirectory (include )
182183
183184if (GSL_FOUND)
184- ADD_SUBDIRECTORY (tests)
185+ add_subdirectory (tests)
185186endif ()
0 commit comments