Skip to content

Commit

Permalink
codegen-rewrite: building works now
Browse files Browse the repository at this point in the history
stdout of configure and cmake has been beautified
build system has been refactored further
fixed minor bug after minor bug...
  • Loading branch information
mic-e committed Oct 10, 2014
1 parent 23b7c6f commit b0e74b7
Show file tree
Hide file tree
Showing 11 changed files with 250 additions and 176 deletions.
57 changes: 30 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,48 @@ cmake_minimum_required(VERSION 2.8.10)
#git tag --contains=fa7141f => 2.8.8 # compiler version detection
#git tag --contains=fbda7bb => 2.8.10 # find GLEW module

project(openage C CXX)

# main build configuration file

# text art: figlet -f rounded "[SFT] openage" | sed -e 's/\\/\\\\/g'
message("")
message("==============================================================================")
message(" ___ ______ _______ _______ ___")
message("| _)/ _____|_______|_______|_ |")
message("| | ( (____ _____ _ | | ___ ____ _____ ____ _____ ____ _____")
message("| | \\____ \\| ___) | | | | / _ \\| _ \\| ___ | _ \\(____ |/ _ | ___ |")
message("| |_ _____) ) | | | _| | | |_| | |_| | ____| | | / ___ ( (_| | ____|")
message("|___|______/|_| |_| (___| \\___/| __/|_____)_| |_\\_____|\\___ |_____)")
message(" |_| (_____|")
message("")
message(" Welcome to the SFT technologies computer aided openage build system!")
message(" You have chosen, or been chosen, to do the adventurous task of")
message(" compiling openage.")
message(" If you payed attention to the dependency requirements,")
message(" the build process should just work!")
message("")
message(" We hope your expectations will not be disappointed,")
message(" otherwise, contact our support team and the developers:")
message(" * IRC: #sfttech at freenode.org")
message("==============================================================================")
message("")
message("(running cmake...)
___ ______ _______ _______ ___
| _)/ _____|_______|_______|_ |
| | ( (____ _____ _ | | ___ ____ _____ ____ _____ ____ _____
| | \\____ \\| ___) | | | | / _ \\| _ \\| ___ | _ \\(____ |/ _ | ___ |
| |_ _____) ) | | | _| | | |_| | |_| | ____| | | / ___ ( (_| | ____|
|___|______/|_| |_| (___| \\___/| __/|_____)_| |_\\_____|\\___ |_____)
|_| (_____|
Welcome to this SFT technologies computer-aided openage build system!
You have chose, or been chosen, to attempt the daring task of building openage.
If you have installed all the dependencies that are conveniently listed in [building.md], this _might_ work!
If it doesn't, try asking for help in #sfttech on freenode.net
")

project(openage C CXX)

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

# include build configuration modules
include("CTest")

include("${BUILDSYSTEM_DIR}/util.cmake")

include("${BUILDSYSTEM_DIR}/python.cmake")
python_init()
include("${BUILDSYSTEM_DIR}/cpp.cmake")
include("${BUILDSYSTEM_DIR}/version.cmake")
include("${BUILDSYSTEM_DIR}/doxygen.cmake")
include("${BUILDSYSTEM_DIR}/testing.cmake")
include("${BUILDSYSTEM_DIR}/codegen.cmake")

include("${BUILDSYSTEM_DIR}/testing.cmake")
include("${BUILDSYSTEM_DIR}/doxygen.cmake")

include("${BUILDSYSTEM_DIR}/version.cmake")

# currently unused
detect_version()

# include source subdirectories
add_subdirectory("cpp")
add_subdirectory("py")
Expand Down
68 changes: 37 additions & 31 deletions buildsystem/codegen.cmake
Original file line number Diff line number Diff line change
@@ -1,33 +1,39 @@
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}
RESULT_VARIABLE COMMAND_RESULT
)

if(NOT ${COMMAND_RESULT} EQUAL 0)
message(FATAL_ERROR "failed to get codegen filelist via convert script invocation")
endif()


FILE(READ "${CMAKE_BINARY_DIR}/codegen_target_cache" CODEGEN_TARGETS)
FILE(READ "${CMAKE_BINARY_DIR}/codegen_depend_cache" CODEGEN_DEPENDS)
STRING(REGEX REPLACE "\n" ";" CODEGEN_TARGETS "${CODEGEN_TARGETS}")
STRING(REGEX REPLACE "\n" ";" CODEGEN_DEPENDS "${CODEGEN_DEPENDS}")

add_custom_command(OUTPUT ${CODEGEN_TARGETS}
COMMAND ${CODEGEN_INVOCATION} --write-to-sourcedir --touch-file-on-cache-change=${CMAKE_BINARY_DIR} --force-rerun-on-targetcache-change
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
DEPENDS ${CODEGEN_DEPENDS}
COMMENT running code generation
PRE_BUILD
)

