Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support msvc 1 #349

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
224 changes: 224 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
# AUTHOR(S): Rashad Kanavath <rashad km gmail>
# PURPOSE: Grass root that adds options to activate/deactivate 3rd party libraries
# COPYRIGHT: (C) 2020 by the GRASS Development Team
# This program is free software under the GPL (>=v2)
# Read the file COPYING that comes with GRASS for details.

cmake_minimum_required(VERSION 3.3)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)

#if(DEFINED ENV{VCPKG_DEFAULT_TRIPLET} AND NOT DEFINED VCPKG_TARGET_TRIPLET)
# set(VCPKG_TARGET_TRIPLET "$ENV{VCPKG_DEFAULT_TRIPLET}" CACHE STRING "")
#endif()

project(GRASSGIS)

set(BUILD_SHARED_LIBS ON)
#message(FATAL_ERROR "VCPKG_TARGET_TRIPLET=${VCPKG_TARGET_TRIPLET}")
if(MSVC)
if(BUILD_SHARED_LIBS)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
endif()

set_property(GLOBAL PROPERTY USE_FOLDERS ON)
endif()

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/find_scripts;${CMAKE_SOURCE_DIR}/cmake/modules;${CMAKE_MODULE_PATH}")

set(default_option_enabled ON)
if(WIN32)
set(default_option_enabled OFF)
endif()

if(CMAKE_BUILD_TYPE)
set( grass_build_type "${CMAKE_BUILD_TYPE}" )
string( TOLOWER "${grass_build_type}" grass_build_type_lc )
set(find_library_suffix "_RELEASE")
if( grass_build_type_lc STREQUAL "debug" )
set(find_library_suffix "_DEBUG")
endif()
else()
set(find_library_suffix "")
endif()

option(WITH_CAIRO "Build with cairo support ." ON)
option(WITH_X11 "Build with X11 support ." ${default_option_enabled})
option(WITH_OPENGL "Build with opengl support ." ON)
option(WITH_SQLITE "enable sqlite support" ON)
option(WITH_POSTGRES "enable postgres support" ON)
option(WITH_NLS "enable nls support" ${default_option_enabled})
option(WITH_BZLIB "enable bzlib support" ON)
option(WITH_BLAS "enable blas support" ON)
option(WITH_LAPACK "enable lapack support" ON)
option(WITH_LIBLAS "enable libLAS support" ON)
option(WITH_OPENDWG "enable v.in.dwg" OFF)

option(WITH_PYTHON "Build python bindings" ON)
option(WITH_LARGEFILES "enable largefile support" ${default_option_enabled})
option(WITH_DOCS "Build documentation" ON)
if(APPLE)
if(POLICY CMP0042)
cmake_policy(SET CMP0042 NEW)
endif()
set(CMAKE_MACOSX_RPATH TRUE)
endif()

set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
if("${isSystemDir}" STREQUAL "-1")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
endif("${isSystemDir}" STREQUAL "-1")

include(get_host_arch)
get_host_arch(BUILD_ARCH)

include(get_versions)
get_versions("include/VERSION"
GRASS_VERSION_MAJOR
GRASS_VERSION_MINOR
GRASS_VERSION_RELEASE
GRASS_VERSION_DATE)

set(GRASS_VERSION_NUMBER ${GRASS_VERSION_MAJOR}.${GRASS_VERSION_MINOR}.${GRASS_VERSION_RELEASE})
message(STATUS "GRASS_VERSION_NUMBER = '${GRASS_VERSION_NUMBER}'")
set(GRASS_VERSION_UPDATE_PKG "0.2")

include(set_compiler_flags)
set_compiler_flags()

include(repo_status)
repo_status("${CMAKE_CURRENT_LIST_DIR}" GRASS_VERSION_GIT)

enable_testing()

# Setup build locations.
if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
endif()
if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
endif()
if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
endif()

include(build_module)
include(build_program)
include(build_program_in_subdir)
include(build_library_in_subdir)
include(copy_python_files_in_subdir)
include(build_script_in_subdir)
include(build_gui_in_subdir)
include(check_target)

add_subdirectory(thirdparty)
set(MKHTML_PY ${CMAKE_BINARY_DIR}/tools/mkhtml.py)

