From 7dbfb109fe42704814e9bbe41f23d24de2ffa240 Mon Sep 17 00:00:00 2001 From: Daniel Nicoletti Date: Tue, 9 Apr 2024 14:59:17 -0300 Subject: [PATCH] Fixes CMake static support on Windows BUILD_SHARED_LIBS was added but was not tested on Windows which is known to be more complex due dll export/import. Static builds enforce DEMAND_LOADING --- CMakeLists.txt | 9 ++++---- cmd/dot/CMakeLists.txt | 37 +++++++++++++++++++----------- plugin/dot_layout/CMakeLists.txt | 2 +- plugin/neato_layout/CMakeLists.txt | 2 +- plugin/pango/CMakeLists.txt | 2 +- 5 files changed, 31 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dbda0d9193..5ba19e0fb6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,11 +27,10 @@ set(with_tclpkg AUTO CACHE STRING "Build TCL components") set_property(CACHE with_tclpkg PROPERTY STRINGS AUTO ON OFF) if(WIN32) - # Build dynamic-link libraries on Windows, including MinGW. The - # CMake build system does not currently support building static - # libraries, so the GVDLL symbol can be unconditionally set until - # such support is introduced. - add_definitions(-DGVDLL) + if(BUILD_SHARED_LIBS) + # GVDLL definition exports symbols + add_definitions(-DGVDLL) + endif() option(install_win_dependency_dlls "Install 3rd party dependencies" ON) endif() diff --git a/cmd/dot/CMakeLists.txt b/cmd/dot/CMakeLists.txt index 8748e4b4b2..1e2982022c 100644 --- a/cmd/dot/CMakeLists.txt +++ b/cmd/dot/CMakeLists.txt @@ -1,4 +1,10 @@ -add_definitions(-DDEMAND_LOADING=1) +if(BUILD_SHARED_LIBS) + add_definitions(-DDEMAND_LOADING=1) + set(DOT_TARGET dot) +else() + add_definitions(-DDEMAND_LOADING=0) + set(DOT_TARGET dot_static) +endif() include_directories( ../../lib @@ -10,28 +16,31 @@ include_directories( ../../lib/pathplan ) -add_executable(dot +add_executable(${DOT_TARGET} # Source files dot.c no_builtins.c ) -target_link_libraries(dot PRIVATE +target_link_libraries(${DOT_TARGET} PRIVATE cgraph gvc ) if(APPLE) - set_target_properties(dot PROPERTIES LINK_FLAGS -Wl,-stack_size,0x2000000) + set_target_properties(${DOT_TARGET} PROPERTIES + LINK_FLAGS -Wl,-stack_size,0x2000000) elseif(MINGW) - set_target_properties(dot PROPERTIES LINK_FLAGS -Wl,--stack,0x2000000) + set_target_properties(${DOT_TARGET} PROPERTIES + LINK_FLAGS -Wl,--stack,0x2000000) elseif(WIN32) - set_target_properties(dot PROPERTIES LINK_FLAGS /STACK:"33554432") + set_target_properties(${DOT_TARGET} PROPERTIES + LINK_FLAGS /STACK:"33554432") endif() # Installation location of executables install( - TARGETS dot + TARGETS ${DOT_TARGET} RUNTIME DESTINATION ${BINARY_INSTALL_DIR} LIBRARY DESTINATION ${LIBRARY_INSTALL_DIR} ARCHIVE DESTINATION ${LIBRARY_INSTALL_DIR} @@ -111,10 +120,10 @@ foreach(cmd_alias IN LISTS dot_aliases) if(WIN32 OR CYGWIN) # Copy dot executable to each alias name then install copies to bindir add_custom_command( - TARGET dot + TARGET ${DOT_TARGET} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy $ ${DOTCOPY} - COMMENT "Copying dot to ${DOTCOPY}" + COMMAND ${CMAKE_COMMAND} -E copy $ ${DOTCOPY} + COMMENT "Copying ${DOT_TARGET} to ${DOTCOPY}" ) install( PROGRAMS ${DOTCOPY} @@ -128,12 +137,14 @@ foreach(cmd_alias IN LISTS dot_aliases) # ${CMAKE_CURRENT_BINARY_DIR}/dot is installed to ${BINARY_INSTALL_DIR}/dot. # There is a (small?) risk of dangling symlinks add_custom_command( - TARGET dot + TARGET ${DOT_TARGET} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E create_symlink $ + COMMAND ${CMAKE_COMMAND} + -E create_symlink + $ ${cmd_alias} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMENT "Linking dot as ${cmd_alias}" + COMMENT "Linking ${DOT_TARGET} as ${cmd_alias}" ) install( FILES ${DOTCOPY} diff --git a/plugin/dot_layout/CMakeLists.txt b/plugin/dot_layout/CMakeLists.txt index 21a2d23904..e35560f560 100644 --- a/plugin/dot_layout/CMakeLists.txt +++ b/plugin/dot_layout/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(gvplugin_dot_layout SHARED +add_library(gvplugin_dot_layout # Source files gvplugin_dot_layout.c gvlayout_dot_layout.c diff --git a/plugin/neato_layout/CMakeLists.txt b/plugin/neato_layout/CMakeLists.txt index 180b7250b4..c92032a5c2 100644 --- a/plugin/neato_layout/CMakeLists.txt +++ b/plugin/neato_layout/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(gvplugin_neato_layout SHARED +add_library(gvplugin_neato_layout # Source files gvplugin_neato_layout.c gvlayout_neato_layout.c diff --git a/plugin/pango/CMakeLists.txt b/plugin/pango/CMakeLists.txt index 16c6f8d89c..1502e264ae 100644 --- a/plugin/pango/CMakeLists.txt +++ b/plugin/pango/CMakeLists.txt @@ -1,6 +1,6 @@ if(CAIRO_FOUND AND PANGOCAIRO_FOUND) - add_library(gvplugin_pango SHARED + add_library(gvplugin_pango # Header files gvgetfontlist.h gvplugin_pango.h -- GitLab