Skip to content

Commit

Permalink
buildsystem: Fix paths and usage
Browse files Browse the repository at this point in the history
Tweak to find python library
Fix inplacemodules for msvc build
  • Loading branch information
tusharpm committed Jul 9, 2017
1 parent 53e6bb3 commit 102a823
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 73 deletions.
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,12 @@ add_subdirectory(libopenage/)

# Python content (uses the C++ library)
set(PYEXT_LINK_LIBRARY libopenage)
set(PYEXT_CXXFLAGS "${PYEXT_CXXFLAGS} -include \"${CMAKE_SOURCE_DIR}/libopenage/pyinterface/hacks.h\"")
if(MSVC)
set(FORCE_INCLUDE_CXXFLAG "/FI")
else()
set(FORCE_INCLUDE_CXXFLAG "-include ")
endif()
set(PYEXT_CXXFLAGS "${PYEXT_CXXFLAGS} ${FORCE_INCLUDE_CXXFLAG}\"${CMAKE_SOURCE_DIR}/libopenage/pyinterface/hacks.h\"")
add_cython_modules(EMBED NOINSTALL run.py)
add_py_modules(BININSTALL run.py AS openage)
add_subdirectory(openage/)
Expand Down
4 changes: 3 additions & 1 deletion buildsystem/HandleCXXOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ endmacro()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(EXTRA_FLAGS "${EXTRA_FLAGS} -Wall -Wextra -pedantic")
if(NOT MSVC)
set(EXTRA_FLAGS "${EXTRA_FLAGS} -Wall -Wextra -pedantic")
endif()

# check for compiler versions
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
Expand Down
4 changes: 2 additions & 2 deletions buildsystem/HandlePythonOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(PYEXT_CXXFLAGS "${PYEXT_CXXFLAGS} -Wno-#warnings")
endif()

set(PYEXT_LIBRARY "${PYTHON_LIBRARY}")
set(PYEXT_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR};${NUMPY_INCLUDE_DIR}")
set(PYEXT_LIBRARY "${PYTHON_LIBRARIES}")
set(PYEXT_INCLUDE_DIRS "${PYTHON_INCLUDE_DIRS};${NUMPY_INCLUDE_DIR}")

if(NOT CMAKE_PY_INSTALL_PREFIX)
py_exec("import site, os; print(os.path.normpath(site.getsitepackages()[0]))" PREFIX)
Expand Down
2 changes: 1 addition & 1 deletion buildsystem/check_py_file_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def main():
args = cli.parse_args()

with open(args.py_file_list) as fileobj:
listed = set(fileobj.read().strip().split(';'))
listed = set(os.path.normpath(filepath) for filepath in fileobj.read().strip().split(';'))
if listed == {''}:
listed = set()

Expand Down
3 changes: 2 additions & 1 deletion buildsystem/cpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function(add_sources binary_name)
if(NOT IS_ABSOLUTE "${source}")
set(source "${CMAKE_CURRENT_SOURCE_DIR}/${source}")
endif()
file(TO_CMAKE_PATH "${source}" source)