foreach(target ${CODEGEN_TARGETS})
if(${target} MATCHES \\.cpp$)
add_sources_absolute(${PROJECT_NAME} ${target})
function(codegen_init)
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}
RESULT_VARIABLE COMMAND_RESULT
)

if(NOT ${COMMAND_RESULT} EQUAL 0)
message(FATAL_ERROR "failed to get codegen filelist via convert script invocation")
endif()
endforeach()

add_custom_target(codegen ALL DEPENDS ${CODEGEN_TARGETS})

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}")

add_custom_command(OUTPUT ${CODEGEN_TARGET_FILES}
COMMAND ${CODEGEN_INVOCATION} --write-to-sourcedir --touch-file-on-cache-change=${CMAKE_CURRENT_LIST_FILE} --force-rerun-on-targetcache-change
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
DEPENDS ${CODEGEN_DEPENDS}
COMMENT running code generation
)

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

add_custom_target(codegen ALL DEPENDS ${CODEGEN_TARGET_FILES})

set(CODEGEN_TARGET_TUS ${CODEGEN_TARGET_TUS} PARENT_SCOPE)
endfunction()

codegen_init()
128 changes: 79 additions & 49 deletions buildsystem/cpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,78 +2,108 @@

#TODO: integrate PGO (profile-guided optimization) build

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -std=c++11")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS}")
function(cpp_init)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -std=c++11" PARENT_SCOPE)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g" PARENT_SCOPE)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS}" PARENT_SCOPE)

set(CPP_SOURCE_DIR "${CMAKE_SOURCE_DIR}/cpp")
set(CPP_SOURCE_DIR "${CMAKE_SOURCE_DIR}/cpp" PARENT_SCOPE)

message("compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
message("compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
message("")

function(require_cxx_version CXXNAME MINIMAL)
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${MINIMAL})
message(FATAL_ERROR ">=${CXXNAME}-${MINIMAL} required (c++11, you know?), you have ${CMAKE_CXX_COMPILER_VERSION}")
endif()
endfunction()

macro(cxx_required CXXNAME MINIMAL)
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${MINIMAL})
message(FATAL_ERROR ">=${CXXNAME}-${MINIMAL} required (c++11, you know?), you have ${CMAKE_CXX_COMPILER_VERSION}")
# check for compiler versions
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
require_cxx_version("gcc" 4.8)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
require_cxx_version("clang" 3.3)
else() #"Intel", "MSVC", etc..
message(WARNING "Using untested compiler, at least I hope it's free software. Continue on your own, warrior.")
endif()
endmacro()

# check for compiler versions
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
cxx_required("gcc" 4.8)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
cxx_required("clang" 3.3)
else() #"Intel", "MSVC", etc..
message(WARNING "Using untested compiler, at least I hope it's free software. Continue on your own, warrior.")
endif()

# output binary definition helpers.
# allows to add sources to a binary from anywhere.

# create a new 'empty' binary
function(create_binary binary_name)
endfunction()

# declare a new 'empty' executable file.
# 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_BINARY_PATH_${binary_name} ${CMAKE_CURRENT_BINARY_DIR}/${binary_name})
endfunction()

# add a source file with current source dir path
# add source files to a binary
#
# by default, the filename is interpreted as relative to the current directory
# to specify absolute filenames, write ABSOLUTE
# to specify a file that will be auto-generated, write GENERATED
function(add_sources binary_name)
set(generated FALSE)

get_property(binary_list GLOBAL PROPERTY SFT_BINARIES)
if(NOT ${binary_list} MATCHES ${binary_name})
message(FATAL_ERROR "adding sources to unknown binary ${binary_name}")
list_contains(contained ${binary_name} ${binary_list})
if(NOT contained)
message(FATAL_ERROR "attempting to add source to unknown binary ${binary_name}")
endif()

foreach(source ${ARGN})
set_property(
GLOBAL APPEND PROPERTY
SFT_BINARY_SRCS_${binary_name}
${CMAKE_CURRENT_SOURCE_DIR}/${source}
)
endforeach()
endfunction()
if(source STREQUAL GENERATED)
set(generated TRUE)
else()
if(NOT IS_ABSOLUTE ${source})
set(source ${CMAKE_CURRENT_SOURCE_DIR}/${source})
endif()

# add sources file with absolute path to a binary
function(add_sources_absolute binary_name)
get_property(binary_list GLOBAL PROPERTY SFT_BINARIES)
if(NOT ${binary_list} MATCHES ${binary_name})
message(FATAL_ERROR "adding source to unknown binary ${binary_name}")
endif()
set_property(
GLOBAL APPEND PROPERTY
SFT_BINARY_SRCS_${binary_name}
${source}
)

foreach(source ${ARGN})
set_property(
GLOBAL APPEND PROPERTY
SFT_BINARY_SRCS_${binary_name}
${source}
)
if(${generated})
set_property(
GLOBAL APPEND PROPERTY
SFT_BINARY_GENERATED_SRCS_${binary_name}
${source}
)
endif()
endif()
endforeach()
endfunction()

