less assumptions about the generated CMakeLists.txt

This commit is contained in:
Radovan Bast 2015-06-04 14:13:25 +02:00
parent ea10164306
commit 77f6b62829
4 changed files with 25 additions and 30 deletions

View File

@ -1,6 +1,15 @@
# Copyright (c) 2015 by Radovan Bast and Jonas Juselius
# see https://github.com/scisoft/autocmake/blob/master/LICENSE
# generated cmake files will be written to this path
# only build info is generated
# everything else is static for the user
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/generated_by_cmake)
set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
${PROJECT_BINARY_DIR}/generated_by_cmake
)
#-------------------------------------------------------------------------------
function(get_git_info

View File

@ -15,5 +15,9 @@ function(guard_against_bad_build_types in_build_type)
endif()
endfunction()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()
guard_against_in_source(${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR})
guard_against_bad_build_types(${CMAKE_BUILD_TYPE})

9
modules/version.cmake Normal file
View File

@ -0,0 +1,9 @@
# determine program version from file, example: "14.1"
# the reason why this information is stored
# in a file and not as cmake variable
# is that cmake-unaware programs can
# parse and use it (e.g. Sphinx)
if(EXISTS "${PROJECT_SOURCE_DIR}/VERSION")
file(READ "${PROJECT_SOURCE_DIR}/VERSION" PROGRAM_VERSION)
string(STRIP "${PROGRAM_VERSION}" PROGRAM_VERSION)
endif()

View File

@ -166,42 +166,15 @@ def gen_cmakelists(config, relative_path, list_of_modules):
s.append('# do not rebuild if rules (compiler flags) change')
s.append('set(CMAKE_SKIP_RULE_DEPENDENCY TRUE)')
s.append('\n')
s.append('# directory which holds enabled cmake modules')
s.append('set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}')
s.append(' ${PROJECT_SOURCE_DIR}/%s)' % os.path.join(relative_path, 'modules'))
s.append('\n')
s.append('# guards against in-source builds and bad build types')
s.append('if(NOT CMAKE_BUILD_TYPE)')
s.append(' set(CMAKE_BUILD_TYPE "Debug")')
s.append('endif()')
s.append('\n')
s.append('# python interpreter is required at many')
s.append('# places during configuration and build')
s.append('find_package(PythonInterp REQUIRED)')
s.append('\n')
s.append('# determine program version from file, example: "14.1"')
s.append('# the reason why this information is stored')
s.append('# in a file and not as cmake variable')
s.append('# is that cmake-unaware programs can')
s.append('# parse and use it (e.g. Sphinx)')
s.append('if(EXISTS "${PROJECT_SOURCE_DIR}/VERSION")')
s.append(' file(READ "${PROJECT_SOURCE_DIR}/VERSION" PROGRAM_VERSION)')
s.append(' string(STRIP "${PROGRAM_VERSION}" PROGRAM_VERSION)')
s.append('endif()')
s.append('\n')
s.append('# generated cmake files will be written to this path')
s.append('# only build info is generated')
s.append('# everything else is static for the user')
s.append('file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/generated_by_cmake)')
s.append('set(CMAKE_MODULE_PATH')
s.append(' ${CMAKE_MODULE_PATH}')
s.append(' ${PROJECT_BINARY_DIR}/generated_by_cmake')
s.append(' )')
s.append('# directory which holds enabled cmake modules')
s.append('set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}')
s.append(' ${PROJECT_SOURCE_DIR}/%s)' % os.path.join(relative_path, 'modules'))
s.append('\n')
s.append('# included cmake modules')