-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
189 lines (169 loc) · 7.04 KB
/
CMakeLists.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# CMakeList.txt : Top-level CMake project file for the Modular Aligner MA
# Tips:
# - For getting more information with make: make VERBOSE=1
# - Call cmake with "-DCMAKE_BUILD_TYPE=Debug" for switching to the debug mode
cmake_minimum_required (VERSION 3.8)
project("MA" VERSION 2.0.2 DESCRIPTION "MA - The Modular Aligner")
# optional features
option(WITH_PYTHON "Build python integration of libMS." ON)
option(WITH_ZLIB "Build gz file readers using zlib." ON)
option(WITH_DOCS "Build doxygen documentation." OFF)
option(WITH_GUI "Build maGUI" OFF)
option(WITH_DB "Build Database connector and dependant modules (required for MSV)." ON)
# assert that the compiler knows c++17
if ( NOT "cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
message( FATAL_ERROR "Your compiler does not support C++17, which is required for compiling MA. "
"(Updating your compiler will likely fix this issue.)" )
endif()
# Collect all arguments of the CMake call (just for info purposes ...)
get_cmake_property(CACHE_VARS CACHE_VARIABLES)
foreach(CACHE_VAR ${CACHE_VARS})
get_property(CACHE_VAR_HELPSTRING CACHE ${CACHE_VAR} PROPERTY HELPSTRING)
if(CACHE_VAR_HELPSTRING STREQUAL "No help, variable specified on the command line.")
get_property(CACHE_VAR_TYPE CACHE ${CACHE_VAR} PROPERTY TYPE)
if(CACHE_VAR_TYPE STREQUAL "UNINITIALIZED")
set(CACHE_VAR_TYPE)
else()
set(CACHE_VAR_TYPE :${CACHE_VAR_TYPE})
endif()
set(CMAKE_ARGS "${CMAKE_ARGS} -D${CACHE_VAR}${CACHE_VAR_TYPE}=\"${${CACHE_VAR}}\"")
endif()
endforeach()
# Print info about the current call/environment of CMake
message("// CC = \"${CMAKE_CC_COMPILER_ID}\"")
message("// CXX = \"${CMAKE_CXX_COMPILER_ID}\"")
# message("// CMAKE_ARGS: ${CMAKE_ARGS}")
message("// CMAKE_BUILD_TYPE = \"${CMAKE_BUILD_TYPE}\"")
# message("// CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}")
message("// CMAKE_CXX_FLAGS_DEBUG = ${CMAKE_CXX_FLAGS_DEBUG}")
message("// CMAKE_CXX_FLAGS_RELEASE = ${CMAKE_CXX_FLAGS_RELEASE}")
message("// CMAKE_CXX_FLAGS_RELWITHDEBINFO = ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
# message("// CMAKE_CXX_FLAGS_MINSIZEREL = ${CMAKE_CXX_FLAGS_MINSIZEREL}")
if( CMAKE_BUILD_TYPE STREQUAL "" )
# Switch to the release mode, so that we get full optimization
message( "Build type set to \"Release\"" )
set( CMAKE_BUILD_TYPE "Release" )
endif()
# Currently, the debug_level settings effect all projects (incl. kswcpp)
if( CMAKE_BUILD_TYPE STREQUAL "Debug" )
# Set the debug level
message( "Set debug level to 1" )
add_definitions( "-DDEBUG_LEVEL=1" )
if( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" )
# In the debug mode the code comprises unsed variables.
# Corresponding warning will be switched off.
message( "Add -Wno-unused-variable for gcc")
add_compile_options( "-Wno-unused-variable" )
elseif( MSVC )
# FOr MSVC with have to adapt the RelWithDebInfo setting in order to avoid linking problems
set( CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MDd /Zi /O2 /Ob2")
message("CMAKE_CXX_FLAGS_RELWITHDEBINFO changed to ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
endif()
endif()
if( CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO" )
if( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" )
set( CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O0 -g -DNDEBUG")
elseif( MSVC )
# FOr MSVC with have to adapt the RelWithDebInfo setting in order to avoid linking problems
set( CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MDd /Zi /O2 /Ob2")
message("CMAKE_CXX_FLAGS_RELWITHDEBINFO changed to ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
endif()
endif()
# Testing with cmake
# https://stackoverflow.com/questions/50468620/what-does-enable-testing-do-in-cmake
option(ENABLE_TESTS "Enable tests" ON)
if (${ENABLE_TESTS})
include(CTest)
endif()
# Add additional general compile flags
# Note: Some flags are already preset by the generator depending on the build-type
# TODO: use set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -foo" )
if( NOT MSVC )
# Note: Adding "-Wextra" delivers more warnings
# "-Werror" "-Wall" : All warnings enabled and warning are treated as errors
add_compile_options( "-Wall" )
if( CMAKE_BUILD_TYPE STREQUAL "Debug" )
#add_compile_options( "-Werror" )
endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# Clang prefers libc++ over libstdc++
add_compile_options( "-stdlib=libc++" )
# Regarding the linker, there can be chosen among ld(gnu) and lld(llvm).
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=ld -stdlib=libc++")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=ld -stdlib=libc++")
endif()
elseif( (CMAKE_BUILD_TYPE MATCHES "Debug") )
# For fixing the fatal error C1128 if using MSVC and debug builds
add_compile_options( /bigobj )
endif()
if(WITH_PYTHON)
# Look for Python
set(requested_python_version 3.5)
find_package( PythonLibs ${requested_python_version} )
if( PythonLibs_FOUND )
message( "Found Python Libs")
endif()
endif()
if(WITH_ZLIB)
# Look for zlib
find_package( ZLIB )
if( ZLIB_FOUND )
message( "Found zlib" )
endif()
endif()
# Required for linking via libpthreads on UNIX systems
# set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
# Use Cpp 17 standard
if (NOT MSVC)
set(PYBIND11_CPP_STANDARD -std=c++17)
else()
set(PYBIND11_CPP_STANDARD /std:c++17)
endif()
set(CMAKE_CXX_STANDARD 17)
# Build all required contributor libraries
add_subdirectory ( contrib )
# Build all required libraries
add_subdirectory ( libs )
# Build wxWidgets GUI
if(WITH_GUI)
add_subdirectory ( gui )
endif()
if(WITH_DOCS)
# check if Doxygen is installed
find_package(Doxygen)
if (DOXYGEN_FOUND)
set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/doxygen.config)
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/doxygen.config.out)
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
# note the option ALL which allows to build the docs together with the application
add_custom_target( docs-cpp
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM )
else (DOXYGEN_FOUND)
message("Doxygen needs to be installed in order to generate a cpp documentation")
endif (DOXYGEN_FOUND)
# determine wether pdoc can be called from the command line
execute_process (
COMMAND pdoc --version
RESULT_VARIABLE PDOC_FOUND
)
# if so create the docs-py target
if (${PDOC_FOUND} EQUAL 0)
add_custom_target( docs-py
COMMAND pdoc --html --force -o build/docs/py libMS libMA libMSV
DEPENDS MA
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with pdoc"
VERBATIM )
else()
message("pdoc needs to be installed in order to generate a python documentation")
endif()
endif()
# Build the MA executable itself
add_executable ( maCMD cmdMa.cpp )
# Link cmdMA
target_link_libraries ( maCMD PUBLIC libMA Threads::Threads )
target_compile_definitions( maCMD PUBLIC DLL_PORT_MA=dllimport )