Add sax converter from json to xml
[anna.git] / CMakeLists.txt
1 # See more at: https://cmake.org/Wiki/CMake_Useful_Variables
2
3 # Stop if cmake version below 2.8
4 cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
5
6 # Project name
7 project(anna)
8
9 # Enable c++ language
10 enable_language(C CXX)
11
12 # Project version
13 set(VERSION_MAJOR 1)
14 set(VERSION_MINOR 0)
15 set(VERSION_PATCH 0)
16
17 # Dynamic libraries not linked to build tree:
18 set(CMAKE_SKIP_RPATH TRUE)
19
20 # Build type:
21 if(NOT CMAKE_BUILD_TYPE)
22   message(WARNING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel.")
23   set(CMAKE_BUILD_TYPE "Release" CACHE STRING
24       "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
25 endif(NOT CMAKE_BUILD_TYPE)
26 message(STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
27
28 # Build output directory:
29 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/build/${CMAKE_BUILD_TYPE}/bin)
30 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/build/${CMAKE_BUILD_TYPE}/lib)
31 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/build/${CMAKE_BUILD_TYPE}/lib)
32 message(STATUS "CMAKE_RUNTIME_OUTPUT_DIRECTORY is ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
33 message(STATUS "CMAKE_LIBRARY_OUTPUT_DIRECTORY is ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
34 message(STATUS "CMAKE_ARCHIVE_OUTPUT_DIRECTORY is ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}")
35
36 # http://stackoverflow.com/questions/6594796/how-do-i-make-cmake-output-into-a-bin-dir
37 #set_target_properties( targets...
38 #    PROPERTIES
39 #    ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
40 #    LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
41 #    RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
42 #)
43
44 # Location of additional cmake modules
45 set(CMAKE_MODULE_PATH
46     ${CMAKE_MODULE_PATH}
47     ${CMAKE_CURRENT_SOURCE_DIR}/cmake
48     )
49
50 # Detect operating system
51 message(STATUS "This is a ${CMAKE_SYSTEM_NAME} system")
52 if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
53     add_definitions(-DSYSTEM_LINUX)
54 endif()
55 if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
56     add_definitions(-DSYSTEM_DARWIN)
57 endif()
58 if(${CMAKE_SYSTEM_NAME} STREQUAL "AIX")
59     add_definitions(-DSYSTEM_AIX)
60 endif()
61
62 # Detect host processor
63 message(STATUS "The host processor is ${CMAKE_HOST_SYSTEM_PROCESSOR}")
64 message(STATUS "The c compiler is ${CMAKE_C_COMPILER}")
65 message(STATUS "The c++ compiler is ${CMAKE_CXX_COMPILER}")
66 message(STATUS "The build type is ${CMAKE_BUILD_TYPE}")
67
68 # Example how to set c++ compiler flags for GNU
69 message(STATUS "CMAKE_CXX_COMPILER_ID = ${CMAKE_CXX_COMPILER_ID}")
70 if(CMAKE_CXX_COMPILER_ID MATCHES GNU)
71     #execute_process(COMMAND g++ --version >/dev/null 2>/dev/null)
72     set(CMAKE_CXX_COMPILER             "/usr/bin/g++")
73     set(CMAKE_CXX_FLAGS                "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wno-deprecated -Wwrite-strings -Wno-unknown-pragmas -Wno-sign-compare -Wno-maybe-uninitialized -Wno-unused -Wno-reorder")
74     set(CMAKE_CXX_FLAGS_DEBUG          "-O0 -g3")
75     set(CMAKE_CXX_FLAGS_MINSIZEREL     "-Os -DNDEBUG")
76     set(CMAKE_CXX_FLAGS_RELEASE        "-O3")
77     set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
78
79 elseif(CMAKE_CXX_COMPILER_ID MATCHES Clang)
80     #execute_process(COMMAND clang++ --version >/dev/null 2>/dev/null)
81     add_definitions(-DIS_CLANG)
82     set(CMAKE_CXX_COMPILER             "/usr/bin/clang++")
83     set(CMAKE_CXX_FLAGS                "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wno-deprecated -Wwrite-strings -Wno-unknown-pragmas -Wno-sign-compare -Wno-maybe-uninitialized -Wno-unused -Wno-reorder -Wno-parentheses-equality")
84     set(CMAKE_CXX_FLAGS_DEBUG          "-O0 -g3")
85     set(CMAKE_CXX_FLAGS_MINSIZEREL     "-Os -DNDEBUG")
86     set(CMAKE_CXX_FLAGS_RELEASE        "-O3")
87     set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
88 endif()
89
90
91 if (CMAKE_BUILD_TYPE STREQUAL Debug)
92     set(BUILD_POSTFIX "_d")
93 else(CMAKE_BUILD_TYPE STREQUAL Debug)
94     set(BUILD_POSTFIX "")
95 endif(CMAKE_BUILD_TYPE STREQUAL Debug)
96
97
98 # Macro to get children directories:
99 MACRO(SUBDIRLIST result curdir)
100   FILE(GLOB children RELATIVE ${curdir} ${curdir}/*)
101   SET(dirlist "")
102   FOREACH(child ${children})
103
104     # EXCLUDE DATABASE RESOURCES (-DSKIP_DATABASE_BUILD)
105     if(SKIP_DATABASE_BUILD)
106        string(REGEX MATCH "dbms|dbos" DATABASE ${child})
107        IF(DATABASE)
108          CONTINUE()
109        ENDIF()
110     ENDIF()
111
112     IF(IS_DIRECTORY ${curdir}/${child})
113       LIST(APPEND dirlist ${child})
114     ENDIF()
115   ENDFOREACH()
116   SET(${result} ${dirlist})
117 ENDMACRO()
118
119 # Definitions (any way to apply only at ldap context ?):
120 add_definitions(-DLDAP_DEPRECATED)
121
122 # General includes:
123 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
124 include_directories(/usr/include/libxml2)
125 include_directories(/usr/include/oracle/19.6/client64)
126
127 # <source>
128 SUBDIRLIST(SUBDIRS ${CMAKE_CURRENT_SOURCE_DIR}/source)
129 FOREACH(subdir ${SUBDIRS})
130   message(STATUS "Processing library at: source/${subdir}")
131   file(GLOB_RECURSE SRCS source/${subdir}/*.cpp)
132   add_library(anna_${subdir}_static STATIC ${SRCS})
133   add_library(anna_${subdir}_shared SHARED ${SRCS})
134 ENDFOREACH()
135
136 # <dynamic>
137 file(GLOB_RECURSE DYNAMIC_PROCEDURES ${CMAKE_CURRENT_SOURCE_DIR}/dynamic/launcher/*.cpp)
138 FOREACH(procedure ${DYNAMIC_PROCEDURES})
139   get_filename_component(dirname ${procedure} DIRECTORY)
140   file(RELATIVE_PATH rel ${CMAKE_CURRENT_SOURCE_DIR}/dynamic/launcher ${dirname})
141   # convert "/" to "_"
142   string(REGEX REPLACE "/" "_" libpath ${rel})
143
144   message(STATUS "Processing dynamic library at: dynamic/launcher/${rel}")
145   file(GLOB_RECURSE SRCS dynamic/launcher/${rel}/*.cpp)
146   add_library(anna_launcher_procedure_${libpath}_shared SHARED ${SRCS})
147
148   set(target_dirname ${CMAKE_CURRENT_SOURCE_DIR}/build/${CMAKE_BUILD_TYPE}/lib/dynamic/launcher/${rel})
149
150   set(target_basename anna_launcher_procedure_${libpath}_shared)
151   set_target_properties(${target_basename} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${target_dirname})
152   #file(RENAME ${target_dirname}/lib${target_basename}.so ${target_dirname}/libprocedure.so)
153 ENDFOREACH()
154
155 # Generalization:
156 # <example>
157 SUBDIRLIST(MODULES ${CMAKE_CURRENT_SOURCE_DIR}/example)
158 FOREACH(module ${MODULES})
159   SUBDIRLIST(SUBDIRS ${CMAKE_CURRENT_SOURCE_DIR}/example/${module})
160   FOREACH(subdir ${SUBDIRS})
161     message(STATUS "Processing executable at: example/${module}/${subdir}")
162
163     # Sources
164     file(GLOB_RECURSE SRCS ${CMAKE_CURRENT_SOURCE_DIR}/example/${module}/${subdir}/*.cpp)
165
166     # Executable
167     set(target "anna_${module}_${subdir}")
168     add_executable(${target} ${SRCS})
169     set_target_properties(${target} PROPERTIES LINKER_LANGUAGE CXX)
170     set(libraries_file "${CMAKE_CURRENT_SOURCE_DIR}/example/${module}/${subdir}/libraries.txt")
171     set(includes_file "${CMAKE_CURRENT_SOURCE_DIR}/example/${module}/${subdir}/includes.txt")
172
173     if(EXISTS "${includes_file}")
174       file (STRINGS "${includes_file}" HDRS)
175       # Include own example directory:
176       target_include_directories(${target} PUBLIC
177         $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/example/${module}/${subdir}>
178       )
179       FOREACH(HDR ${HDRS})
180         #message(STATUS "Header directory: ${HDR}")
181         target_include_directories(${target} PUBLIC
182           $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${HDR}>
183         )
184       ENDFOREACH()
185     endif()
186
187     if(EXISTS "${libraries_file}")
188       file (STRINGS "${libraries_file}" LIBS)
189       #message(STATUS "Libraries: ${LIBS}")
190       target_link_libraries(${target} ${LIBS})
191     endif()
192
193   ENDFOREACH()
194 ENDFOREACH()
195
196
197 # <test>
198 find_package(GTest)
199 IF(GTest_FOUND)
200
201   enable_testing()
202   include_directories(${GTEST_INCLUDE_DIRS})
203
204   SUBDIRLIST(MODULES ${CMAKE_CURRENT_SOURCE_DIR}/test)
205   FOREACH(module ${MODULES})
206
207     message(STATUS "Processing basic test at: test/${module}")
208
209     # Sources
210     file(GLOB_RECURSE SRCS ${CMAKE_CURRENT_SOURCE_DIR}/test/${module}/*.cpp)
211
212     # Executable
213     set(target "anna_test_${module}")
214     add_executable(${target} ${SRCS})
215     target_link_libraries(${target} ${GTEST_BOTH_LIBRARIES} pthread)
216     set(libraries_file "${CMAKE_CURRENT_SOURCE_DIR}/test/${module}/libraries.txt")
217
218     if(EXISTS "${libraries_file}")
219       file (STRINGS "${libraries_file}" LIBS)
220       #message(STATUS "Libraries: ${LIBS}")
221       target_link_libraries(${target} ${GTEST_BOTH_LIBRARIES} pthread ${LIBS})
222     endif()
223
224     add_test(${target} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${target})
225
226   ENDFOREACH()
227 ENDIF(GTest_FOUND)
228
229
230 # Install
231 SET(MY_OWN_INSTALL_PREFIX "/opt/anna" CACHE PATH "Prefix prepended to install directories")
232 SET(CMAKE_INSTALL_PREFIX "${MY_OWN_INSTALL_PREFIX}" CACHE INTERNAL "Prefix prepended to install directories" FORCE)
233
234 message(STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}")
235 # Binaries:
236 file(GLOB_RECURSE BINARIES ${CMAKE_CURRENT_SOURCE_DIR}/build/${CMAKE_BUILD_TYPE}/bin/*)
237 install(PROGRAMS ${BINARIES} DESTINATION bin)
238 # Headers:
239 install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/anna DESTINATION include)
240 # Libraries:
241 file(GLOB_RECURSE LIBRARIES ${CMAKE_CURRENT_SOURCE_DIR}/build/${CMAKE_BUILD_TYPE}/lib/*)
242 install(FILES ${LIBRARIES} DESTINATION lib)
243
244
245 # Add target for API documentation with Doxygen
246 find_package(Doxygen)
247 IF(Doxygen_FOUND)
248   add_custom_target(doc
249     ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/docs/doxygen/Doxyfile
250     WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/docs/doxygen
251     COMMENT "Generating API documentation with Doxygen" VERBATIM
252   )
253 ENDIF(Doxygen_FOUND)
254