set(GISBASE ${CMAKE_BINARY_DIR}/gisbase)
file(TO_NATIVE_PATH "${GISBASE}" GISBASE_NATIVE)
file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/bin" BINARY_DIR)
file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/lib" LIB_DIR)
file(TO_NATIVE_PATH "${CMAKE_SOURCE_DIR}" MODULE_TOPDIR)
file(TO_NATIVE_PATH "${GISBASE}/scripts" SCRIPTS_DIR)
file(TO_NATIVE_PATH "${GISBASE}/etc/config/rc" GISRC)
file(TO_NATIVE_PATH "${GISBASE}/etc/python" ETC_PYTHON_DIR)
file(TO_NATIVE_PATH "${GISBASE}/gui/wxpython" GUI_WXPYTHON_DIR)
if(WIN32)
set(sep "\;")
set(env_path "")
else()
set(sep ":")
set(env_path ":$ENV{PATH}")
endif()


set(grass_env_command ${CMAKE_COMMAND} -E env
"PATH=${BINARY_DIR}${sep}${SCRIPTS_DIR}${env_path}"
"PYTHONPATH=${ETC_PYTHON_DIR}${sep}${GUI_WXPYTHON_DIR}${sep}$ENV{PYTHONPATH}"
"LD_LIBRARY_PATH=${LIB_DIR}${sep}$ENV{LD_LIBRARY_PATH}"
"GISBASE=${GISBASE_NATIVE}"
"GISRC=${GISRC}"
"LC_ALL=C"
"LANG=C"
"LANGUAGE=C"
"MODULE_TOPDIR=${MODULE_TOPDIR}"
"VERSION_NUMBER=\"${GRASS_VERSION_NUMBER}\""
"VERSION_DATE=\"${GRASS_VERSION_DATE}\"")



set(NO_HTML_DESCR_TARGETS "g.parser;ximgview;test.raster3d.lib")
add_subdirectory(include)

include_directories("${CMAKE_BINARY_DIR}/include")
if(MSVC)
include_directories("${CMAKE_SOURCE_DIR}/msvc")
endif()

execute_process(
COMMAND ${CMAKE_COMMAND} -E echo "Creating directories in ${GISBASE}"
COMMAND ${CMAKE_COMMAND} -E make_directory ${GISBASE}/bin/
COMMAND ${CMAKE_COMMAND} -E make_directory ${GISBASE}/scripts/
COMMAND ${CMAKE_COMMAND} -E make_directory ${GISBASE}/demolocation/
COMMAND ${CMAKE_COMMAND} -E make_directory ${GISBASE}/etc/config/
COMMAND ${CMAKE_COMMAND} -E make_directory ${GISBASE}/driver/db/
COMMAND ${CMAKE_COMMAND} -E make_directory ${GISBASE}/tools/
COMMAND ${CMAKE_COMMAND} -E make_directory ${GISBASE}/lib/
COMMAND ${CMAKE_COMMAND} -E make_directory ${GISBASE}/etc/lister/
COMMAND ${CMAKE_COMMAND} -E make_directory ${GISBASE}/etc/python/grass/lib
COMMAND ${CMAKE_COMMAND} -E make_directory ${GISBASE}/gui/wxpython/xml/
COMMAND ${CMAKE_COMMAND} -E make_directory ${GISBASE}/gui/icons/
COMMAND ${CMAKE_COMMAND} -E make_directory ${GISBASE}/gui/images/
COMMAND ${CMAKE_COMMAND} -E make_directory ${GISBASE}/docs/html/
)

add_subdirectory(lib)
add_subdirectory(tools)
set(modules_list)


set(ALL_SUBDIRS
general
db
display
imagery
misc
raster
raster3d
scripts
vector
temporal
# ps
)

foreach(d ${ALL_SUBDIRS})
add_subdirectory(${d})
endforeach()
add_custom_target(ALL_MODULES
COMMAND ${CMAKE_COMMAND} -E echo "Building all modules"
DEPENDS ${modules_list})

###message(FATAL_ERROR "modules_list=${modules_list}")

if(WITH_PYTHON)
add_subdirectory(gui)
endif()

if(WITH_DOCS)
add_subdirectory(doc)
add_subdirectory(man)
endif() # WITH_DOCS


####add_subdirectory(locale)

# TODO: To be discussed
# add_subdirectory(testsuite)
# add_subdirectory(macosx)

if(WITH_X11)
build_program_in_subdir(visualization/ximgview DEPENDS grass_gis X11)
endif()
35 changes: 35 additions & 0 deletions cmake/copy_g_gui_module.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# AUTHOR(S): Rashad Kanavath <rashad km gmail>
# PURPOSE: Copy g.gui script plus .bat file if on windows
# COPYRIGHT: (C) 2020 by the GRASS Development Team
# This program is free software under the GPL (>=v2)
# Read the file COPYING that comes with GRASS for details.
# -DSOURCE_DIR
# -DGISBASE
# -DG_NAME
# -DSRC_SCRIPT_FILE
# -DBINARY_DIR

