Skip to content

Commit

Permalink
Merge pull request #92 from TheJJ/cmakequotes
Browse files Browse the repository at this point in the history
quotes for cmake variables
  • Loading branch information
mic-e committed Nov 3, 2014
2 parents 995e7ef + 013e09f commit f6736cd
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 96 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Expand Up @@ -26,7 +26,7 @@ If it doesn't, consider reporting the issue/asking for help in #sfttech on freen
project(openage C CXX)

set(BUILDSYSTEM_DIR "${CMAKE_SOURCE_DIR}/buildsystem")
set(CMAKE_MODULE_PATH ${BUILDSYSTEM_DIR}/modules/)
set(CMAKE_MODULE_PATH "${BUILDSYSTEM_DIR}/modules/")

# include build configuration modules
include("CTest")
Expand All @@ -46,7 +46,7 @@ include("${BUILDSYSTEM_DIR}/doxygen.cmake")
disallow_in_source_builds()

# create python config file
configure_file(py/openage/config.py.in ${CMAKE_SOURCE_DIR}/py/openage/config.py)
configure_file(py/openage/config.py.in "${CMAKE_SOURCE_DIR}/py/openage/config.py")

# create documentation for cpp and py folders
doxygen_configure(cpp/ py/)
Expand Down
12 changes: 6 additions & 6 deletions buildsystem/assets.cmake
@@ -1,15 +1,15 @@
# Copyright 2014-2014 the openage authors. See copying.md for legal info.

function(init_assets)
set(GLOBAL_ASSET_DIR ${CMAKE_SOURCE_DIR}/assets)
set(INSTALLED_GLOBAL_ASSET_DIR ${CMAKE_INSTALL_PREFIX}/share/openage)
set(GLOBAL_ASSET_DIR "${CMAKE_SOURCE_DIR}/assets")
set(INSTALLED_GLOBAL_ASSET_DIR "${CMAKE_INSTALL_PREFIX}/share/openage")

