CMakeLists.txt 5.64 KB
Newer Older
1
2
3
4
if(NOT DEFINED PROJECT_NAME)
  cmake_minimum_required(VERSION 3.7.2)
  
  # Project name and version
5
  project(cameo VERSION 1.0.1 LANGUAGES CXX)
6
  #cmake_policy(SET CMP0048 NEW)
7
8
endif()

9
10
11
message("========================================")
message("Project ${PROJECT_NAME}, major version: ${PROJECT_VERSION_MAJOR}, version ${PROJECT_VERSION}")

12
13
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
14
include(FetchContent)
15
16

if(NOT DEFINED BUILD_SHARED_LIBS)
17
18
  option(BUILD_SHARED_LIBS "Building dynamic (ON) or static (OFF)" ON)
  #set(BUILD_SHARED_LIBS True)
19
20
21
22
endif()

if(NOT DEFINED CMAKE_CXX_STANDARD)
  # specify the C++ standard
legoc's avatar
legoc committed
23
  set(CMAKE_CXX_STANDARD 17)
24
25
26
27
28
29
30
31
32
33
34
35
36
  set(CMAKE_CXX_STANDARD_REQUIRED True)
endif()


# fix the RPATH for the linker
#if(not APPLE)
#  set(CMAKE_INSTALL_RPATH $ORIGIN)
#endif()

#------------------------------------------------------------
# Dependencies
#------------------------------------------------------------
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
37
find_package(ZeroMQ REQUIRED)
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
find_package(Rapidjson QUIET)
if(NOT Rapidjson_FOUND)
  message(WARNING "Using Rapidjson from GIT repository")
  FetchContent_Declare(rapidjson
	GIT_REPOSITORY https://github.com/Tencent/rapidjson.git
	GIT_TAG v1.1.0
	GIT_SHALLOW True
	#INSTALL_COMMAND "make install"
	)
  FetchContent_GetProperties(rapidjson)
  FetchContent_Populate(rapidjson)

  set(Rapidjson_ROOT ${rapidjson_SOURCE_DIR})
  find_package(Rapidjson REQUIRED)
endif()
  message(${Rapidjson_INCLUDE_DIRS})
legoc's avatar
legoc committed
54
55
56
#------------------------------------------------------------
# Libraries
#------------------------------------------------------------
57
58
59
60
61

#---------------
# Files
file(GLOB_RECURSE CAMEO_SOURCE_FILES "src/*.cpp")

62
63
add_library(cameo ${CAMEO_SOURCE_FILES})
target_link_libraries(cameo PRIVATE zmq)
64
65
66
67
68
target_include_directories(cameo
  PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/ # all the private headers
  PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> 
  PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
  )
69
70
71
target_include_directories(cameo
    SYSTEM PRIVATE ${Rapidjson_INCLUDE_DIRS}/
)
72
73
#target_include_directories(cameo PRIVATE ${DOCTEST_INCLUDE_DIR})
#target_compile_features(cameo PUBLIC cxx_std_11)
legoc's avatar
legoc committed
74

75
76
77
78
79
80
81
82
83
84
85
86
set_target_properties(cameo PROPERTIES
  SOVERSION ${PROJECT_VERSION_MAJOR}
  VERSION ${PROJECT_VERSION}
  )

#---------------
# Library version
write_basic_package_version_file(cameoConfigVersion.cmake
  COMPATIBILITY SameMajorVersion
  VERSION ${PROJECT_VERSION}
  )

legoc's avatar
legoc committed
87
88
89
90
#------------------------------------------------------------
# Tests
#------------------------------------------------------------

legoc's avatar
legoc committed
91
# Note: execute ctest --verbose to have more details 
legoc's avatar
legoc committed
92
93
enable_testing()
add_subdirectory(tests)
94
95
96
97
98
99
100
101

#------------------------------------------------------------
# Install
#------------------------------------------------------------
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cameoConfigVersion.cmake
  DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake)

# this is to install the headers
102
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ # don't forget the trailing /
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
  DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
  )

# in CMake 3.14 you just need #install(TARGETS cameo)
install(TARGETS cameo
  EXPORT cameoexport
  RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} # windows
    COMPONENT cameo_Runtime
  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} # dynamic
    COMPONENT cameo_Runtime
#    NAMELINK_COMPONENT cameo_Development #from CMake 3.12
  ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} # static
    COMPONENT cameo_Development
  PUBLIC_HEADER  DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
  INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
  )


# This makes the project importable from the install directory
# Put config file in per-project dir (name MUST match), can also
# just go into 'cmake'.
install(EXPORT cameoexport
  DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake
  FILE ${PROJECT_NAME}Config.cmake 
  )
# makes the project importable from the build directory
export(TARGETS cameo FILE ${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake)

# the install_manifest file is created only after the installation....
#install(FILES ${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt
#  DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake
#  RENAME cameo_install_manifest.txt
#  )


#enable_testing()
#add_subdirectory(test)

141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# include(ExternalProject)
# find_package(Git REQUIRED)

# ExternalProject_Add(
#     doctest
#     PREFIX ${CMAKE_BINARY_DIR}/doctest
#     GIT_REPOSITORY https://github.com/onqtam/doctest.git
#     TIMEOUT 10
#     UPDATE_COMMAND ${GIT_EXECUTABLE} pull
#     CONFIGURE_COMMAND ""
#     BUILD_COMMAND ""
#     INSTALL_COMMAND ""
#     LOG_DOWNLOAD ON
# )

# # Expose required variable (DOCTEST_INCLUDE_DIR) to parent scope
# ExternalProject_Get_Property(doctest source_dir)
# set(DOCTEST_INCLUDE_DIR ${source_dir}/doctest CACHE INTERNAL "Path to include folder for doctest")
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174

#include(CMakeFindDependencyMacro)
#find_dependency(
#include("${CMAKE_CURRENT_LIST_DIR}/cameo.cmake")
################ Doc
find_package(Doxygen)
if (DOXYGEN_FOUND)
  # set input and output files
  set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
  set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
  
  # request to configure the file
  configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
  message("Doxygen build started")
  
  # note the option ALL which allows to build the docs together with the application
175
  add_custom_target( cameo_doc 
176
177
178
179
180
181
182
183
184
    COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
    COMMENT "Generating API documentation with Doxygen"
    VERBATIM )
else (DOXYGEN_FOUND)
  message("Doxygen need to be installed to generate the doxygen documentation")
endif (DOXYGEN_FOUND)