solvespace/src/CMakeLists.txt

428 lines
11 KiB
CMake
Raw Normal View History

include(GNUInstallDirs)
# configuration
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR})
set(HAVE_BACKTRACE ${Backtrace_FOUND})
if(HAVE_BACKTRACE)
set(BACKTRACE_HEADER <${Backtrace_HEADER}>)
endif()
set(HAVE_SPACEWARE ${SPACEWARE_FOUND})
if(NOT WIN32 OR APPLE)
if(GTKMM_gtkmm-3.0_VERSION VERSION_LESS "3.24.0")
set(HAVE_GTK_FILECHOOSERNATIVE 0)
else()
set(HAVE_GTK_FILECHOOSERNATIVE 1)
endif()
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
${CMAKE_CURRENT_BINARY_DIR}/config.h)
# platform utilities
if(WIN32)
set(util_SOURCES
platform/utilwin.cpp)
else()
set(util_SOURCES
platform/utilunix.cpp)
endif()
if(APPLE)
set(util_LIBRARIES
${APPKIT_LIBRARY})
endif()
# libslvs
set(libslvs_SOURCES
util.cpp
entity.cpp
expr.cpp
constraint.cpp
constrainteq.cpp
system.cpp
platform/platform.cpp)
set(libslvs_HEADERS
solvespace.h
platform/platform.h)
add_library(slvs SHARED
${libslvs_SOURCES}
${libslvs_HEADERS}
${util_SOURCES}
lib.cpp)
target_compile_definitions(slvs
PRIVATE -DLIBRARY)
target_include_directories(slvs
PUBLIC ${CMAKE_SOURCE_DIR}/include)
target_link_libraries(slvs
${util_LIBRARIES})
set_target_properties(slvs PROPERTIES
PUBLIC_HEADER ${CMAKE_SOURCE_DIR}/include/slvs.h
VERSION ${solvespace_VERSION_MAJOR}.${solvespace_VERSION_MINOR}
SOVERSION 1)
if(NOT WIN32)
install(TARGETS slvs
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()
# solvespace dependencies
include_directories(
${OPENGL_INCLUDE_DIR}
${ZLIB_INCLUDE_DIR}
${PNG_PNG_INCLUDE_DIR}
${FREETYPE_INCLUDE_DIRS}
${CAIRO_INCLUDE_DIRS}
${Q3D_INCLUDE_DIR})
if(Backtrace_FOUND)
include_directories(
${Backtrace_INCLUDE_DIRS})
endif()
if(SPACEWARE_FOUND)
include_directories(
${SPACEWARE_INCLUDE_DIR})
endif()
if(OPENGL STREQUAL 3)
set(gl_SOURCES
render/gl3shader.cpp
render/rendergl3.cpp)
elseif(OPENGL STREQUAL 1)
set(gl_SOURCES
render/rendergl1.cpp)
else()
message(FATAL_ERROR "Unsupported OpenGL version ${OPENGL}")
endif()
set(platform_SOURCES
${gl_SOURCES}
platform/entrygui.cpp)
if(WIN32)
list(APPEND platform_SOURCES
platform/guiwin.cpp)
set(platform_LIBRARIES
comctl32
${SPACEWARE_LIBRARIES})
2015-03-24 06:45:53 +00:00
elseif(APPLE)
add_compile_options(
2015-03-24 06:45:53 +00:00
-fobjc-arc)
list(APPEND platform_SOURCES
render/rendergl.cpp
platform/guimac.mm)
else()
list(APPEND platform_SOURCES
platform/guigtk.cpp)
set(platform_LIBRARIES
${SPACEWARE_LIBRARIES})
foreach(pkg_config_lib GTKMM JSONC FONTCONFIG)
include_directories(${${pkg_config_lib}_INCLUDE_DIRS})
link_directories(${${pkg_config_lib}_LIBRARY_DIRS})
list(APPEND platform_LIBRARIES ${${pkg_config_lib}_LIBRARIES})
endforeach()
endif()
set(every_platform_SOURCES
platform/guiwin.cpp
platform/guigtk.cpp
platform/guimac.mm)
# solvespace library
set(solvespace_core_HEADERS
dsc.h
expr.h
polygon.h
sketch.h
solvespace.h
ui.h
platform/platform.h
Abstract all (ex-OpenGL) drawing operations into a Canvas interface. This has several desirable consequences: * It is now possible to port SolveSpace to a later version of OpenGL, such as OpenGLES 2, so that it runs on platforms that only have that OpenGL version; * The majority of geometry is now rendered without references to the camera in C++ code, so a renderer can now submit it to the video card once and re-rasterize with a different projection matrix every time the projection is changed, avoiding expensive reuploads; * The DOGD (draw or get distance) interface is now a straightforward Canvas implementation; * There are no more direct references to SS.GW.(projection) in sketch rendering code, which allows rendering to multiple viewports; * There are no more unnecessary framebuffer flips on CPU on Cocoa and GTK; * The platform-dependent GL code is now confined to rendergl1.cpp. * The Microsoft and Apple headers required by it that are prone to identifier conflicts are no longer included globally; * The rendergl1.cpp implementation can now be omitted from compilation to run SolveSpace headless or with a different OpenGL version. Note these implementation details of Canvas: * GetCamera currently always returns a reference to the field `Camera camera;`. This is so that a future renderer that caches geometry in the video memory can define it as asserting, which would provide assurance against code that could accidentally put something projection-dependent in the cache; * Line and triangle rendering is specified through a level of indirection, hStroke and hFill. This is so that a future renderer that batches geometry could cheaply group identical styles. * DrawPixmap and DrawVectorText accept a (o,u,v) and not a matrix. This is so that a future renderer into an output format that uses 2d transforms (e.g. SVG) could easily derive those. Some additional internal changes were required to enable this: * Pixmap is now always passed as std::shared_ptr<{const ,}Pixmap>. This is so that the renderer could cache uploaded textures between API calls, which requires it to capture a (weak) reference. * The PlatformPathEqual function was properly extracted into platform-specific code. This is so that the <windows.h> header could be included only where needed (in platform/w32* as well as rendergl1.cpp). * The SBsp{2,3}::DebugDraw functions were removed. They can be rewritten using the Canvas API if they are ever needed. While no visual changes were originally intended, some minor fixes happened anyway: * The "emphasis" yellow line from top-left corner is now correctly rendered much wider. * The marquee rectangle is now pixel grid aligned. * The hidden entities now do not clobber the depth buffer, removing some minor artifacts. * The workplane "tab" now scales with the font used to render the workplane name. * The workplane name font is now taken from the normals style. * Workplane and constraint line stipple is insignificantly different. This is so that it can reuse the existing stipple codepaths; rendering of workplanes and constraints predates those. Some debug functionality was added: * In graphics window, an fps counter that becomes red when rendering under 60fps is drawn.
2016-05-31 00:55:13 +00:00
render/render.h
render/gl3shader.h
srf/surface.h)
set(solvespace_core_SOURCES
bsp.cpp
clipboard.cpp
confscreen.cpp
constraint.cpp
constrainteq.cpp
describescreen.cpp
draw.cpp
drawconstraint.cpp
drawentity.cpp
entity.cpp
export.cpp
exportstep.cpp
exportvector.cpp
expr.cpp
file.cpp
generate.cpp
graphicswin.cpp
group.cpp
groupmesh.cpp
2016-04-13 08:43:06 +00:00
importdxf.cpp
mesh.cpp
modify.cpp
mouse.cpp
polyline.cpp
polygon.cpp
Implement a resource system. Currently, icons, fonts, etc are converted to C structures at compile time and are hardcoded to the binary. This presents several problems: * Cross-compilation is complicated. Right now, it is necessary to be able to run executables for the target platform; this happens to work with wine-binfmt installed, but is rather ugly. * Icons can only have one resolution. On OS X, modern software is expected to take advantage of high-DPI ("Retina") screens and use so-called @2x assets when ran in high-DPI mode. * Localization is complicated. Win32 and OS X provide built-in support for loading the resource appropriate for the user's locale. * Embedding strings can only be done as raw strings, using C++'s R"(...)" literals. This precludes embedding sizable strings, e.g. JavaScript libraries as used in Three.js export, and makes git history less useful. Not embedding the libraries means we have to rely on external CDNs, which requires an Internet connection and adds a glaring point of failure. * Linux distribution guidelines are violated. All architecture- independent data, especially large data such as fonts, is expected to be in /usr/share, not in the binary. * Customization is impossible without recompilation. Minor modifications like adding a few missing vector font characters or adjusting localization require a complete development environment, which is unreasonable to expect from users of a mechanical CAD. As such, this commit adds a resource system that bundles (and sometimes builds) resources with the executable. Where they go is platform-dependent: * on Win32: into resources of the executable, which allows us to keep distributing one file; * on OS X: into the app bundle; * on other *nix: into /usr/share/solvespace/ or ../res/ (relative to the executable path), the latter allowing us to run freshly built executables without installation. It also subsides the platform-specific resources that are in src/. The resource system is not yet used for anything; this will be added in later commits.
2016-04-21 15:54:18 +00:00
resource.cpp
request.cpp
style.cpp
system.cpp
textscreens.cpp
textwin.cpp
toolbar.cpp
ttf.cpp
undoredo.cpp
util.cpp
view.cpp
platform/platform.cpp
platform/gui.cpp
Abstract all (ex-OpenGL) drawing operations into a Canvas interface. This has several desirable consequences: * It is now possible to port SolveSpace to a later version of OpenGL, such as OpenGLES 2, so that it runs on platforms that only have that OpenGL version; * The majority of geometry is now rendered without references to the camera in C++ code, so a renderer can now submit it to the video card once and re-rasterize with a different projection matrix every time the projection is changed, avoiding expensive reuploads; * The DOGD (draw or get distance) interface is now a straightforward Canvas implementation; * There are no more direct references to SS.GW.(projection) in sketch rendering code, which allows rendering to multiple viewports; * There are no more unnecessary framebuffer flips on CPU on Cocoa and GTK; * The platform-dependent GL code is now confined to rendergl1.cpp. * The Microsoft and Apple headers required by it that are prone to identifier conflicts are no longer included globally; * The rendergl1.cpp implementation can now be omitted from compilation to run SolveSpace headless or with a different OpenGL version. Note these implementation details of Canvas: * GetCamera currently always returns a reference to the field `Camera camera;`. This is so that a future renderer that caches geometry in the video memory can define it as asserting, which would provide assurance against code that could accidentally put something projection-dependent in the cache; * Line and triangle rendering is specified through a level of indirection, hStroke and hFill. This is so that a future renderer that batches geometry could cheaply group identical styles. * DrawPixmap and DrawVectorText accept a (o,u,v) and not a matrix. This is so that a future renderer into an output format that uses 2d transforms (e.g. SVG) could easily derive those. Some additional internal changes were required to enable this: * Pixmap is now always passed as std::shared_ptr<{const ,}Pixmap>. This is so that the renderer could cache uploaded textures between API calls, which requires it to capture a (weak) reference. * The PlatformPathEqual function was properly extracted into platform-specific code. This is so that the <windows.h> header could be included only where needed (in platform/w32* as well as rendergl1.cpp). * The SBsp{2,3}::DebugDraw functions were removed. They can be rewritten using the Canvas API if they are ever needed. While no visual changes were originally intended, some minor fixes happened anyway: * The "emphasis" yellow line from top-left corner is now correctly rendered much wider. * The marquee rectangle is now pixel grid aligned. * The hidden entities now do not clobber the depth buffer, removing some minor artifacts. * The workplane "tab" now scales with the font used to render the workplane name. * The workplane name font is now taken from the normals style. * Workplane and constraint line stipple is insignificantly different. This is so that it can reuse the existing stipple codepaths; rendering of workplanes and constraints predates those. Some debug functionality was added: * In graphics window, an fps counter that becomes red when rendering under 60fps is drawn.
2016-05-31 00:55:13 +00:00
render/render.cpp
render/render2d.cpp
srf/boolean.cpp
srf/curve.cpp
srf/merge.cpp
srf/ratpoly.cpp
srf/raycast.cpp
srf/surface.cpp
srf/surfinter.cpp
srf/triangulate.cpp)
set(solvespace_core_gl_SOURCES
solvespace.cpp)
add_library(solvespace-core STATIC
${util_SOURCES}
${solvespace_core_HEADERS}
${solvespace_core_SOURCES})
add_dependencies(solvespace-core
q3d_header)
target_link_libraries(solvespace-core
dxfrw
${util_LIBRARIES}
${ZLIB_LIBRARY}
${PNG_LIBRARY}
${FREETYPE_LIBRARY}
flatbuffers)
if(Backtrace_FOUND)
target_link_libraries(solvespace-core
${Backtrace_LIBRARY})
endif()
target_compile_options(solvespace-core
PRIVATE ${COVERAGE_FLAGS})
2017-01-04 15:39:27 +00:00
# solvespace translations
if(HAVE_GETTEXT)
set(inputs
${solvespace_core_SOURCES}
${solvespace_core_HEADERS}
${every_platform_SOURCES})
set(templ_po ${CMAKE_CURRENT_BINARY_DIR}/../res/messages.po)
set(output_pot ${CMAKE_CURRENT_SOURCE_DIR}/../res/messages.pot)
set(output_po ${CMAKE_CURRENT_SOURCE_DIR}/../res/locales/en_US.po)
file(GLOB locale_pos ${CMAKE_CURRENT_SOURCE_DIR}/../res/locales/*.po)
2017-01-04 15:39:27 +00:00
string(REPLACE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}
gen_output_pot ${output_pot}.gen)
string(REPLACE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}
gen_output_po ${output_po}.gen)
foreach(locale_po ${locale_pos})
string(REPLACE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}
gen_locale_po ${locale_po}.gen)
list(APPEND gen_locale_pos ${gen_locale_po})
endforeach()
2017-01-04 15:39:27 +00:00
add_custom_command(
OUTPUT ${gen_output_pot}
2017-01-04 15:39:27 +00:00
COMMAND ${XGETTEXT}
--language=C++
--keyword --keyword=_ --keyword=N_ --keyword=C_:2,1c --keyword=CN_:2,1c
2017-01-05 12:35:50 +00:00
--force-po --width=100 --sort-by-file
--package-name=SolveSpace
--package-version=${solvespace_VERSION_MAJOR}.${solvespace_VERSION_MINOR}
2017-01-04 15:39:27 +00:00
"--copyright-holder=the PACKAGE authors"
--msgid-bugs-address=whitequark@whitequark.org
--from-code=utf-8 --output=${gen_output_pot} ${inputs}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${gen_output_pot} ${output_pot}
2017-01-04 15:39:27 +00:00
DEPENDS ${inputs}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
2017-01-04 15:39:27 +00:00
COMMENT "Extracting translations"
VERBATIM)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../res/locales)
# en_US is a bit special; we pre-fill the msgstrs from msgids, instead of (as would normally
# happen) leaving them empty.
2017-01-04 15:39:27 +00:00
add_custom_command(
OUTPUT ${gen_output_po}
2017-01-04 15:39:27 +00:00
COMMAND ${MSGINIT}
--locale=en_US --no-translator
--output=${templ_po} --input=${gen_output_pot}
2017-01-04 15:39:27 +00:00
COMMAND ${MSGMERGE}
2017-01-05 12:27:28 +00:00
--force-po --no-fuzzy-matching
--output=${gen_output_po} ${output_po} ${templ_po}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${gen_output_po} ${output_po}
DEPENDS ${gen_output_pot}
COMMENT "Updating en_US translations"
2017-01-04 15:39:27 +00:00
VERBATIM)
foreach(locale_po ${locale_pos})
string(REPLACE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}
gen_locale_po ${locale_po}.gen)
get_filename_component(locale_name ${locale_po} NAME_WE)
if(locale_name STREQUAL "en_US")
continue()
endif()
add_custom_command(
OUTPUT ${gen_locale_po}
COMMAND ${MSGMERGE}
--no-fuzzy-matching
--output=${gen_locale_po} ${locale_po} ${gen_output_pot}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${gen_locale_po} ${locale_po}
DEPENDS ${gen_output_pot}
COMMENT "Updating ${locale_name} translations"
VERBATIM)
endforeach()
2018-07-12 22:41:18 +00:00
add_custom_target(translate_solvespace
DEPENDS ${gen_output_pot} ${gen_output_po} ${gen_locale_pos})
2017-01-04 15:39:27 +00:00
endif()
# solvespace graphical executable
if(ENABLE_GUI)
add_executable(solvespace WIN32 MACOSX_BUNDLE
${solvespace_core_gl_SOURCES}
${platform_SOURCES}
$<TARGET_PROPERTY:resources,EXTRA_SOURCES>)
add_dependencies(solvespace
resources)
target_link_libraries(solvespace
solvespace-core
${OPENGL_LIBRARIES}
${platform_LIBRARIES}
${COVERAGE_LIBRARY})
if(MSVC)
set_target_properties(solvespace PROPERTIES
LINK_FLAGS "/MANIFEST:NO /SAFESEH:NO /INCREMENTAL:NO /OPT:REF /STACK:33554432")
elseif(APPLE)
set_target_properties(solvespace PROPERTIES
OUTPUT_NAME SolveSpace)
endif()
endif()
# solvespace headless library
set(headless_SOURCES
platform/guinone.cpp
render/rendercairo.cpp)
add_library(solvespace-headless STATIC EXCLUDE_FROM_ALL
${solvespace_core_gl_SOURCES}
${headless_SOURCES})
target_compile_definitions(solvespace-headless
PRIVATE -DHEADLESS)
target_include_directories(solvespace-headless
INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(solvespace-headless
solvespace-core
${CAIRO_LIBRARIES})
target_compile_options(solvespace-headless
PRIVATE ${COVERAGE_FLAGS})
# solvespace command-line executable
2018-07-18 11:49:06 +00:00
if(ENABLE_CLI)
add_executable(solvespace-cli
platform/entrycli.cpp
$<TARGET_PROPERTY:resources,EXTRA_SOURCES>)
2018-07-18 11:49:06 +00:00
target_link_libraries(solvespace-cli
solvespace-core
solvespace-headless)
2018-07-18 11:49:06 +00:00
add_dependencies(solvespace-cli
resources)
2018-07-18 11:49:06 +00:00
if(MSVC)
set_target_properties(solvespace-cli PROPERTIES
LINK_FLAGS "/INCREMENTAL:NO /OPT:REF")
endif()
endif()
# solvespace unix package
if(NOT (WIN32 OR APPLE))
if(ENABLE_GUI)
install(TARGETS solvespace
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
2018-07-18 11:49:06 +00:00
if(ENABLE_CLI)
install(TARGETS solvespace-cli
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
endif()
# solvespace macOS package
2015-03-25 00:31:09 +00:00
if(APPLE)
set(bundle SolveSpace)
set(bundle_bin ${EXECUTABLE_OUTPUT_PATH}/${bundle}.app/Contents/MacOS)
add_custom_command(TARGET solvespace POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${bundle_bin}
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:solvespace-cli> ${bundle_bin}
COMMENT "Bundling executable solvespace-cli"
VERBATIM)
add_custom_command(OUTPUT ${EXECUTABLE_OUTPUT_PATH}/${bundle}.dmg
COMMAND ${CMAKE_COMMAND} -E remove ${EXECUTABLE_OUTPUT_PATH}/${bundle}.dmg
COMMAND hdiutil create -srcfolder ${EXECUTABLE_OUTPUT_PATH}/${bundle}.app
${EXECUTABLE_OUTPUT_PATH}/${bundle}.dmg
DEPENDS solvespace
COMMENT "Building ${bundle}.dmg"
VERBATIM)
2015-03-25 00:31:09 +00:00
add_custom_target(${bundle}-dmg ALL
DEPENDS ${EXECUTABLE_OUTPUT_PATH}/${bundle}.dmg)
endif()