Browse Source

Fix Win32 build with CMake and MSVC

pull/197/head
Mikhail Titov 10 years ago
parent
commit
a3b08c0016
  1. 27
      build/CMakeLists.txt
  2. 27
      build/cmake_modules/FindCryptoPP.cmake

27
build/CMakeLists.txt

@ -45,6 +45,10 @@ set (COMMON_SRC
"${CMAKE_SOURCE_DIR}/Signature.cpp" "${CMAKE_SOURCE_DIR}/Signature.cpp"
) )
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
list (APPEND COMMON_SRC "${CMAKE_SOURCE_DIR}/I2PEndian.cpp")
endif ()
add_library(common ${COMMON_SRC}) add_library(common ${COMMON_SRC})
set (DAEMON_SRC set (DAEMON_SRC
@ -80,7 +84,9 @@ else ()
endif () endif ()
# compiler flags customization (by vendor) # compiler flags customization (by vendor)
if (NOT MSVC)
add_definitions ( "-Wall -Wextra -fPIC" ) add_definitions ( "-Wall -Wextra -fPIC" )
endif ()
# check for c++11 support # check for c++11 support
include(CheckCXXCompilerFlag) include(CheckCXXCompilerFlag)
@ -90,7 +96,7 @@ if (CXX11_SUPPORTED)
add_definitions( "-std=c++11" ) add_definitions( "-std=c++11" )
elseif (CXX0X_SUPPORTED) # gcc 4.6 elseif (CXX0X_SUPPORTED) # gcc 4.6
add_definitions( "-std=c++0x" ) add_definitions( "-std=c++0x" )
else () elseif (NOT MSVC)
message(SEND_ERROR "C++11 standart not seems to be supported by compiler. Too old version?") message(SEND_ERROR "C++11 standart not seems to be supported by compiler. Too old version?")
endif () endif ()
@ -117,6 +123,7 @@ elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/DaemonLinux.cpp") list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/DaemonLinux.cpp")
elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows") elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows")
list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/DaemonWin32.cpp") list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/DaemonWin32.cpp")
list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/Win32/Win32Service.cpp")
endif () endif ()
if (WITH_AESNI) if (WITH_AESNI)
@ -126,6 +133,10 @@ endif()
# libraries # libraries
find_package ( Threads REQUIRED ) find_package ( Threads REQUIRED )
if (WITH_STATIC)
set(Boost_USE_STATIC_LIBS ON)
endif ()
find_package ( Boost COMPONENTS system filesystem regex program_options date_time REQUIRED ) find_package ( Boost COMPONENTS system filesystem regex program_options date_time REQUIRED )
if(NOT DEFINED Boost_INCLUDE_DIRS) if(NOT DEFINED Boost_INCLUDE_DIRS)
message(SEND_ERROR "Boost is not found, or your boost version was bellow 1.46. Please download Boost!") message(SEND_ERROR "Boost is not found, or your boost version was bellow 1.46. Please download Boost!")
@ -159,7 +170,9 @@ include(GNUInstallDirs)
if (WITH_BINARY) if (WITH_BINARY)
add_executable ( "${PROJECT_NAME}-bin" ${DAEMON_SRC} ) add_executable ( "${PROJECT_NAME}-bin" ${DAEMON_SRC} )
if(NOT MSVC) # FIXME: incremental linker file name (.ilk) collision for dll & exe
set_target_properties("${PROJECT_NAME}-bin" PROPERTIES OUTPUT_NAME "${PROJECT_NAME}") set_target_properties("${PROJECT_NAME}-bin" PROPERTIES OUTPUT_NAME "${PROJECT_NAME}")
endif()
if (WITH_HARDENING AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU") if (WITH_HARDENING AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set_target_properties("${PROJECT_NAME}-bin" PROPERTIES LINK_FLAGS "-z relro -z now" ) set_target_properties("${PROJECT_NAME}-bin" PROPERTIES LINK_FLAGS "-z relro -z now" )
@ -168,15 +181,23 @@ if (WITH_BINARY)
if (WITH_STATIC) if (WITH_STATIC)
set(BUILD_SHARED_LIBS OFF) set(BUILD_SHARED_LIBS OFF)
set_target_properties("${PROJECT_NAME}-bin" PROPERTIES LINK_FLAGS "-static" ) set_target_properties("${PROJECT_NAME}-bin" PROPERTIES LINK_FLAGS "-static" )
else()
add_definitions(-DBOOST_ALL_DYN_LINK)
endif () endif ()
target_link_libraries( "${PROJECT_NAME}-bin" common ${Boost_LIBRARIES} ${CRYPTO++_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ) target_link_libraries( "${PROJECT_NAME}-bin" common ${Boost_LIBRARIES} ${CRYPTO++_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} )
install(TARGETS "${PROJECT_NAME}-bin" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) install(TARGETS "${PROJECT_NAME}-bin" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
install(FILES $<TARGET_PDB_FILE:${PROJECT_NAME}-bin> DESTINATION "bin" CONFIGURATIONS DEBUG)
endif () endif ()
if (WITH_LIBRARY) if (WITH_LIBRARY)
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 ()
add_library(${PROJECT_NAME} SHARED ${LIBRARY_SRC}) add_library(${PROJECT_NAME} SHARED ${LIBRARY_SRC})
target_link_libraries( ${PROJECT_NAME} common ) target_link_libraries( ${PROJECT_NAME} common ${Boost_LIBRARIES} ${CRYPTO++_LIBRARIES})
install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ) endif ()
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif () endif ()

27
build/cmake_modules/FindCryptoPP.cmake

@ -12,6 +12,9 @@ else(CRYPTO++_INCLUDE_DIR AND CRYPTO++_LIBRARIES)
/opt/local/include/crypto++ /opt/local/include/crypto++
/opt/local/include/cryptopp /opt/local/include/cryptopp
$ENV{SystemDrive}/Crypto++/include $ENV{SystemDrive}/Crypto++/include
$ENV{CRYPTOPP}
$ENV{CRYPTOPP}/include
${PROJECT_SOURCE_DIR}/../../cryptopp
) )
find_library(CRYPTO++_LIBRARIES NAMES cryptopp find_library(CRYPTO++_LIBRARIES NAMES cryptopp
@ -20,8 +23,32 @@ else(CRYPTO++_INCLUDE_DIR AND CRYPTO++_LIBRARIES)
/usr/local/lib /usr/local/lib
/opt/local/lib /opt/local/lib
$ENV{SystemDrive}/Crypto++/lib $ENV{SystemDrive}/Crypto++/lib
$ENV{CRYPTOPP}/lib
) )
if(MSVC AND NOT CRYPTO++_LIBRARIES) # Give a chance for MSVC multiconfig
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(PLATFORM x64)
else()
set(PLATFORM Win32)
endif()
find_library(CRYPTO++_LIBRARIES_RELEASE NAMES cryptlib cryptopp
PATHS
$ENV{CRYPTOPP}/Win32/Output/Release
${PROJECT_SOURCE_DIR}/../../cryptopp/${PLATFORM}/Output/Release
)
find_library(CRYPTO++_LIBRARIES_DEBUG NAMES cryptlib cryptopp
PATHS
$ENV{CRYPTOPP}/Win32/Output/Debug
${PROJECT_SOURCE_DIR}/../../cryptopp/${PLATFORM}/Output/Debug
)
set(CRYPTO++_LIBRARIES
debug ${CRYPTO++_LIBRARIES_DEBUG}
optimized ${CRYPTO++_LIBRARIES_RELEASE}
CACHE PATH "Path to Crypto++ library" FORCE
)
endif()
if(CRYPTO++_INCLUDE_DIR AND CRYPTO++_LIBRARIES) if(CRYPTO++_INCLUDE_DIR AND CRYPTO++_LIBRARIES)
set(CRYPTO++_FOUND TRUE) set(CRYPTO++_FOUND TRUE)
message(STATUS "Found Crypto++: ${CRYPTO++_INCLUDE_DIR}, ${CRYPTO++_LIBRARIES}") message(STATUS "Found Crypto++: ${CRYPTO++_INCLUDE_DIR}, ${CRYPTO++_LIBRARIES}")

Loading…
Cancel
Save