Skip to content

Commit

Permalink
#156 - updated CMakeLists.txt to fix 'add_executable cannot create ta…
Browse files Browse the repository at this point in the history
…rget because another target with the same name exists' error - trigger [gha] [appveyor]
  • Loading branch information
oxy86 committed Dec 1, 2024
1 parent 90c329e commit 466abec
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 47 deletions.
71 changes: 25 additions & 46 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ target_include_directories(${TARGET_NAME} PUBLIC
)



# Set DEFAULT Target Properties
set_target_properties(${TARGET_NAME} PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
Expand All @@ -179,7 +179,6 @@ set_target_properties(${TARGET_NAME} PROPERTIES
)



# Add compiler options
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
target_compile_options(${TARGET_NAME} PRIVATE -Wall -Wextra -Wpedantic)
Expand All @@ -201,9 +200,28 @@ target_link_libraries(${TARGET_NAME} PRIVATE
Qt6::Svg
Qt6::Xml
)

# Set properties for macOS
if(APPLE AND NOT IOS)



# Add platform-specific properties
if(WIN32)

# Add Windows-specific metadata and icon
set_target_properties(${TARGET_NAME} PROPERTIES
WIN32_EXECUTABLE TRUE
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION}
)

# Embed version and metadata into the binary using a resource file
target_sources(${TARGET_NAME} PRIVATE src/icon.rc)

# Optionally copy the target to a specific directory after build
install(TARGETS ${TARGET_NAME}
RUNTIME DESTINATION release/ # Install to release/ folder
)

elseif(APPLE AND NOT IOS)
set_source_files_properties("${CMAKE_SOURCE_DIR}/src/images/socnetv.icns" PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
target_sources(${TARGET_NAME} PRIVATE "${CMAKE_SOURCE_DIR}/src/images/socnetv.icns")

Expand All @@ -218,21 +236,16 @@ if(APPLE AND NOT IOS)

# Installation
install(TARGETS ${TARGET_NAME}
BUNDLE DESTINATION "${INSTALL_DIR}"
BUNDLE DESTINATION "${INSTALL_DIR}"
)


endif()

if(LINUX)
elseif(LINUX)

# Define the installation prefix (equivalent to qmake's PREFIX)
# By default, this is /usr/local, but we set it to /usr for compatibility
set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Installation prefix")

# Define the target executable name
set(TARGET_NAME socnetv)

# Set the installation paths and files
install(TARGETS ${TARGET_NAME}
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" # Binaries go to /usr/bin
Expand Down Expand Up @@ -272,40 +285,6 @@ endif()



# Set the target name for Windows
if(WIN32)
set(TARGET_NAME SocNetV)

# Add executable with Windows-specific settings
add_executable(${TARGET_NAME} WIN32
${SOURCES} # Your source files
src/images/socnetv.ico # Icon file for Windows
)

# Set properties for the PE header (optional, for advanced customization)
set_target_properties(${TARGET_NAME} PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION} # Equivalent to VERSION_PE_HEADER
)

# Embed version and metadata into the binary (using resource file)
set_source_files_properties(src/images/socnetv.ico PROPERTIES
MACOSX_PACKAGE_LOCATION Resources
)

# Define metadata for the executable (only for Visual Studio or resource scripts)
set_target_properties(${TARGET_NAME} PROPERTIES
COMPANY_NAME "socnetv.org"
PRODUCT_NAME "Social Network Visualizer"
DESCRIPTION "SocNetV: Open-source social network analysis application based on Qt."
COPYRIGHT "Copyright (C) 2023 Dimitris V. Kalamaras. GPLv3."
)

# Optionally copy the target to a specific directory after build
install(TARGETS ${TARGET_NAME}
RUNTIME DESTINATION release/ # Install to release/ folder
)
endif()


qt_finalize_executable(${TARGET_NAME})
Expand Down
21 changes: 20 additions & 1 deletion src/icon.rc
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
IDI_ICON1 ICON DISCARDABLE "images/socnetv.ico"
1 VERSIONINFO
FILEVERSION 3,2,0,0
PRODUCTVERSION 3,2,0,0
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904B0" // Locale and codepage: 0409 (English - United States), 04B0 (Unicode)
BEGIN
VALUE "CompanyName", "socnetv.org"
VALUE "FileDescription", "SocNetV: Open-source social network analysis application based on Qt."
VALUE "ProductName", "Social Network Visualizer"
VALUE "LegalCopyright", "Copyright (C) 2024 Dimitris V. Kalamaras. GPLv3."
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0409, 1200
END
END

IDI_ICON1 ICON "images/socnetv.ico"

0 comments on commit 466abec

Please sign in to comment.