set(SCRIPT_EXT "")
if(WIN32)
set(SCRIPT_EXT ".py")
endif()

if(WIN32)
set(PGM_NAME ${G_NAME})
configure_file(
${SOURCE_DIR}/cmake/windows_launch.bat.in
${GISBASE}/scripts/${G_NAME}.bat @ONLY)
endif(WIN32)

set(TMP_SCRIPT_FILE ${BINARY_DIR}/CMakeFiles/${G_NAME}${SCRIPT_EXT})
configure_file(${SRC_SCRIPT_FILE} ${TMP_SCRIPT_FILE} COPYONLY)
file(
COPY ${TMP_SCRIPT_FILE}
DESTINATION ${GISBASE}/scripts/
FILE_PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE)


file(REMOVE ${TMP_SCRIPT_FILE})
61 changes: 61 additions & 0 deletions cmake/ctypesgen.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# AUTHOR(S): Rashad Kanavath <rashad km gmail>
# PURPOSE: Cmake building of lib/python/ctypes (TODO)
# COPYRIGHT: (C) 2020 by the GRASS Development Team
# This program is free software under the GPL (>=v2)
# Read the file COPYING that comes with GRASS for details.

set(ENV{GISRC} "${BIN_DIR}/etc/config/rc")
set(ENV{GISBASE} "${BIN_DIR}")
set(ENV{PATH} "${BIN_DIR}/bin:${BIN_DIR}/scripts:$ENV{PATH}")
set(ENV{PYTHONPATH} "${BIN_DIR}/gui/wxpython:${BIN_DIR}/etc/python:$ENV{PYTHONPATH}")
if(NOT MSVC)
set(ENV{LD_LIBRARY_PATH} "${BIN_DIR}/lib:$ENV{LD_LIBRARY_PATH}")
endif()
set(ENV{LC_ALL} C)

set(LIBRARIES)
foreach(LIB ${LIBS})
if(WIN32)
list(APPEND LIBRARIES "--library=${BIN_DIR}/lib/${LIB}.${GRASS_VERSION_NUMBER}.dll")
elseif(APPLE)
list(APPEND LIBRARIES "--library=${BIN_DIR}/lib/lib${LIB}.${GRASS_VERSION_NUMBER}.so")
else()
#This can be linux or unix
list(APPEND LIBRARIES "--library=${BIN_DIR}/lib/lib${LIB}.${GRASS_VERSION_NUMBER}.so")
endif()
endforeach()

set(HEADERS)
foreach(HDR ${HDRS})
list(APPEND HEADERS "${BIN_DIR}/include/grass/${HDR}")
endforeach()

foreach(req OUT_FILE HDRS LIBS CTYPESGEN_PY COMPILER )
if(NOT DEFINED ${req} OR "${${req}}" STREQUAL "")
message(FATAL_ERROR "you must set ${req}")
endif()
endforeach()

if(MSVC)
set(CTYPESFLAGS "${COMPILER} -E -DPACKAGE=\"grasslibs\"")
else()
set(CTYPESFLAGS "${COMPILER} -E -DPACKAGE=\"grasslibs\" -D__GLIBC_HAVE_LONG_LONG")
endif()

message(STATUS "Running ${PYTHON_EXECUTABLE} ${CTYPESGEN_PY} --cpp=${CTYPESFLAGS} --includedir=\"${BIN_DIR}/include\" --runtime-libdir=\"${BIN_DIR}/lib\" ${HEADERS} ${LIBRARIES} --output=${OUT_FILE}")
execute_process(
COMMAND ${PYTHON_EXECUTABLE} ${CTYPESGEN_PY}
--cpp=${CTYPESFLAGS}
--includedir="${BIN_DIR}/include"
--runtime-libdir="${BIN_DIR}/lib"
${HEADERS}
${LIBRARIES}
--output=${OUT_FILE}
OUTPUT_VARIABLE ctypesgen_OV
ERROR_VARIABLE ctypesgen_EV
RESULT_VARIABLE ctypesgen_RV
)

if( ctypesgen_RV )
message(FATAL_ERROR "ctypesgen.py: ${ctypesgen_EV} \n ${ctypesgen_OV}")
endif()
Loading