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 build/${CMAKE_BUILD_TYPE}/bin)
30 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY build/${CMAKE_BUILD_TYPE}/lib)
31 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY 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++11 -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++11 -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})
103 IF(IS_DIRECTORY ${curdir}/${child})
104 LIST(APPEND dirlist ${child})
107 SET(${result} ${dirlist})
110 # Definitions (any way to apply only at ldap context ?):
111 add_definitions(-DLDAP_DEPRECATED)
114 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
115 include_directories(/usr/include/libxml2)
116 include_directories(/usr/lib/oracle/12.1/client64/include)
119 SUBDIRLIST(SUBDIRS ${CMAKE_CURRENT_SOURCE_DIR}/source)
120 FOREACH(subdir ${SUBDIRS})
121 message(STATUS "Processing library at: source/${subdir}")
122 file(GLOB_RECURSE SRCS source/${subdir}/*.cpp)
123 add_library(anna_${subdir}_static STATIC ${SRCS})
124 add_library(anna_${subdir}_shared SHARED ${SRCS})
128 file(GLOB_RECURSE DYNAMIC_PROCEDURES ${CMAKE_CURRENT_SOURCE_DIR}/dynamic/launcher/*.cpp)
129 FOREACH(procedure ${DYNAMIC_PROCEDURES})
130 get_filename_component(dirname ${procedure} DIRECTORY)
131 file(RELATIVE_PATH rel ${CMAKE_CURRENT_SOURCE_DIR}/dynamic/launcher ${dirname})
133 string(REGEX REPLACE "/" "_" libpath ${rel})
135 message(STATUS "Processing dynamic library at: dynamic/launcher/${rel}")
136 file(GLOB_RECURSE SRCS dynamic/launcher/${rel}/*.cpp)
137 add_library(anna_launcher_procedure_${libpath}_shared SHARED ${SRCS})
139 set(target_dirname build/${CMAKE_BUILD_TYPE}/lib/dynamic/launcher/${rel})
141 set(target_basename anna_launcher_procedure_${libpath}_shared)
142 set_target_properties(${target_basename} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${target_dirname})
143 #file(RENAME ${target_dirname}/lib${target_basename}.so ${target_dirname}/libprocedure.so)
148 SUBDIRLIST(MODULES ${CMAKE_CURRENT_SOURCE_DIR}/example)
149 FOREACH(module ${MODULES})
150 SUBDIRLIST(SUBDIRS ${CMAKE_CURRENT_SOURCE_DIR}/example/${module})
151 FOREACH(subdir ${SUBDIRS})
152 message(STATUS "Processing executable at: example/${module}/${subdir}")
155 file(GLOB_RECURSE SRCS ${CMAKE_CURRENT_SOURCE_DIR}/example/${module}/${subdir}/*.cpp)
158 set(target "anna_${module}_${subdir}")
159 add_executable(${target} ${SRCS})
160 set_target_properties(${target} PROPERTIES LINKER_LANGUAGE CXX)
161 set(libraries_file "${CMAKE_CURRENT_SOURCE_DIR}/example/${module}/${subdir}/libraries.txt")
162 set(includes_file "${CMAKE_CURRENT_SOURCE_DIR}/example/${module}/${subdir}/includes.txt")
164 if(EXISTS "${includes_file}")
165 file (STRINGS "${includes_file}" HDRS)
166 # Include own example directory:
167 target_include_directories(${target} PUBLIC
168 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/example/${module}/${subdir}>
171 #message(STATUS "Header directory: ${HDR}")
172 target_include_directories(${target} PUBLIC
173 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${HDR}>
178 if(EXISTS "${libraries_file}")
179 file (STRINGS "${libraries_file}" LIBS)
180 #message(STATUS "Libraries: ${LIBS}")
181 target_link_libraries(${target} ${LIBS})
193 include_directories(${GTEST_INCLUDE_DIRS})
195 SUBDIRLIST(MODULES ${CMAKE_CURRENT_SOURCE_DIR}/test)
196 FOREACH(module ${MODULES})
198 message(STATUS "Processing basic test at: test/${module}")
201 file(GLOB_RECURSE SRCS ${CMAKE_CURRENT_SOURCE_DIR}/test/${module}/*.cpp)
204 set(target "anna_test_${module}")
205 add_executable(${target} ${SRCS})
206 target_link_libraries(${target} ${GTEST_BOTH_LIBRARIES} pthread)
207 set(libraries_file "${CMAKE_CURRENT_SOURCE_DIR}/test/${module}/libraries.txt")
209 if(EXISTS "${libraries_file}")
210 file (STRINGS "${libraries_file}" LIBS)
211 #message(STATUS "Libraries: ${LIBS}")
212 target_link_libraries(${target} ${GTEST_BOTH_LIBRARIES} pthread ${LIBS})
215 add_test(${target} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${target})
222 SET(MY_OWN_INSTALL_PREFIX "/opt/anna" CACHE PATH "Prefix prepended to install directories")
223 SET(CMAKE_INSTALL_PREFIX "${MY_OWN_INSTALL_PREFIX}" CACHE INTERNAL "Prefix prepended to install directories" FORCE)
225 message(STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}")
227 file(GLOB_RECURSE BINARIES ${CMAKE_CURRENT_SOURCE_DIR}/build/${CMAKE_BUILD_TYPE}/bin/*)
228 install(PROGRAMS ${BINARIES} DESTINATION bin)
230 install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/anna DESTINATION include)
232 file(GLOB_RECURSE LIBRARIES ${CMAKE_CURRENT_SOURCE_DIR}/build/${CMAKE_BUILD_TYPE}/lib/*)
233 install(FILES ${LIBRARIES} DESTINATION lib)
236 # Add target for API documentation with Doxygen
237 find_package(Doxygen)
239 add_custom_target(doc
240 ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/docs/doxygen/Doxyfile
241 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/docs/doxygen
242 COMMENT "Generating API documentation with Doxygen" VERBATIM