# finalize the executable definition,
# no sources can be added to the binary afterwards.
function(define_executable binary_name)
function(finalize_executable binary_name)
get_property(sources GLOBAL PROPERTY SFT_BINARY_SRCS_${binary_name})
get_property(generatedsources GLOBAL PROPERTY SFT_BINARY_GENERATED_SRCS_${binary_name})

# mark the generated sources as GENERATED.
if(generatedsources)
set_source_files_properties(${generatedsources} PROPERTIES GENERATED ON)
endif()

# print overview of the executable's files
message("C++ executable: ${binary_name}")
foreach(source ${sources})
message("\t${source}")
list_contains(contained ${source} ${generatedsources})
if(${contained})
print_filename(${source} "[gen]")
else()
print_filename(${source})
endif()
endforeach()

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

# make the binary depend on codegen iff it has any generated files
if(generatedsources)
add_dependencies(${binary_name} codegen)
endif()
message("")
endfunction()

cpp_init()
45 changes: 25 additions & 20 deletions buildsystem/doxygen.cmake
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
# Doxygen integration

find_package(Doxygen)
if(DOXYGEN_FOUND)
find_file(DOT dot HINTS /usr/bin/dot)
function(doxygen_init)
find_package(Doxygen)
if(DOXYGEN_FOUND)
find_file(DOT dot HINTS /usr/bin/dot)

set(DOT_EXECUTABLE "/bin/false")
set(HAVE_DOT "NO")
set(DOT_EXECUTABLE "/bin/false")
set(HAVE_DOT "NO")

if(NOT ${DOT} STREQUAL "DOT-NOTFOUND")
set(DOT_EXECUTABLE "${DOT}")
set(HAVE_DOT "YES")
message("found dot: ${DOT_EXECUTABLE}")
if(NOT ${DOT} STREQUAL "DOT-NOTFOUND")
set(DOT_EXECUTABLE "${DOT}")
set(HAVE_DOT "YES")
else()
message(WARNING "graphviz dot couldn't be found, you won't have cool graphs in the docs.")
endif()

# adapt doxygen config
configure_file(${BUILDSYSTEM_DIR}/templates/Doxyfile.in ${CMAKE_BINARY_DIR}/Doxyfile @ONLY)

# add doc target
add_custom_target(doc
${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "generating docs with Doxygen" VERBATIM
)
else()
message(WARNING "graphviz dot couldn't be found, you won't have cool graphs in the docs.")
message(WARNING "doxygen couldn't be found, you won't be able to generate docs")
endif()
endfunction()

# adapt doxygen config
configure_file(${BUILDSYSTEM_DIR}/templates/Doxyfile.in ${CMAKE_BINARY_DIR}/Doxyfile @ONLY)

# add doc target
add_custom_target(doc
${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "generating docs with Doxygen" VERBATIM
)
endif()
doxygen_init()
8 changes: 5 additions & 3 deletions buildsystem/python.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function(add_py_package name)
file(GLOB package_sources "${PYTHON_SOURCE_DIR}/${package_path}/*.py")
set_property(GLOBAL PROPERTY SFT_PY_PACKAGE_${name})
foreach(sourcefile ${package_sources})
message("\t${sourcefile}")
print_filename(${sourcefile})
set_property(GLOBAL APPEND PROPERTY SFT_PY_PACKAGE_${name} "${sourcefile}")
endforeach()
message("")
Expand All @@ -71,7 +71,7 @@ function(add_pyext_module name)
set_property(GLOBAL PROPERTY SFT_PY_EXT_MODULE_${name})
foreach(sourcefile ${ARGN})
set(sourcefile "${CMAKE_CURRENT_SOURCE_DIR}/${sourcefile}")
message("\t${sourcefile}")
print_filename(${sourcefile})
set_property(GLOBAL APPEND PROPERTY SFT_PY_EXT_MODULE_${name} "${sourcefile}")
endforeach()
message("")
Expand All @@ -85,7 +85,7 @@ function(python_modules_in_prefix prefix varname)
get_property(packages GLOBAL PROPERTY SFT_PY_PACKAGES)
foreach(package ${packages})
string(FIND "${package}" "${prefix}" match)
if(${match} EQUALS 0)
if(${match} EQUAL 0)
get_property(sourcefiles GLOBAL PROPERTY SFT_PY_PACKAGE_${package})
foreach(sourcefile ${sourcefiles})
list(APPEND modules "${sourcefile}")
Expand Down Expand Up @@ -149,3 +149,5 @@ function(process_python_modules)
# * evaluate the temporary install destination parameter DESTDIR at 'make install'-time
install(CODE "execute_process(COMMAND ${PYTHON3} ${SETUP_PY} install --prefix=${CMAKE_INSTALL_PREFIX} --root=\$ENV{DESTDIR})")
endfunction()

python_init()
Loading

0 comments on commit b0e74b7

Please sign in to comment.