Commit 2db5ef63 authored by Philip Quinn's avatar Philip Quinn

CMake: Update CMakeLists with MSVC compiler flags and paths.

parent 0f9a4777
......@@ -4,7 +4,11 @@ cmake_minimum_required(VERSION 2.8)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(CheckIncludeFileCXX)
check_include_file_cxx(initializer_list HAS_CXX11 "-std=c++11")
if(MSVC)
check_include_file_cxx(initializer_list HAS_CXX11)
else()
check_include_file_cxx(initializer_list HAS_CXX11 "-std=c++11")
endif()
if(NOT HAS_CXX11)
message(SEND_ERROR "Requires a C++11 compiler and standard library.")
endif()
......
......@@ -22,13 +22,28 @@ if(CAPNP_LITE AND BUILD_TOOLS)
message(WARNING "Command-line tools will not be built with CAPNP_LITE.")
endif()
if(CAPNP_LITE)
if(MSVC AND NOT CAPNP_LITE)
message(SEND_ERROR "Building with MSVC is only supported with CAPNP_LITE.")
endif()
if(CAPNP_LITE AND MSVC)
set(CAPNP_LITE_FLAG "/DCAPNP_LITE")
elseif(CAPNP_LITE)
set(CAPNP_LITE_FLAG "-DCAPNP_LITE")
else()
set(CAPNP_LITE_FLAG)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-parameter -std=c++11 -pthread ${CAPNP_LITE_FLAG}")
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Wall ${CAPNP_LITE_FLAG}")
# Statically link with the runtime libraries.
# TODO: This should depend on whether or not Cap'n Proto is being built as a static or shared library.
# When building the tests, this needs to match with how gtest is built as well.
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-parameter -std=c++11 -pthread ${CAPNP_LITE_FLAG}")
endif()
# Source =======================================================================
......@@ -36,25 +51,27 @@ add_subdirectory(src)
# Install ======================================================================
# Variables for pkg-config files
set(prefix "${CMAKE_INSTALL_PREFIX}")
set(exec_prefix "${EXEC_INSTALL_PREFIX}")
set(libdir "${LIB_INSTALL_DIR}")
set(includedir "${INCLUDE_INSTALL_DIR}")
set(PTHREAD_CFLAGS "-pthread")
set(STDLIB_FLAG) # TODO: Unsupported
if(NOT MSVC) # Don't install pkg-config files when building with MSVC
# Variables for pkg-config files
set(prefix "${CMAKE_INSTALL_PREFIX}")
set(exec_prefix "${EXEC_INSTALL_PREFIX}")
set(libdir "${LIB_INSTALL_DIR}")
set(includedir "${INCLUDE_INSTALL_DIR}")
set(PTHREAD_CFLAGS "-pthread")
set(STDLIB_FLAG) # TODO: Unsupported
configure_file(capnp.pc.in "${CMAKE_CURRENT_BINARY_DIR}/capnp.pc" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/capnp.pc" DESTINATION "${LIB_INSTALL_DIR}/pkgconfig")
configure_file(capnp.pc.in "${CMAKE_CURRENT_BINARY_DIR}/capnp.pc" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/capnp.pc" DESTINATION "${LIB_INSTALL_DIR}/pkgconfig")
if(NOT CAPNP_LITE)
configure_file(capnp-rpc.pc.in "${CMAKE_CURRENT_BINARY_DIR}/capnp-rpc.pc" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/capnp-rpc.pc" DESTINATION "${LIB_INSTALL_DIR}/pkgconfig")
endif()
if(NOT CAPNP_LITE)
configure_file(capnp-rpc.pc.in "${CMAKE_CURRENT_BINARY_DIR}/capnp-rpc.pc" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/capnp-rpc.pc" DESTINATION "${LIB_INSTALL_DIR}/pkgconfig")
endif()
unset(STDLIB_FLAG)
unset(PTHREAD_CFLAGS)
unset(includedir)
unset(libdir)
unset(exec_prefix)
unset(prefix)
unset(STDLIB_FLAG)
unset(PTHREAD_CFLAGS)
unset(includedir)
unset(libdir)
unset(exec_prefix)
unset(prefix)
endif()
......@@ -22,15 +22,22 @@ if(BUILD_TESTING)
ExternalProject_Get_Property(gtest_build binary_dir)
add_library(gtest UNKNOWN IMPORTED)
set_property(TARGET gtest
PROPERTY IMPORTED_LOCATION "${binary_dir}/${CMAKE_FIND_LIBRARY_PREFIXES}gtest.a"
)
if(CMAKE_GENERATOR MATCHES "Visual Studio.*")
set_target_properties(gtest PROPERTIES IMPORTED_LOCATION_DEBUG "${binary_dir}/Debug/gtest.lib")
set_target_properties(gtest PROPERTIES IMPORTED_LOCATION_RELEASE "${binary_dir}/Release/gtest.lib")
else()
set_target_properties(gtest PROPERTIES IMPORTED_LOCATION "${binary_dir}/libgtest.a")
endif()
add_dependencies(gtest gtest_build)
add_library(gtest_main UNKNOWN IMPORTED)
set_property(TARGET gtest_main
PROPERTY IMPORTED_LOCATION "${binary_dir}/${CMAKE_FIND_LIBRARY_PREFIXES}gtest_main.a"
)
if(CMAKE_GENERATOR MATCHES "Visual Studio.*")
set_target_properties(gtest_main PROPERTIES IMPORTED_LOCATION_DEBUG "${binary_dir}/Debug/gtest_main.lib")
set_target_properties(gtest_main PROPERTIES IMPORTED_LOCATION_RELEASE "${binary_dir}/Release/gtest_main.lib")
else()
set_target_properties(gtest_main PROPERTIES IMPORTED_LOCATION "${binary_dir}/libgtest_main.a")
endif()
add_dependencies(gtest_main gtest)
ExternalProject_Get_Property(gtest_build source_dir)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment