Commit 10b34e38 authored by Philip Quinn's avatar Philip Quinn

CMake: Consistently quote variables that may contain special characters. Fixes #136.

parent 495319e0
project("Cap'n Proto" CXX) project("Cap'n Proto" CXX)
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 2.8)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(CheckIncludeFileCXX) include(CheckIncludeFileCXX)
check_include_file_cxx(initializer_list HAS_CXX11) check_include_file_cxx(initializer_list HAS_CXX11)
......
include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
# Tests ======================================================================== # Tests ========================================================================
...@@ -8,7 +8,7 @@ if(BUILD_TESTING) ...@@ -8,7 +8,7 @@ if(BUILD_TESTING)
# Setup CAPNP_GENERATE_CPP for compiling test schemas # Setup CAPNP_GENERATE_CPP for compiling test schemas
find_package(CapnProto QUIET) find_package(CapnProto QUIET)
set(CAPNP_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}) set(CAPNP_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}")
# Setup googletest build and library targets (gtest and gtest_main) # Setup googletest build and library targets (gtest and gtest_main)
include(ExternalProject) include(ExternalProject)
...@@ -23,21 +23,21 @@ if(BUILD_TESTING) ...@@ -23,21 +23,21 @@ if(BUILD_TESTING)
add_library(gtest UNKNOWN IMPORTED) add_library(gtest UNKNOWN IMPORTED)
set_property(TARGET gtest set_property(TARGET gtest
PROPERTY IMPORTED_LOCATION ${binary_dir}/${CMAKE_FIND_LIBRARY_PREFIXES}gtest.a PROPERTY IMPORTED_LOCATION "${binary_dir}/${CMAKE_FIND_LIBRARY_PREFIXES}gtest.a"
) )
add_dependencies(gtest gtest_build) add_dependencies(gtest gtest_build)
add_library(gtest_main UNKNOWN IMPORTED) add_library(gtest_main UNKNOWN IMPORTED)
set_property(TARGET gtest_main set_property(TARGET gtest_main
PROPERTY IMPORTED_LOCATION ${binary_dir}/${CMAKE_FIND_LIBRARY_PREFIXES}gtest_main.a PROPERTY IMPORTED_LOCATION "${binary_dir}/${CMAKE_FIND_LIBRARY_PREFIXES}gtest_main.a"
) )
add_dependencies(gtest_main gtest) add_dependencies(gtest_main gtest)
ExternalProject_Get_Property(gtest_build source_dir) ExternalProject_Get_Property(gtest_build source_dir)
include_directories(${source_dir}/include) include_directories("${source_dir}/include")
# Sadly, we can't use the 'test' target, as that's coopted by ctest # Sadly, we can't use the 'test' target, as that's coopted by ctest
add_custom_target(check ${CMAKE_CTEST_COMMAND} -V) add_custom_target(check "${CMAKE_CTEST_COMMAND}" -V)
endif() # BUILD_TESTING endif() # BUILD_TESTING
# kj =========================================================================== # kj ===========================================================================
......
...@@ -76,8 +76,8 @@ set(capnp-rpc_headers ...@@ -76,8 +76,8 @@ set(capnp-rpc_headers
if(NOT CAPNP_LITE) if(NOT CAPNP_LITE)
add_library(capnp-rpc ${capnp-rpc_sources}) add_library(capnp-rpc ${capnp-rpc_sources})
target_link_libraries(capnp-rpc kj-async kj) target_link_libraries(capnp-rpc kj-async kj)
install(TARGETS capnp-rpc ARCHIVE DESTINATION ${LIB_INSTALL_DIR}) install(TARGETS capnp-rpc ARCHIVE DESTINATION "${LIB_INSTALL_DIR}")
install(FILES ${capnp-rpc_headers} DESTINATION ${INCLUDE_INSTALL_DIR}/capnp) install(FILES ${capnp-rpc_headers} DESTINATION "${INCLUDE_INSTALL_DIR}/capnp")
endif() endif()
# Tools/Compilers ============================================================== # Tools/Compilers ==============================================================
...@@ -102,8 +102,8 @@ set(capnpc_headers ...@@ -102,8 +102,8 @@ set(capnpc_headers
if(NOT CAPNP_LITE) if(NOT CAPNP_LITE)
add_library(capnpc ${capnpc_sources}) add_library(capnpc ${capnpc_sources})
target_link_libraries(capnpc capnp kj) target_link_libraries(capnpc capnp kj)
install(TARGETS capnpc ARCHIVE DESTINATION ${LIB_INSTALL_DIR}) install(TARGETS capnpc ARCHIVE DESTINATION "${LIB_INSTALL_DIR}")
install(FILES ${capnpc_headers} DESTINATION ${INCLUDE_INSTALL_DIR}/capnp) install(FILES ${capnpc_headers} DESTINATION "${INCLUDE_INSTALL_DIR}/capnp")
endif() endif()
if(BUILD_TOOLS AND NOT CAPNP_LITE) if(BUILD_TOOLS AND NOT CAPNP_LITE)
...@@ -129,7 +129,7 @@ if(BUILD_TOOLS AND NOT CAPNP_LITE) ...@@ -129,7 +129,7 @@ if(BUILD_TOOLS AND NOT CAPNP_LITE)
install(TARGETS capnp_tool capnpc_cpp capnpc_capnp RUNTIME DESTINATION "${BIN_INSTALL_DIR}") install(TARGETS capnp_tool capnpc_cpp capnpc_capnp RUNTIME DESTINATION "${BIN_INSTALL_DIR}")
# Symlink capnpc -> capnp # Symlink capnpc -> capnp
install(CODE "execute_process(COMMAND \"${CMAKE_COMMAND}\" -E create_symlink capnp ${BIN_INSTALL_DIR}/capnpc)") install(CODE "execute_process(COMMAND \"${CMAKE_COMMAND}\" -E create_symlink capnp \"${BIN_INSTALL_DIR}/capnpc\")")
endif() # BUILD_TOOLS AND NOT CAPNP_LITE endif() # BUILD_TOOLS AND NOT CAPNP_LITE
# Tests ======================================================================== # Tests ========================================================================
...@@ -150,7 +150,7 @@ if(BUILD_TESTING) ...@@ -150,7 +150,7 @@ if(BUILD_TESTING)
# the FindCapnProto module; (2) environment variables; or (3) find_program() # the FindCapnProto module; (2) environment variables; or (3) find_program()
if (NOT CAPNP_EXECUTABLE) if (NOT CAPNP_EXECUTABLE)
if (DEFINED ENV{CAPNP}) if (DEFINED ENV{CAPNP})
set(CAPNP_EXECUTABLE $ENV{CAPNP}) set(CAPNP_EXECUTABLE "$ENV{CAPNP}")
else() else()
find_program(CAPNP_EXECUTABLE capnp) find_program(CAPNP_EXECUTABLE capnp)
endif() endif()
...@@ -158,19 +158,19 @@ if(BUILD_TESTING) ...@@ -158,19 +158,19 @@ if(BUILD_TESTING)
if(NOT CAPNPC_CXX_EXECUTABLE) if(NOT CAPNPC_CXX_EXECUTABLE)
if (DEFINED ENV{CAPNPC_CXX}) if (DEFINED ENV{CAPNPC_CXX})
set(CAPNPC_CXX_EXECUTABLE $ENV{CAPNPC_CXX}) set(CAPNPC_CXX_EXECUTABLE "$ENV{CAPNPC_CXX}")
else() else()
# Also search in the same directory that `capnp` was found in # Also search in the same directory that `capnp` was found in
get_filename_component(capnp_dir ${CAPNP_EXECUTABLE} DIRECTORY) get_filename_component(capnp_dir "${CAPNP_EXECUTABLE}" DIRECTORY)
find_program(CAPNPC_CXX_EXECUTABLE capnpc-c++ HINTS ${capnp_dir}) find_program(CAPNPC_CXX_EXECUTABLE capnpc-c++ HINTS "${capnp_dir}")
endif() endif()
endif() endif()
endif() endif()
# Add "/capnp" to match the path used to import the files in the test sources # Add "/capnp" to match the path used to import the files in the test sources
set(CAPNPC_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/test_capnp/capnp) set(CAPNPC_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/test_capnp/capnp")
include_directories(${CMAKE_CURRENT_BINARY_DIR}/test_capnp) # Note: no "/capnp" include_directories("${CMAKE_CURRENT_BINARY_DIR}/test_capnp") # Note: no "/capnp"
file(MAKE_DIRECTORY ${CAPNPC_OUTPUT_DIR}) file(MAKE_DIRECTORY "${CAPNPC_OUTPUT_DIR}")
capnp_generate_cpp(test_capnp_cpp_files test_capnp_h_files ${test_capnp_files}) capnp_generate_cpp(test_capnp_cpp_files test_capnp_h_files ${test_capnp_files})
......
...@@ -46,9 +46,9 @@ set(kj-parse_headers ...@@ -46,9 +46,9 @@ set(kj-parse_headers
parse/char.h parse/char.h
) )
add_library(kj ${kj_sources}) add_library(kj ${kj_sources})
install(TARGETS kj ARCHIVE DESTINATION ${LIB_INSTALL_DIR}) install(TARGETS kj ARCHIVE DESTINATION "${LIB_INSTALL_DIR}")
install(FILES ${kj_headers} DESTINATION ${INCLUDE_INSTALL_DIR}/kj) install(FILES ${kj_headers} DESTINATION "${INCLUDE_INSTALL_DIR}/kj")
install(FILES ${kj-parse_headers} DESTINATION ${INCLUDE_INSTALL_DIR}/kj/parse) install(FILES ${kj-parse_headers} DESTINATION "${INCLUDE_INSTALL_DIR}/kj/parse")
set(kj-async_sources set(kj-async_sources
async.c++ async.c++
...@@ -65,8 +65,8 @@ set(kj-async_headers ...@@ -65,8 +65,8 @@ set(kj-async_headers
if(NOT CAPNP_LITE) if(NOT CAPNP_LITE)
add_library(kj-async ${kj-async_sources}) add_library(kj-async ${kj-async_sources})
target_link_libraries(kj-async kj) target_link_libraries(kj-async kj)
install(TARGETS kj-async ARCHIVE DESTINATION ${LIB_INSTALL_DIR}) install(TARGETS kj-async ARCHIVE DESTINATION "${LIB_INSTALL_DIR}")
install(FILES ${kj-async_headers} DESTINATION ${INCLUDE_INSTALL_DIR}/kj) install(FILES ${kj-async_headers} DESTINATION "${INCLUDE_INSTALL_DIR}/kj")
endif() endif()
# Tests ======================================================================== # Tests ========================================================================
......
...@@ -67,7 +67,7 @@ function(CAPNP_GENERATE_CPP SOURCES HEADERS) ...@@ -67,7 +67,7 @@ function(CAPNP_GENERATE_CPP SOURCES HEADERS)
if(DEFINED CAPNPC_IMPORT_DIRS) if(DEFINED CAPNPC_IMPORT_DIRS)
# Append each directory as a series of '-I' flags in ${include_path} # Append each directory as a series of '-I' flags in ${include_path}
foreach(directory ${CAPNPC_IMPORT_DIRS}) foreach(directory ${CAPNPC_IMPORT_DIRS})
get_filename_component(absolute_path ${directory} ABSOLUTE) get_filename_component(absolute_path "${directory}" ABSOLUTE)
list(APPEND include_path -I ${absolute_path}) list(APPEND include_path -I ${absolute_path})
endforeach() endforeach()
endif() endif()
...@@ -80,42 +80,42 @@ function(CAPNP_GENERATE_CPP SOURCES HEADERS) ...@@ -80,42 +80,42 @@ function(CAPNP_GENERATE_CPP SOURCES HEADERS)
endif() endif()
if(NOT DEFINED CAPNPC_SRC_PREFIX) if(NOT DEFINED CAPNPC_SRC_PREFIX)
set(CAPNPC_SRC_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}) set(CAPNPC_SRC_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}")
endif() endif()
get_filename_component(CAPNPC_SRC_PREFIX ${CAPNPC_SRC_PREFIX} ABSOLUTE) get_filename_component(CAPNPC_SRC_PREFIX "${CAPNPC_SRC_PREFIX}" ABSOLUTE)
set(${SOURCES}) set(${SOURCES})
set(${HEADERS}) set(${HEADERS})
foreach(schema_file ${ARGN}) foreach(schema_file ${ARGN})
get_filename_component(file_path ${schema_file} ABSOLUTE) get_filename_component(file_path "${schema_file}" ABSOLUTE)
get_filename_component(file_dir ${file_path} PATH) get_filename_component(file_dir "${file_path}" PATH)
# Figure out where the output files will go # Figure out where the output files will go
if (NOT DEFINED CAPNPC_OUTPUT_DIR) if (NOT DEFINED CAPNPC_OUTPUT_DIR)
set(output_base ${file_path}) set(output_base "${file_path}")
else() else()
# Output files are placed in CAPNPC_OUTPUT_DIR, at a location as if they were # Output files are placed in CAPNPC_OUTPUT_DIR, at a location as if they were
# relative to CAPNPC_SRC_PREFIX. # relative to CAPNPC_SRC_PREFIX.
string(LENGTH ${CAPNPC_SRC_PREFIX} prefix_len) string(LENGTH "${CAPNPC_SRC_PREFIX}" prefix_len)
string(SUBSTRING ${file_path} 0 ${prefix_len} output_prefix) string(SUBSTRING "${file_path}" 0 ${prefix_len} output_prefix)
if(NOT ${CAPNPC_SRC_PREFIX} STREQUAL ${output_prefix}) if(NOT "${CAPNPC_SRC_PREFIX}" STREQUAL "${output_prefix}")
message(SEND_ERROR "Could not determine output path for '${schema_file}' ('${file_path}') with source prefix '${CAPNPC_SRC_PREFIX}' into '${CAPNPC_OUTPUT_DIR}'.") message(SEND_ERROR "Could not determine output path for '${schema_file}' ('${file_path}') with source prefix '${CAPNPC_SRC_PREFIX}' into '${CAPNPC_OUTPUT_DIR}'.")
endif() endif()
string(SUBSTRING ${file_path} ${prefix_len} -1 output_path) string(SUBSTRING "${file_path}" ${prefix_len} -1 output_path)
set(output_base ${CAPNPC_OUTPUT_DIR}${output_path}) set(output_base "${CAPNPC_OUTPUT_DIR}${output_path}")
endif() endif()
add_custom_command( add_custom_command(
OUTPUT "${output_base}.c++" "${output_base}.h" OUTPUT "${output_base}.c++" "${output_base}.h"
COMMAND ${CAPNP_EXECUTABLE} COMMAND "${CAPNP_EXECUTABLE}"
ARGS compile ARGS compile
-o ${CAPNPC_CXX_EXECUTABLE}${output_dir} -o ${CAPNPC_CXX_EXECUTABLE}${output_dir}
--src-prefix ${CAPNPC_SRC_PREFIX} --src-prefix ${CAPNPC_SRC_PREFIX}
${include_path} ${include_path}
${CAPNPC_FLAGS} ${CAPNPC_FLAGS}
${file_path} ${file_path}
DEPENDS ${schema_file} DEPENDS "${schema_file}"
COMMENT "Compiling Cap'n Proto schema ${schema_file}" COMMENT "Compiling Cap'n Proto schema ${schema_file}"
VERBATIM VERBATIM
) )
...@@ -136,16 +136,16 @@ pkg_check_modules(PKGCONFIG_CAPNP capnp) ...@@ -136,16 +136,16 @@ pkg_check_modules(PKGCONFIG_CAPNP capnp)
pkg_check_modules(PKGCONFIG_CAPNP_RPC capnp-rpc QUIET) pkg_check_modules(PKGCONFIG_CAPNP_RPC capnp-rpc QUIET)
find_library(CAPNP_LIB_KJ kj find_library(CAPNP_LIB_KJ kj
HINTS ${PKGCONFIG_CAPNP_LIBDIR} ${PKGCONFIG_CAPNP_LIBRARY_DIRS} HINTS "${PKGCONFIG_CAPNP_LIBDIR}" ${PKGCONFIG_CAPNP_LIBRARY_DIRS}
) )
find_library(CAPNP_LIB_KJ-ASYNC kj-async find_library(CAPNP_LIB_KJ-ASYNC kj-async
HINTS ${PKGCONFIG_CAPNP_RPC_LIBDIR} ${PKGCONFIG_CAPNP_RPC_LIBRARY_DIRS} HINTS "${PKGCONFIG_CAPNP_RPC_LIBDIR}" ${PKGCONFIG_CAPNP_RPC_LIBRARY_DIRS}
) )
find_library(CAPNP_LIB_CAPNP capnp find_library(CAPNP_LIB_CAPNP capnp
HINTS ${PKGCONFIG_CAPNP_LIBDIR} ${PKGCONFIG_CAPNP_LIBRARY_DIRS} HINTS "${PKGCONFIG_CAPNP_LIBDIR}" ${PKGCONFIG_CAPNP_LIBRARY_DIRS}
) )
find_library(CAPNP_LIB_CAPNP-RPC capnp-rpc find_library(CAPNP_LIB_CAPNP-RPC capnp-rpc
HINTS ${PKGCONFIG_CAPNP_RPC_LIBDIR} ${PKGCONFIG_CAPNP_RPC_LIBRARY_DIRS} HINTS "${PKGCONFIG_CAPNP_RPC_LIBDIR}" ${PKGCONFIG_CAPNP_RPC_LIBRARY_DIRS}
) )
mark_as_advanced(CAPNP_LIB_KJ CAPNP_LIB_KJ-ASYNC CAPNP_LIB_CAPNP CAPNP_LIB_CAPNP-RPC) mark_as_advanced(CAPNP_LIB_KJ CAPNP_LIB_KJ-ASYNC CAPNP_LIB_CAPNP CAPNP_LIB_CAPNP-RPC)
set(CAPNP_LIBRARIES_LITE set(CAPNP_LIBRARIES_LITE
...@@ -159,26 +159,26 @@ set(CAPNP_LIBRARIES ...@@ -159,26 +159,26 @@ set(CAPNP_LIBRARIES
) )
# Was only the 'lite' library found? # Was only the 'lite' library found?
if(CAPNP_LIB_CAPNP_FOUND AND NOT CAPNP_LIB_CAPNP-RPC_FOUND) if(CAPNP_LIB_CAPNP AND NOT CAPNP_LIB_CAPNP-RPC)
set(CAPNP_DEFINITIONS "-DCAPNP_LITE") set(CAPNP_DEFINITIONS -DCAPNP_LITE)
else() else()
set(CAPNP_DEFINITIONS) set(CAPNP_DEFINITIONS)
endif() endif()
find_path(CAPNP_INCLUDE_DIRS capnp/generated-header-support.h find_path(CAPNP_INCLUDE_DIRS capnp/generated-header-support.h
HINTS ${PKGCONFIG_CAPNP_INCLUDEDIR} ${PKGCONFIG_CAPNP_INCLUDE_DIRS} HINTS "${PKGCONFIG_CAPNP_INCLUDEDIR}" ${PKGCONFIG_CAPNP_INCLUDE_DIRS}
) )
find_program(CAPNP_EXECUTABLE find_program(CAPNP_EXECUTABLE
NAMES capnp NAMES capnp
DOC "Cap'n Proto Command-line Tool" DOC "Cap'n Proto Command-line Tool"
HINTS ${PKGCONFIG_CAPNP_PREFIX}/bin HINTS "${PKGCONFIG_CAPNP_PREFIX}/bin"
) )
find_program(CAPNPC_CXX_EXECUTABLE find_program(CAPNPC_CXX_EXECUTABLE
NAMES capnpc-c++ NAMES capnpc-c++
DOC "Capn'n Proto C++ Compiler" DOC "Capn'n Proto C++ Compiler"
HINTS ${PKGCONFIG_CAPNP_PREFIX}/bin HINTS "${PKGCONFIG_CAPNP_PREFIX}/bin"
) )
# Only *require* the include directory, libkj, and libcapnp. If compiling with # Only *require* the include directory, libkj, and libcapnp. If compiling with
......
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