install(DIRECTORY ${GLOBAL_ASSET_DIR}/
DESTINATION ${INSTALLED_GLOBAL_ASSET_DIR}
install(DIRECTORY "${GLOBAL_ASSET_DIR}/"
DESTINATION "${INSTALLED_GLOBAL_ASSET_DIR}"
PATTERN .gitignore EXCLUDE)

set(GLOBAL_ASSET_DIR ${GLOBAL_ASSET_DIR} PARENT_SCOPE)
set(INSTALLED_GLOBAL_ASSET_DIR ${INSTALLED_GLOBAL_ASSET_DIR} PARENT_SCOPE)
set(GLOBAL_ASSET_DIR "${GLOBAL_ASSET_DIR}" PARENT_SCOPE)
set(INSTALLED_GLOBAL_ASSET_DIR "${INSTALLED_GLOBAL_ASSET_DIR}" PARENT_SCOPE)
endfunction()

init_assets()
26 changes: 13 additions & 13 deletions buildsystem/codegen.cmake
Expand Up @@ -10,11 +10,11 @@ function(codegen_run)
endif()
set_property(GLOBAL PROPERTY SFT_CODEGEN_HAS_BEEN_RUN 1)

set(CODEGEN_INVOCATION ${PYTHON_INVOCATION} -m openage.codegen --target-cache=${CMAKE_BINARY_DIR}/codegen_target_cache --depend-cache=${CMAKE_BINARY_DIR}/codegen_depend_cache --cpp-src-dir=${CPP_SOURCE_DIR})
set(CODEGEN_INVOCATION ${PYTHON_INVOCATION} -m openage.codegen "--target-cache=${CMAKE_BINARY_DIR}/codegen_target_cache" "--depend-cache=${CMAKE_BINARY_DIR}/codegen_depend_cache" "--cpp-src-dir=${CPP_SOURCE_DIR}")

execute_process(COMMAND
${CODEGEN_INVOCATION}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
RESULT_VARIABLE COMMAND_RESULT
)

Expand All @@ -25,32 +25,32 @@ function(codegen_run)

FILE(READ "${CMAKE_BINARY_DIR}/codegen_target_cache" CODEGEN_TARGET_FILES)
FILE(READ "${CMAKE_BINARY_DIR}/codegen_depend_cache" CODEGEN_DEPENDS)
STRING(REGEX REPLACE "\n" ";" CODEGEN_TARGET_FILES "${CODEGEN_TARGET_FILES}")
STRING(REGEX REPLACE "\n" ";" CODEGEN_DEPENDS "${CODEGEN_DEPENDS}")
STRING(REGEX REPLACE "\n" ";" CODEGEN_TARGET_FILES ${CODEGEN_TARGET_FILES})
STRING(REGEX REPLACE "\n" ";" CODEGEN_DEPENDS ${CODEGEN_DEPENDS})
set(CODEGEN_TIMEFILE "${CMAKE_BINARY_DIR}/codegen_timefile")

add_custom_command(
OUTPUT ${CODEGEN_TIMEFILE}
COMMAND ${CODEGEN_INVOCATION} --write-to-sourcedir --touch-file-on-cache-change=${CMAKE_CURRENT_LIST_FILE} --force-rerun-on-targetcache-change
COMMAND ${CMAKE_COMMAND} -E touch ${CODEGEN_TIMEFILE}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT "${CODEGEN_TIMEFILE}"
COMMAND ${CODEGEN_INVOCATION} --write-to-sourcedir "--touch-file-on-cache-change=${CMAKE_CURRENT_LIST_FILE}" --force-rerun-on-targetcache-change
COMMAND "${CMAKE_COMMAND}" -E touch "${CODEGEN_TIMEFILE}"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
DEPENDS ${CODEGEN_DEPENDS}
COMMENT "generating c++ code (via py/openage/codegen)"
)

add_custom_target(codegen DEPENDS ${CODEGEN_TIMEFILE})
add_custom_target(codegen DEPENDS "${CODEGEN_TIMEFILE}")

add_custom_target(cleancodegen
COMMAND ${CODEGEN_INVOCATION} --clean
COMMAND ${CMAKE_COMMAND} -E remove ${CODEGEN_TIMEFILE}
COMMAND "${CMAKE_COMMAND}" -E remove "${CODEGEN_TIMEFILE}"
)

set(CODEGEN_TARGET_TUS)
foreach(target ${CODEGEN_TARGET_FILES})
if(${target} MATCHES \\.cpp$)
list(APPEND CODEGEN_TARGET_TUS ${target})
if("${target}" MATCHES "\\.cpp$")
list(APPEND CODEGEN_TARGET_TUS "${target}")
endif()
endforeach()

set(CODEGEN_TARGET_TUS ${CODEGEN_TARGET_TUS} PARENT_SCOPE)
set(CODEGEN_TARGET_TUS "${CODEGEN_TARGET_TUS}" PARENT_SCOPE)
endfunction()
26 changes: 13 additions & 13 deletions buildsystem/cpp.cmake
Expand Up @@ -31,7 +31,7 @@ endfunction()
# you need to use add_sources to add source files to it, and finalize_executable to finalize it.
# then you can add libraries, include dirs, etc.
function(declare_executable binary_name)
set_property(GLOBAL APPEND PROPERTY SFT_BINARIES ${binary_name})
set_property(GLOBAL APPEND PROPERTY SFT_BINARIES "${binary_name}")
endfunction()

# add source files to a binary
Expand All @@ -43,7 +43,7 @@ function(add_sources binary_name)
set(generated FALSE)

get_property(binary_list GLOBAL PROPERTY SFT_BINARIES)
list_contains(contained ${binary_name} ${binary_list})
list_contains(contained "${binary_name}" "${binary_list}")
if(NOT contained)
message(FATAL_ERROR "attempting to add source to unknown binary ${binary_name}")
endif()
Expand All @@ -52,21 +52,21 @@ function(add_sources binary_name)
if(source STREQUAL GENERATED)
set(generated TRUE)
else()
if(NOT IS_ABSOLUTE ${source})
set(source ${CMAKE_CURRENT_SOURCE_DIR}/${source})
if(NOT IS_ABSOLUTE "${source}")
set(source "${CMAKE_CURRENT_SOURCE_DIR}/${source}")
endif()

set_property(
GLOBAL APPEND PROPERTY
SFT_BINARY_SRCS_${binary_name}
${source}
"SFT_BINARY_SRCS_${binary_name}"
"${source}"
)

if(${generated})
set_property(
GLOBAL APPEND PROPERTY
SFT_BINARY_GENERATED_SRCS_${binary_name}
${source}
"SFT_BINARY_GENERATED_SRCS_${binary_name}"
"${source}"
)
endif()
endif()
Expand All @@ -87,20 +87,20 @@ function(finalize_executable binary_name)
# print overview of the executable's files
message("C++ executable: ${binary_name}")
foreach(source ${sources})
list_contains(contained ${source} ${generatedsources})
list_contains(contained "${source}" "${generatedsources}")
if(contained)
print_filename(${source} "[gen]")
print_filename("${source}" "[gen]")
else()
print_filename(${source})
print_filename("${source}")
endif()
endforeach()

# create the executable
add_executable(${binary_name} ${sources})
add_executable("${binary_name}" ${sources})

# make the binary depend on codegen iff it has any generated files
if(generatedsources)
add_dependencies(${binary_name} codegen)
add_dependencies("${binary_name}" codegen)
endif()
message("")
endfunction()
Expand Down
12 changes: 6 additions & 6 deletions buildsystem/doxygen.cmake
Expand Up @@ -6,7 +6,7 @@
function(doxygen_init)
find_package(Doxygen)
if(DOXYGEN_FOUND)
find_file(DOT dot HINTS /usr/bin/dot)
find_file(DOT dot HINTS "/usr/bin/dot")

if(NOT ${DOT} STREQUAL "DOT-NOTFOUND")
set(DOT_EXECUTABLE "${DOT}" PARENT_SCOPE)
Expand All @@ -18,16 +18,16 @@ function(doxygen_init)
endif()
endif()

set(DOXYGEN_EXECUTABLE ${DOXYGEN_EXECUTABLE} PARENT_SCOPE)
set(DOXYGEN_FOUND ${DOXYGEN_FOUND} PARENT_SCOPE)
set(DOXYGEN_EXECUTABLE "${DOXYGEN_EXECUTABLE}" PARENT_SCOPE)
set(DOXYGEN_FOUND "${DOXYGEN_FOUND}" PARENT_SCOPE)
endfunction()

function(doxygen_configure)
if(DOXYGEN_FOUND)
# add doc target
add_custom_target(doc
${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
"${DOXYGEN_EXECUTABLE}" "${CMAKE_BINARY_DIR}/Doxyfile"
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
COMMENT "generating docs (via Doxygen)"
VERBATIM
)
Expand All @@ -38,7 +38,7 @@ function(doxygen_configure)
endforeach()

# adapt doxygen config
configure_file(${BUILDSYSTEM_DIR}/templates/Doxyfile.in ${CMAKE_BINARY_DIR}/Doxyfile @ONLY)
configure_file("${BUILDSYSTEM_DIR}/templates/Doxyfile.in" "${CMAKE_BINARY_DIR}/Doxyfile" @ONLY)
else()
message(WARNING "doxygen couldn't be found, you won't be able to generate docs")
endif()
Expand Down
68 changes: 34 additions & 34 deletions buildsystem/python.cmake
Expand Up @@ -18,33 +18,32 @@ function(python_init)
# all of those lists will be used to generate setup.py in the generator function

set(PYTHON_SOURCE_DIR "${CMAKE_SOURCE_DIR}/py")
set(PYTHON_SOURCE_DIR ${PYTHON_SOURCE_DIR} PARENT_SCOPE)
set(PYTHON_SOURCE_DIR "${PYTHON_SOURCE_DIR}" PARENT_SCOPE)

set(PYTHON3 ${PYTHON_EXECUTABLE})
set(PYTHON3 ${PYTHON3} PARENT_SCOPE)
set(PYTHON3 "${PYTHON_EXECUTABLE}")
set(PYTHON3 "${PYTHON3}" PARENT_SCOPE)
set(PYTHON_INCLUDE_DIR "${PYTHON_INCLUDE_DIR}" PARENT_SCOPE)
set(PYTHON_LIBRARY "${PYTHON_LIBRARY}" PARENT_SCOPE)
set(PYTHON_VERSION_STRING "${PYTHON_VERSION_STRING}" PARENT_SCOPE)

set(PYTHON_INVOCATION ${PYTHON3} ${BUILDSYSTEM_DIR}/runinenv "PYTHONPATH:prependpath:${PYTHON_SOURCE_DIR}" -- ${PYTHON3})
set(PYTHON_INVOCATION ${PYTHON_INVOCATION} PARENT_SCOPE)
set(PYTHON_INVOCATION "${PYTHON3}" "${BUILDSYSTEM_DIR}/runinenv" "PYTHONPATH:prependpath:${PYTHON_SOURCE_DIR}" -- "${PYTHON3}" PARENT_SCOPE)
endfunction()


function(get_py_module_name var path)
if(NOT IS_ABSOLUTE ${path})
set(path ${CMAKE_CURRENT_SOURCE_DIR}/${path})
if(NOT IS_ABSOLUTE "${path}")
set(path "${CMAKE_CURRENT_SOURCE_DIR}/${path}")
endif()

file(RELATIVE_PATH relpath ${PYTHON_SOURCE_DIR} ${path})
file(RELATIVE_PATH relpath "${PYTHON_SOURCE_DIR}" "${path}")

string(REPLACE "/" "." name ${relpath})
set(${var} ${name} PARENT_SCOPE)
string(REPLACE "/" "." name "${relpath}")
set(${var} "${name}" PARENT_SCOPE)
endfunction()


function(get_py_module_path var name)
string(REPLACE "." "/" relpath ${name})
string(REPLACE "." "/" relpath "${name}")
set(${var} "${PYTHON_SOURCE_DIR}/${relpath}" PARENT_SCOPE)
endfunction()

Expand All @@ -58,39 +57,39 @@ function(add_py_package name)
message("py package: ${name}")
endif()

set_property(GLOBAL APPEND PROPERTY SFT_PY_PACKAGES ${name})
set_property(GLOBAL APPEND PROPERTY SFT_PY_PACKAGES "${name}")

# find all sourcefiles for this package
# this list of sourcefiles is not used directly for building,
# just for determining whether a re-build is neccesary.
get_py_module_path(package_path ${name})
get_py_module_path(package_path "${name}")
file(GLOB package_sources "${package_path}/*.py")
set_property(GLOBAL PROPERTY SFT_PY_PACKAGE_${name})
set_property(GLOBAL PROPERTY "SFT_PY_PACKAGE_${name}")
foreach(sourcefile ${package_sources})
print_filename(${sourcefile})
set_property(GLOBAL APPEND PROPERTY SFT_PY_PACKAGE_${name} "${sourcefile}")
print_filename("${sourcefile}")
set_property(GLOBAL APPEND PROPERTY "SFT_PY_PACKAGE_${name}" "${sourcefile}")
endforeach()
message("")
endfunction()


function(add_pyext_module name)
# check whether the module has already been defined
get_property(module GLOBAL PROPERTY SFT_PY_EXT_MODULE_${name})
get_property(module GLOBAL PROPERTY "SFT_PY_EXT_MODULE_${name}")
if(${module})
message(FATAL_ERROR "py cpp extension module ${name} has already been defined!")
else()
message("py cpp extension module: ${name}")
endif()

set_property(GLOBAL APPEND PROPERTY SFT_PY_EXT_MODULES ${name})
set_property(GLOBAL APPEND PROPERTY SFT_PY_EXT_MODULES "${name}")

# process the user-supplied list of cpp source files
set_property(GLOBAL PROPERTY SFT_PY_EXT_MODULE_${name})
set_property(GLOBAL PROPERTY "SFT_PY_EXT_MODULE_${name}")
foreach(sourcefile ${ARGN})
set(sourcefile "${CMAKE_CURRENT_SOURCE_DIR}/${sourcefile}")
print_filename(${sourcefile})
set_property(GLOBAL APPEND PROPERTY SFT_PY_EXT_MODULE_${name} "${sourcefile}")
print_filename("${sourcefile}")
set_property(GLOBAL APPEND PROPERTY "SFT_PY_EXT_MODULE_${name}" "${sourcefile}")
endforeach()
message("")
endfunction()
Expand All @@ -104,7 +103,7 @@ function(python_modules_in_prefix prefix varname)
foreach(package ${packages})
string(FIND "${package}" "${prefix}" match)
if(${match} EQUAL 0)
get_property(sourcefiles GLOBAL PROPERTY SFT_PY_PACKAGE_${package})
get_property(sourcefiles GLOBAL PROPERTY "SFT_PY_PACKAGE_${package}")
foreach(sourcefile ${sourcefiles})
list(APPEND modules "${sourcefile}")
endforeach()
Expand All @@ -122,7 +121,7 @@ function(process_python_modules)
get_property(packages GLOBAL PROPERTY SFT_PY_PACKAGES)
foreach(package ${packages})
set(pkg_src "${pkg_src} '${package}': [")
get_property(sourcefiles GLOBAL PROPERTY SFT_PY_PACKAGE_${package})
get_property(sourcefiles GLOBAL PROPERTY "SFT_PY_PACKAGE_${package}")
foreach(sourcefile ${sourcefiles})
set(pkg_src "${pkg_src}'${sourcefile}', ")
list(APPEND all_sourcefiles "${sourcefile}")
Expand All @@ -134,7 +133,7 @@ function(process_python_modules)
get_property(modules GLOBAL PROPERTY SFT_PY_EXT_MODULES)
foreach(module ${modules})
set(ext_src "${ext_src} '${module}': [")
get_property(sourcefiles GLOBAL PROPERTY SFT_PY_EXT_MODULE_${module})
get_property(sourcefiles GLOBAL PROPERTY "SFT_PY_EXT_MODULE_${module}")
foreach(sourcefile ${sourcefiles})
set(ext_src "${ext_src}'${sourcefile}', ")
list(APPEND all_sourcefiles "${sourcefile}")
Expand All @@ -146,27 +145,28 @@ function(process_python_modules)
set(SETUP_PY "${CMAKE_BINARY_DIR}/py/setup.py")
set(PY_TIMEFILE "${CMAKE_BINARY_DIR}/py/timefile")

set(SETUP_INVOCATION ${PYTHON3} ${BUILDSYSTEM_DIR}/runinenv CXX=${CMAKE_CXX_COMPILER} CC=${CMAKE_C_COMPILER} -- ${PYTHON3} ${SETUP_PY})
set(SETUP_INVOCATION "${PYTHON3}" "${BUILDSYSTEM_DIR}/runinenv" "CXX=${CMAKE_CXX_COMPILER}" "CC=${CMAKE_C_COMPILER}" -- "${PYTHON3}" "${SETUP_PY}")

# create setup.py file for python module creation
#
# * the time stamp file is used for rebuilding
# * all python-C extensions are built in-place
# so they can be used for imports in the development tree
# * the pure python modules are compiled to pyc
configure_file(${SETUP_PY_IN} ${SETUP_PY})
add_custom_command(OUTPUT ${PY_TIMEFILE}
COMMAND ${SETUP_INVOCATION} build_ext --inplace
COMMAND ${SETUP_INVOCATION} build
COMMAND ${CMAKE_COMMAND} -E touch ${PY_TIMEFILE}
DEPENDS ${all_sourcefiles}
COMMENT "building python modules (via setup.py)")
configure_file("${SETUP_PY_IN}" "${SETUP_PY}")
add_custom_command(OUTPUT "${PY_TIMEFILE}"
COMMAND ${SETUP_INVOCATION} build_ext --inplace
COMMAND ${SETUP_INVOCATION} build
COMMAND ${CMAKE_COMMAND} -E touch "${PY_TIMEFILE}"
DEPENDS ${all_sourcefiles}
COMMENT "building python modules (via setup.py)"
)

add_custom_target(pymodules ALL DEPENDS ${PY_TIMEFILE})
add_custom_target(pymodules ALL DEPENDS "${PY_TIMEFILE}")

add_custom_target(cleanpymodules
COMMAND ${SETUP_INVOCATION} clean --all
COMMAND ${CMAKE_COMMAND} -E remove ${PY_TIMEFILE}
COMMAND ${CMAKE_COMMAND} -E remove "${PY_TIMEFILE}"
)

# create call to setup.py when installing
Expand Down

0 comments on commit f6736cd

Please sign in to comment.