set_property(
GLOBAL APPEND PROPERTY
Expand Down Expand Up @@ -88,7 +89,7 @@ function(finalize_binary target_name output_name type)
message(FATAL_ERROR "finalize_binary flag 'allow_no_undefined' is only valid for libraries!")
endif()

if(NOT "${CMAKE_CXX_FLAGS}" MATCHES "-fsanitize")
if(NOT "${CMAKE_CXX_FLAGS}" MATCHES "-fsanitize" AND NOT MSVC)
if(APPLE)
set(link_flag "-undefined,error")
else()
Expand Down
2 changes: 1 addition & 1 deletion buildsystem/cythonize.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def read_list_from_file(filename):
with open(filename) as fileobj:
data = fileobj.read().strip()

data = data.split(';')
data = [os.path.normpath(filename) for filename in data.split(';')]
if data == ['']:
return []

Expand Down
8 changes: 7 additions & 1 deletion buildsystem/inplacemodules.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2015-2016 the openage authors. See copying.md for legal info.
# Copyright 2015-2017 the openage authors. See copying.md for legal info.

"""
Installs the Python extension modules that were created in the build directory
Expand All @@ -21,6 +21,9 @@ def main():
cli.add_argument("binary_dir", help=(
"the build directory where those files will be found."
))
cli.add_argument("configuration", help=(
"the build configuration like Debug or Release"
))
cli.add_argument("--clean", action="store_true", help=(
"remove instead of creating"
))
Expand All @@ -39,6 +42,9 @@ def main():
sourcefile = module
targetfile = os.path.relpath(module, args.binary_dir)

# If `targetfile` has a configuration component, remove it.
targetfile = os.path.normpath(targetfile.replace(args.configuration, '.'))

if os.path.exists(targetfile):
if args.clean:
print(targetfile)
Expand Down
57 changes: 26 additions & 31 deletions buildsystem/modules/FindPython.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#
# PYTHON_FOUND - True when python was found.
# PYTHON - The full path to the Python interpreter.
# PYTHON_INCLUDE_DIR - Include path for Python extensions.
# PYTHON_LIBRARY - Library and Linker options for Python extensions.
# PYTHON_INCLUDE_DIRS - Include path for Python extensions.
# PYTHON_LIBRARIES - Library and Linker options for Python extensions.
#
# Also defines py_exec and py_get_config_var.
#
Expand Down Expand Up @@ -54,21 +54,6 @@ function(py_get_config_var VAR RESULTVAR)
set("${RESULTVAR}" "${RESULT}" PARENT_SCOPE)
endfunction()

function(py_get_lib_name RESULTVAR)
# uses py_exec to compute Python's C/C++ library name, just like python-config does.
py_get_config_var(VERSION PYTHON_VERSION)
if(NOT "${PYTHON_VERSION}" VERSION_LESS "3.2")
py_exec(
"import sys; print(sys.abiflags)"
ABIFLAGS
)
else()
set(ABIFLAGS, "")
endif()

set("${RESULTVAR}" "python${PYTHON_VERSION}${ABIFLAGS}" PARENT_SCOPE)
endfunction()

function(find_python_interpreter_builtin)
find_package(PythonInterp "${PYTHON_MIN_VERSION}" QUIET)
if(PYTHONINTERP_FOUND)
Expand Down Expand Up @@ -170,19 +155,30 @@ endforeach()
# test all the found interpreters; break on success.
foreach(PYTHON ${PYTHON_INTERPRETERS})

# ask the interpreter for the essential extension-building flags
py_get_config_var(INCLUDEPY PYTHON_INCLUDE_DIR)
py_get_config_var(LIBDIR PYTHON_LIBRARY_DIR)
py_get_lib_name(PYTHON_LIBRARY_NAME)
# If the current python interpreter equals the one found at the very beginning with PythonInterp,
# we can use the PythonLibs find-module to find the matching libraries.
# Otherwise we ask that interpreter where its matching libraries are.
if (PYTHON STREQUAL PYTHON_EXECUTABLE)
find_package(PythonLibs REQUIRED)
else()
# ask the interpreter for the essential extension-building flags
py_get_config_var(INCLUDEPY PYTHON_INCLUDE_DIRS)
py_get_config_var(LIBDIR PYTHON_LIBRARY_DIR)
py_get_config_var(LIBPL PYTHON_LIBPL)
py_get_config_var(LDLIBRARY PYTHON_LIBRARY_NAME)
find_library(PYTHON_LIBRARIES ${PYTHON_LIBRARY_NAME}
PATHS "${PYTHON_LIBRARY_DIR}" "${PYTHON_LIBPL}"
)
endif()

# there's a static_assert that tests the Python version.
# that way, we verify the interpreter and the library version.
# (the interpreter provided us the library location)
try_compile(PYTHON_TEST_RESULT
"${CMAKE_BINARY_DIR}"
SOURCES "${CMAKE_CURRENT_LIST_DIR}/FindPython_test.cpp"
LINK_LIBRARIES "${PYTHON_LIBRARY_NAME}"
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${PYTHON_INCLUDE_DIR}" "-DLINK_DIRECTORIES=${PYTHON_LIBRARY_DIR}" "-DCMAKE_CXX_STANDARD=14"
LINK_LIBRARIES ${PYTHON_LIBRARIES}
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${PYTHON_INCLUDE_DIRS}" "-DCMAKE_CXX_STANDARD=14"
COMPILE_DEFINITIONS "-DTARGET_VERSION=${PYTHON_MIN_VERSION_HEX}"
OUTPUT_VARIABLE PYTHON_TEST_OUTPUT
)
Expand All @@ -191,7 +187,6 @@ foreach(PYTHON ${PYTHON_INTERPRETERS})
message("-- Using python interpreter: ${PYTHON}")

set(PYTHON_INTERP "${PYTHON}")
set(PYTHON_LIBRARY "-l${PYTHON_LIBRARY_NAME} -L${PYTHON_LIBRARY_DIR}")
break()
else()
set(PYTHON_TEST_ERRORS "${PYTHON_TEST_ERRORS}python candidate ${PYTHON}:\n${PYTHON_TEST_OUTPUT}\n\n")
Expand All @@ -207,12 +202,12 @@ if(NOT PYTHON_INTERP)
message("We need an interpreter that is shipped with libpython and header files.")
message("Specify your own with -DPYTHON=/path/to/executable\n\n\n")
set(PYTHON_INTERP "")
set(PYTHON_INCLUDE_DIR "")
set(PYTHON_LIBRARY "")
set(PYTHON_INCLUDE_DIRS "")
set(PYTHON_LIBRARIES "")

unset(PYTHON CACHE)
unset(PYTHON_LIBRARY CACHE)
unset(PYTHON_INCLUDE_DIR CACHE)
unset(PYTHON_LIBRARIES CACHE)
unset(PYTHON_INCLUDE_DIRS CACHE)
endif()

if(NOT PYTHON)
Expand All @@ -221,8 +216,8 @@ if(NOT PYTHON)
endif()

set(PYTHON "${PYTHON_INTERP}" CACHE FILEPATH "Location of the Python interpreter" ${LOL_FORCE})
set(PYTHON_LIBRARY "${PYTHON_LIBRARY}" CACHE STRING "Linker invocation for the Python library" ${LOL_FORCE})
set(PYTHON_INCLUDE_DIR "${PYTHON_INCLUDE_DIR}" CACHE PATH "Location of the Python include dir" ${LOL_FORCE})
set(PYTHON_LIBRARIES "${PYTHON_LIBRARIES}" CACHE STRING "Linker invocation for the Python library" ${LOL_FORCE})
set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIRS}" CACHE PATH "Location of the Python include dir" ${LOL_FORCE})


unset(LOL_FORCE)
Expand All @@ -233,4 +228,4 @@ mark_as_advanced(PYTHON_TEST_ERRORS)
mark_as_advanced(PYTHON_INTERPRETERS)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Python REQUIRED_VARS PYTHON PYTHON_INCLUDE_DIR PYTHON_LIBRARY)
find_package_handle_standard_args(Python REQUIRED_VARS PYTHON PYTHON_INCLUDE_DIRS PYTHON_LIBRARIES)
4 changes: 2 additions & 2 deletions buildsystem/modules/FindSDL2Image.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2015 the openage authors. See copying.md for legal info.
# Copyright 2014-2017 the openage authors. See copying.md for legal info.

find_package(PackageHandleStandardArgs)

Expand All @@ -24,6 +24,6 @@ else()
find_path(SDL2IMAGE_INCLUDE_DIRS SDL2/SDL_image.h DOC "Include directory for SDL2_image")
endif()

# handle the QUIETLY and REQUIRED arguments and set OPENGL_FOUND to TRUE if
# handle the QUIETLY and REQUIRED arguments and set SDL2Image_FOUND to TRUE if
# all listed variables are TRUE
find_package_handle_standard_args(SDL2Image DEFAULT_MSG SDL2IMAGE_LIBRARIES)
4 changes: 2 additions & 2 deletions buildsystem/pxdgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def get_pxd_lines(self):
if namespace != previous_namespace:
yield (
"cdef extern "
"from \"" + self.filename + "\" "
"from r\"" + self.filename + "\" "
"namespace \"" + namespace + "\" "
"nogil"
":"
Expand Down Expand Up @@ -403,7 +403,7 @@ def parse_args():
def main():
""" CLI entry point """
args = parse_args()
cppdir = CWD + "/libopenage"
cppdir = os.path.join(CWD, "libopenage")

if args.verbose:
hdr_count = len(args.all_files)
Expand Down
17 changes: 10 additions & 7 deletions buildsystem/python.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function(add_cython_modules)
add_executable("${TARGETNAME}" "${CPPNAME}")

# TODO: use full ldflags and cflags provided by python${VERSION}-config
target_link_libraries("${TARGETNAME}" "${PYEXT_LIBRARY}")
target_link_libraries("${TARGETNAME}" ${PYEXT_LIBRARY})
else()
set_property(GLOBAL APPEND PROPERTY SFT_CYTHON_MODULES "${source}")
add_library("${TARGETNAME}" MODULE "${CPPNAME}")
Expand All @@ -113,6 +113,9 @@ function(add_cython_modules)
PREFIX ""
SUFFIX "${PYEXT_SUFFIX}"
)
if(MSVC)
target_link_libraries("${TARGETNAME}" ${PYEXT_LIBRARY})
endif()
endif()

if(NOINSTALL_NEXT)
Expand Down Expand Up @@ -410,16 +413,16 @@ function(python_finalize)
list(APPEND cython_module_files_expr "$<TARGET_FILE:${cython_module_target}>")
endforeach()
file(GENERATE
OUTPUT "${CMAKE_BINARY_DIR}/py/inplace_module_list"
OUTPUT "${CMAKE_BINARY_DIR}/py/inplace_module_list$<CONFIG>"
CONTENT "${cython_module_files_expr}"
)
set(INPLACEMODULES_TIMEFILE "${CMAKE_BINARY_DIR}/py/inplacemodules_timefile")
add_custom_command(OUTPUT "${INPLACEMODULES_TIMEFILE}"
COMMAND "${PYTHON}" -m buildsystem.inplacemodules
"${CMAKE_BINARY_DIR}/py/inplace_module_list"
"${CMAKE_BINARY_DIR}"
"${CMAKE_BINARY_DIR}/py/inplace_module_list$<CONFIG>"
"${CMAKE_BINARY_DIR}" "$<CONFIG>"
DEPENDS
"${CMAKE_BINARY_DIR}/py/inplace_module_list"
"${CMAKE_BINARY_DIR}/py/inplace_module_list$<CONFIG>"
${cython_module_targets}
COMMAND "${CMAKE_COMMAND}" -E touch "${INPLACEMODULES_TIMEFILE}"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
Expand All @@ -432,8 +435,8 @@ function(python_finalize)

add_custom_target(cleancython
COMMAND "${PYTHON}" -m buildsystem.inplacemodules --clean
"${CMAKE_BINARY_DIR}/py/inplace_module_list"
"${CMAKE_BINARY_DIR}"
"${CMAKE_BINARY_DIR}/py/inplace_module_list$<CONFIG>"
"${CMAKE_BINARY_DIR}" "$<CONFIG>"
COMMAND "${PYTHON}" -m buildsystem.cythonize --clean
"${CMAKE_BINARY_DIR}/py/cython_modules"
"${CMAKE_BINARY_DIR}/py/cython_modules_embed"
Expand Down
39 changes: 16 additions & 23 deletions libopenage/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,21 @@ endif()
# windows does not have libm
if(NOT WIN32)
find_library(MATH_LIB m)
find_library(UTIL_LIB util)
endif()
if(MSVC)
find_library(OGG_LIB ogg)
else()
find_library(DL_LIB dl)
endif()
if(NOT APPLE AND NOT MSVC)
find_library(RT_LIB rt)
if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
find_library(EXECINFO_LIB execinfo)
endif()
endif()

find_library(FONTCONFIG_LIB fontconfig)
if(NOT WIN32)
find_library(UTIL_LIB util)
endif()

find_package(Freetype REQUIRED)
find_package(OpenGL REQUIRED)
Expand All @@ -89,11 +98,6 @@ find_package(Opusfile REQUIRED)
find_package(Epoxy REQUIRED)
find_package(HarfBuzz 1.0.0 REQUIRED)

set(DLOPEN "")
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(DLOPEN dl)
endif()

set(QT_VERSION_REQ "5.5")
find_package(Qt5Core ${QT_VERSION_REQ} REQUIRED)
find_package(Qt5Quick ${QT_VERSION_REQ} REQUIRED)
Expand Down Expand Up @@ -166,7 +170,7 @@ include_directories(
# link the executable to those libraries
target_link_libraries(libopenage
PUBLIC
${DLOPEN}
${DL_LIB}
${FONTCONFIG_LIB}
${FREETYPE_LIBRARIES}
${EPOXY_LIBRARIES}
Expand All @@ -177,6 +181,9 @@ target_link_libraries(libopenage
${SDL2_LIBRARY}
${UTIL_LIB}
${HarfBuzz_LIBRARIES}
${RT_LIB}
${OGG_LIB}
${EXECINFO_LIB}
# TODO: change to PUBLIC (or, alternatively, remove all keywords
# of this type) when qt cmake scripts change declarations of the
# IMPORTED libraries to GLOBAL.
Expand All @@ -185,18 +192,4 @@ target_link_libraries(libopenage
Qt5::Quick
)

if(NOT APPLE)
if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
target_link_libraries(libopenage
PUBLIC
execinfo
util
)
endif()
target_link_libraries(libopenage
PUBLIC
rt
)
endif()

install(TARGETS libopenage DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY)

0 comments on commit 102a823

Please sign in to comment.