i2pd/build/CMakeLists.txt

204 lines
7.0 KiB
CMake
Raw Normal View History

2014-12-31 21:05:54 +03:00
cmake_minimum_required ( VERSION 2.8.5 )
2014-09-17 04:16:39 +04:00
project ( "i2pd" )
2014-04-03 23:54:43 +04:00
2014-09-17 04:16:39 +04:00
# configurale options
option(WITH_AESNI "Use AES-NI instructions set" OFF)
option(WITH_HARDENING "Use hardening compiler flags" OFF)
2014-12-12 16:46:07 +03:00
option(WITH_LIBRARY "Build library" ON)
option(WITH_BINARY "Build binary" ON)
2014-12-12 16:46:07 +03:00
option(WITH_STATIC "Static build" OFF)
2014-04-03 23:54:43 +04:00
2014-09-17 04:16:39 +04:00
# paths
set ( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules" )
set ( CMAKE_SOURCE_DIR ".." )
2014-12-12 16:46:07 +03:00
set (COMMON_SRC
2014-12-02 18:34:02 +03:00
"${CMAKE_SOURCE_DIR}/AddressBook.cpp"
2014-09-17 04:16:39 +04:00
"${CMAKE_SOURCE_DIR}/CryptoConst.cpp"
"${CMAKE_SOURCE_DIR}/Garlic.cpp"
"${CMAKE_SOURCE_DIR}/I2NPProtocol.cpp"
"${CMAKE_SOURCE_DIR}/Identity.cpp"
"${CMAKE_SOURCE_DIR}/LeaseSet.cpp"
"${CMAKE_SOURCE_DIR}/Log.cpp"
"${CMAKE_SOURCE_DIR}/NTCPSession.cpp"
2015-04-09 19:45:00 +03:00
"${CMAKE_SOURCE_DIR}/NetDbRequests.cpp"
2014-09-17 04:16:39 +04:00
"${CMAKE_SOURCE_DIR}/NetDb.cpp"
2015-03-24 19:47:57 +03:00
"${CMAKE_SOURCE_DIR}/Profiling.cpp"
2014-09-17 04:16:39 +04:00
"${CMAKE_SOURCE_DIR}/Reseed.cpp"
"${CMAKE_SOURCE_DIR}/RouterContext.cpp"
"${CMAKE_SOURCE_DIR}/RouterInfo.cpp"
"${CMAKE_SOURCE_DIR}/SSU.cpp"
"${CMAKE_SOURCE_DIR}/SSUData.cpp"
2014-12-12 16:46:07 +03:00
"${CMAKE_SOURCE_DIR}/SSUSession.cpp"
2014-09-17 04:16:39 +04:00
"${CMAKE_SOURCE_DIR}/Streaming.cpp"
"${CMAKE_SOURCE_DIR}/Destination.cpp"
2014-09-17 04:16:39 +04:00
"${CMAKE_SOURCE_DIR}/TransitTunnel.cpp"
"${CMAKE_SOURCE_DIR}/Tunnel.cpp"
"${CMAKE_SOURCE_DIR}/TunnelGateway.cpp"
"${CMAKE_SOURCE_DIR}/Transports.cpp"
"${CMAKE_SOURCE_DIR}/TunnelEndpoint.cpp"
"${CMAKE_SOURCE_DIR}/TunnelPool.cpp"
"${CMAKE_SOURCE_DIR}/aes.cpp"
"${CMAKE_SOURCE_DIR}/base64.cpp"
"${CMAKE_SOURCE_DIR}/util.cpp"
2015-04-08 20:21:49 +03:00
"${CMAKE_SOURCE_DIR}/Datagram.cpp"
2015-05-11 12:56:13 +03:00
"${CMAKE_SOURCE_DIR}/Signature.cpp"
2014-12-12 16:46:07 +03:00
)
2015-06-06 11:33:15 +03:00
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
list (APPEND COMMON_SRC "${CMAKE_SOURCE_DIR}/I2PEndian.cpp")
endif ()
2015-05-11 12:56:13 +03:00
add_library(common ${COMMON_SRC})
2014-12-12 16:46:07 +03:00
set (DAEMON_SRC
2014-12-02 18:34:02 +03:00
"${CMAKE_SOURCE_DIR}/BOB.cpp"
2014-10-22 23:30:25 +04:00
"${CMAKE_SOURCE_DIR}/ClientContext.cpp"
2014-12-12 16:46:07 +03:00
"${CMAKE_SOURCE_DIR}/Daemon.cpp"
"${CMAKE_SOURCE_DIR}/HTTPProxy.cpp"
"${CMAKE_SOURCE_DIR}/HTTPServer.cpp"
"${CMAKE_SOURCE_DIR}/I2PService.cpp"
2015-01-07 21:26:44 +03:00
"${CMAKE_SOURCE_DIR}/I2PControl.cpp"
2014-12-12 16:46:07 +03:00
"${CMAKE_SOURCE_DIR}/I2PTunnel.cpp"
"${CMAKE_SOURCE_DIR}/SAM.cpp"
"${CMAKE_SOURCE_DIR}/SOCKS.cpp"
"${CMAKE_SOURCE_DIR}/UPnP.cpp"
"${CMAKE_SOURCE_DIR}/i2p.cpp"
)
set (LIBRARY_SRC
"${CMAKE_SOURCE_DIR}/api.cpp"
2014-04-03 23:54:43 +04:00
)
2014-09-17 04:16:39 +04:00
file (GLOB HEADERS "${CMAKE_SOURCE_DIR}/*.h")
# MSVS grouping
source_group ("Header Files" FILES ${HEADERS})
2014-12-12 16:46:07 +03:00
source_group ("Source Files" FILES ${COMMON_SRC} ${DAEMON_SRC} ${LIBRARY_SRC})
2014-09-17 04:16:39 +04:00
# Default build is Debug
if (CMAKE_BUILD_TYPE STREQUAL "Release")
add_definitions( "-pedantic" )
2014-04-23 22:48:02 +04:00
else ()
2014-09-17 04:16:39 +04:00
set(CMAKE_BUILD_TYPE Debug)
2014-04-23 22:48:02 +04:00
endif ()
2014-09-17 04:16:39 +04:00
# compiler flags customization (by vendor)
2015-06-06 11:33:15 +03:00
if (NOT MSVC)
2014-12-12 16:46:07 +03:00
add_definitions ( "-Wall -Wextra -fPIC" )
2015-06-06 11:33:15 +03:00
endif ()
# check for c++11 support
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" CXX11_SUPPORTED)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" CXX0X_SUPPORTED)
if (CXX11_SUPPORTED)
2014-09-17 07:30:12 +04:00
add_definitions( "-std=c++11" )
elseif (CXX0X_SUPPORTED) # gcc 4.6
add_definitions( "-std=c++0x" )
2015-06-06 11:33:15 +03:00
elseif (NOT MSVC)
message(SEND_ERROR "C++11 standart not seems to be supported by compiler. Too old version?")
endif ()
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
2014-09-17 04:16:39 +04:00
if (WITH_HARDENING)
add_definitions( "-D_FORTIFY_SOURCE=2" )
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat -Wformat-security -Werror=format-security" )
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector --param ssp-buffer-size=4" )
endif ()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# more tweaks
2014-09-17 04:16:39 +04:00
endif ()
2014-04-23 22:48:02 +04:00
2014-09-17 04:16:39 +04:00
# compiler flags customization (by system)
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
2014-12-12 16:46:07 +03:00
list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/DaemonLinux.cpp")
# "'sleep_for' is not a member of 'std::this_thread'" in gcc 4.7/4.8
add_definitions( "-D_GLIBCXX_USE_NANOSLEEP=1" )
2014-09-17 04:16:39 +04:00
elseif (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
2014-12-12 16:46:07 +03:00
list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/DaemonLinux.cpp")
2014-09-17 09:10:03 +04:00
# "'sleep_for' is not a member of 'std::this_thread'" in gcc 4.7/4.8
add_definitions( "-D_GLIBCXX_USE_NANOSLEEP=1" )
2014-12-12 16:46:07 +03:00
elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/DaemonLinux.cpp")
2014-09-17 04:16:39 +04:00
elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows")
2014-12-12 16:46:07 +03:00
list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/DaemonWin32.cpp")
2015-06-06 11:33:15 +03:00
list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/Win32/Win32Service.cpp")
2014-09-17 04:16:39 +04:00
endif ()
2014-04-23 22:48:02 +04:00
2014-09-17 04:16:39 +04:00
if (WITH_AESNI)
add_definitions ( "-maes -DAESNI" )
endif()
2014-09-17 04:16:39 +04:00
# libraries
2014-04-03 23:54:43 +04:00
find_package ( Threads REQUIRED )
2015-06-06 11:33:15 +03:00
if (WITH_STATIC)
set(Boost_USE_STATIC_LIBS ON)
endif ()
find_package ( Boost COMPONENTS system filesystem regex program_options date_time REQUIRED )
if(NOT DEFINED Boost_INCLUDE_DIRS)
2014-09-17 04:16:39 +04:00
message(SEND_ERROR "Boost is not found, or your boost version was bellow 1.46. Please download Boost!")
endif()
2014-09-17 04:16:39 +04:00
find_package ( CryptoPP REQUIRED )
if(NOT DEFINED CRYPTO++_INCLUDE_DIR)
2014-09-17 04:16:39 +04:00
message(SEND_ERROR "Could not find Crypto++. Please download and install it first!")
endif()
2014-09-17 04:16:39 +04:00
# load includes
2014-12-11 10:57:46 +03:00
include_directories( ${Boost_INCLUDE_DIRS} ${CRYPTO++_INCLUDE_DIR} "${CMAKE_SOURCE_DIR}/..")
2014-09-17 04:16:39 +04:00
# show summary
message(STATUS "---------------------------------------")
message(STATUS "Build type : ${CMAKE_BUILD_TYPE}")
2014-09-17 07:00:18 +04:00
message(STATUS "Compiler vendor : ${CMAKE_CXX_COMPILER_ID}")
message(STATUS "Compiler version : ${CMAKE_CXX_COMPILER_VERSION}")
2014-09-17 07:00:18 +04:00
message(STATUS "Compiler path : ${CMAKE_CXX_COMPILER}")
2014-09-17 04:16:39 +04:00
message(STATUS "Install prefix: : ${CMAKE_INSTALL_PREFIX}")
message(STATUS "Options:")
message(STATUS " AESNI : ${WITH_AESNI}")
message(STATUS " HARDENING : ${WITH_HARDENING}")
2014-12-12 16:46:07 +03:00
message(STATUS " LIBRARY : ${WITH_LIBRARY}")
message(STATUS " BINARY : ${WITH_BINARY}")
2014-12-12 16:46:07 +03:00
message(STATUS " STATIC BUILD : ${WITH_STATIC}")
2014-09-17 04:16:39 +04:00
message(STATUS "---------------------------------------")
2014-12-31 21:05:54 +03:00
#Handle paths nicely
include(GNUInstallDirs)
if (WITH_BINARY)
2015-05-11 12:56:13 +03:00
add_executable ( "${PROJECT_NAME}-bin" ${DAEMON_SRC} )
2015-06-06 11:33:15 +03:00
if(NOT MSVC) # FIXME: incremental linker file name (.ilk) collision for dll & exe
set_target_properties("${PROJECT_NAME}-bin" PROPERTIES OUTPUT_NAME "${PROJECT_NAME}")
2015-06-06 11:33:15 +03:00
endif()
2014-04-03 23:54:43 +04:00
if (WITH_HARDENING AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set_target_properties("${PROJECT_NAME}-bin" PROPERTIES LINK_FLAGS "-z relro -z now" )
endif ()
2014-04-03 23:54:43 +04:00
if (WITH_STATIC)
set(BUILD_SHARED_LIBS OFF)
set_target_properties("${PROJECT_NAME}-bin" PROPERTIES LINK_FLAGS "-static" )
2015-06-06 11:33:15 +03:00
else()
add_definitions(-DBOOST_ALL_DYN_LINK)
endif ()
2014-12-12 16:46:07 +03:00
2015-05-11 12:56:13 +03:00
target_link_libraries( "${PROJECT_NAME}-bin" common ${Boost_LIBRARIES} ${CRYPTO++_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} )
2014-09-17 04:16:39 +04:00
install(TARGETS "${PROJECT_NAME}-bin" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
2015-06-06 11:33:15 +03:00
install(FILES $<TARGET_PDB_FILE:${PROJECT_NAME}-bin> DESTINATION "bin" CONFIGURATIONS DEBUG)
endif ()
2014-12-11 10:57:46 +03:00
2014-12-12 16:46:07 +03:00
if (WITH_LIBRARY)
2015-06-06 11:33:15 +03:00
if (MSVC)
# FIXME: DLL would not have any symbols unless we use __declspec(dllexport) through out the code
add_library(${PROJECT_NAME} ${LIBRARY_SRC})
else ()
2015-05-11 12:56:13 +03:00
add_library(${PROJECT_NAME} SHARED ${LIBRARY_SRC})
2015-06-06 11:33:15 +03:00
target_link_libraries( ${PROJECT_NAME} common ${Boost_LIBRARIES} ${CRYPTO++_LIBRARIES})
endif ()
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
2014-12-11 10:57:46 +03:00
endif ()