1 # See more at: https://cmake.org/Wiki/CMake_Useful_Variables
3 # Stop if cmake version below 2.8
4 cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
10 enable_language(C CXX)
17 # Dynamic libraries not linked to build tree:
18 set(CMAKE_SKIP_RPATH TRUE)
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}")
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}")
36 # http://stackoverflow.com/questions/6594796/how-do-i-make-cmake-output-into-a-bin-dir
37 #set_target_properties( targets...
39 # ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
40 # LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
41 # RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
44 # Location of additional cmake modules
47 ${CMAKE_CURRENT_SOURCE_DIR}/cmake
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)
55 if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
56 add_definitions(-DSYSTEM_DARWIN)
58 if(${CMAKE_SYSTEM_NAME} STREQUAL "AIX")
59 add_definitions(-DSYSTEM_AIX)
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}")
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")
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")
91 if (CMAKE_BUILD_TYPE STREQUAL Debug)
92 set(BUILD_POSTFIX "_d")
93 else(CMAKE_BUILD_TYPE STREQUAL Debug)
95 endif(CMAKE_BUILD_TYPE STREQUAL Debug)
98 # Macro to get children directories:
99 MACRO(SUBDIRLIST result curdir)
100 FILE(GLOB children RELATIVE ${curdir} ${curdir}/*)
102 FOREACH(child ${children})
104 # EXCLUDE DATABASE RESOURCES (-DSKIP_DATABASE_BUILD)
105 if(SKIP_DATABASE_BUILD)
106 string(REGEX MATCH "dbms|dbos" DATABASE ${child})
112 IF(IS_DIRECTORY ${curdir}/${child})
113 LIST(APPEND dirlist ${child})
116 SET(${result} ${dirlist})
119 # Definitions (any way to apply only at ldap context ?):
120 add_definitions(-DLDAP_DEPRECATED)
123 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
124 include_directories(/usr/include/libxml2)
125 include_directories(/usr/include/oracle/19.6/client64)
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})
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})
142 string(REGEX REPLACE "/" "_" libpath ${rel})
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})
148 set(target_dirname ${CMAKE_CURRENT_SOURCE_DIR}/build/${CMAKE_BUILD_TYPE}/lib/dynamic/launcher/${rel})
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)
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}")
164 file(GLOB_RECURSE SRCS ${CMAKE_CURRENT_SOURCE_DIR}/example/${module}/${subdir}/*.cpp)
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")
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}>
180 #message(STATUS "Header directory: ${HDR}")
181 target_include_directories(${target} PUBLIC
182 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${HDR}>
187 if(EXISTS "${libraries_file}")
188 file (STRINGS "${libraries_file}" LIBS)
189 #message(STATUS "Libraries: ${LIBS}")
190 target_link_libraries(${target} ${LIBS})
202 include_directories(${GTEST_INCLUDE_DIRS})
204 SUBDIRLIST(MODULES ${CMAKE_CURRENT_SOURCE_DIR}/test)
205 FOREACH(module ${MODULES})
207 message(STATUS "Processing basic test at: test/${module}")
210 file(GLOB_RECURSE SRCS ${CMAKE_CURRENT_SOURCE_DIR}/test/${module}/*.cpp)
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")
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})
224 add_test(${target} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${target})
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)
234 message(STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}")
236 file(GLOB_RECURSE BINARIES ${CMAKE_CURRENT_SOURCE_DIR}/build/${CMAKE_BUILD_TYPE}/bin/*)
237 install(PROGRAMS ${BINARIES} DESTINATION bin)
239 install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/anna DESTINATION include)
241 file(GLOB_RECURSE LIBRARIES ${CMAKE_CURRENT_SOURCE_DIR}/build/${CMAKE_BUILD_TYPE}/lib/*)
242 install(FILES ${LIBRARIES} DESTINATION lib)
245 # Add target for API documentation with Doxygen
246 find_package(Doxygen)
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