forked from statisticalbiotechnology/maracluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommonCMake.txt
155 lines (129 loc) · 5.91 KB
/
CommonCMake.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
macro(my_set variable default options)
if(NOT DEFINED ${variable})
set(${variable} ${default} CACHE STRING ${options} FORCE)
endif(NOT DEFINED ${variable})
endmacro(my_set)
# STORE NEWLY SET VARIABLES IN *.h.cmake FILES
macro(load_config_files location)
file(GLOB_RECURSE configurefiles RELATIVE ${location} ${location}/*.cmake )
foreach(i ${configurefiles})
string(REPLACE ".cmake" "" myReplFile "${i}")
configure_file(${location}/${myReplFile}.cmake ${CMAKE_CURRENT_BINARY_DIR}/${myReplFile} @ONLY)
endforeach()
endmacro()
# useful macro
macro(my_find_program progname)
find_program(${progname}_EXECUTABLE ${progname})
if(NOT ${progname}_EXECUTABLE)
message(FATAL_ERROR "${progname} not found" )
endif(NOT ${progname}_EXECUTABLE)
endmacro(my_find_program)
function(get_arch TARGET_ARCH)
# Detect machine architecture, on UNIX:
if(UNIX AND NOT APPLE AND NOT DEFINED ${TARGET_ARCH})
execute_process(COMMAND dpkg --print-architecture
OUTPUT_VARIABLE TARGET_ARCH
OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "Architecture: ${TARGET_ARCH}")
endif(UNIX AND NOT APPLE AND NOT DEFINED ${TARGET_ARCH})
if(APPLE AND NOT DEFINED ${TARGET_ARCH})
execute_process(COMMAND uname -m
OUTPUT_VARIABLE TARGET_ARCH
OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "Architecture: ${TARGET_ARCH}")
endif(APPLE AND NOT DEFINED ${TARGET_ARCH})
endfunction()
###############################################################################
# SET GLOBAL VARIABLES
###############################################################################
# VERSION AND NAMESPACES
set(CPACK_PACKAGE_VERSION_MAJOR "0")
set(CPACK_PACKAGE_VERSION_MINOR "00")
set(CPACK_PACKAGE_VERSION_PATCH "0")
IF(MINGW OR MSVC)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib" ".dll" ${CMAKE_FIND_LIBRARY_SUFFIXES})
set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} ${CMAKE_SOURCE_DIR}/lib/include)
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ${CMAKE_SOURCE_DIR}/lib/lib)
set(WRITABLE_DIR ${XML_REL_PATH})
add_definitions(-D_WIN32)
ELSE(MINGW OR MSVC)
set(CMAKE_INCLUDE_PATH /usr/include ${CMAKE_INCLUDE_PATH})
set(CMAKE_LIBRARY_PATH /usr/lib /usr/lib64 ${CMAKE_LIBRARY_PATH})
set(WRITABLE_DIR ${CMAKE_INSTALL_PREFIX}/${XML_REL_PATH})
ENDIF(MINGW OR MSVC)
IF(MINGW)
IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
SET(MINGW64 1)
SET(MINGW_PATH /usr/x86_64-w64-mingw32/sys-root/mingw/)
SET(MINGW_PACK_NAME win64)
ELSE()
SET(MINGW32 1)
SET(MINGW_PATH /usr/i686-w64-mingw32/sys-root/mingw/)
SET(MINGW_PACK_NAME win32)
ENDIF()
ENDIF(MINGW)
set(PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
#STATIC/DYNAMIC LIBRARY INCLUSION
if(APPLE)
set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
endif()
if(MINGW OR WIN32 OR APPLE)
OPTION(BUILD_SHARED_LIBS "build static binaries." OFF)
OPTION(STATIC "build a static binaries. This is mainly intended for the win32-package and the MACOSX-bundle." ON )
else(MINGW OR WIN32 OR APPLE)
OPTION(STATIC "build a static binaries. This is mainly intended for the win32-package and the MACOSX-bundle." OFF )
endif()
# Link Boost static and single threaded
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME ON)
set(BOOST_MIN_VERSION "1.43.0")
set(Boost_ADDITIONAL_VERSIONS "1.43.0")
###############################################################################
# SET LOCATION OF MODULE FINDERS
###############################################################################
set(CMAKE_MODULE_PATH ${MARACLUSTER_SOURCE_DIR}/cmake)
###############################################################################
# SET SHARED DYNAMIC LINKING LIBRARIES
###############################################################################
# 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;${CMAKE_PREFIX_PATH}/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")
###############################################################################
# SET COMPILER OPTIONS
###############################################################################
IF(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.7")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=10.7")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -mmacosx-version-min=10.7 -lc++")
ENDIF(APPLE)
if(UNIX OR APPLE OR MINGW)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-result -Wno-overflow -Wno-deprecated-declarations")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-result -Wno-overflow -Wno-deprecated-declarations")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -DNDEBUG")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -DNDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -O0 -g")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -O0 -g")
endif()
if(MSVC)
add_definitions (/MP /D _CRT_SECURE_NO_WARNINGS /D _CRT_NONSTDC_NO_DEPRECATE)
# CMake automatically configures VS to use multi threading,
# if boost would use single threading, the auto-linking process of boost would fail.
set(Boost_USE_MULTITHREADED ON)
endif(MSVC)
find_package(OpenMP)
if (OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()