]> git.sur5r.net Git - fstl/blob - CMakeLists.txt
Update watchfile
[fstl] / CMakeLists.txt
1 #### Fast .stl viewer #####
2 # Original Project Author: Matt Keeter Copyright 2014 -2017
3 # Author: Paul Tsouchlos Copyright 2017
4
5 cmake_minimum_required(VERSION 3.3)
6
7 project(fstl)
8
9 # Setting -std=c++11
10 set(CMAKE_CXX_STANDARD 11)
11 # Setting standard to required, as requisted by DeveloperPaul123 on github
12 set(CXX_STANDARD_REQUIRED ON)
13
14 # Set the version number
15 set (FSTL_VERSION_MAJOR "0")
16 set (FSTL_VERSION_MINOR "10")
17 set (FSTL_VERSION_PATCH "0")
18 set (PROJECT_VERSION "${FSTL_VERSION_MAJOR}.${FSTL_VERSION_MINOR}.${FSTL_VERSION_PATCH}")
19
20 message(STATUS "Version: ${PROJECT_VERSION}")
21
22 set(CMAKE_AUTOMOC ON)
23 set(CMAKE_INCLUDE_CURRENT_DIR ON)
24 set(CMAKE_AUTOUIC ON)
25
26 #set project sources
27 set(Project_Sources src/app.cpp
28 src/backdrop.cpp
29 src/axis.cpp
30 src/canvas.cpp
31 src/glmesh.cpp
32 src/loader.cpp
33 src/main.cpp
34 src/mesh.cpp
35 src/window.cpp)
36
37 #set project headers. 
38 set(Project_Headers src/app.h
39 src/backdrop.h
40 src/axis.h
41 src/canvas.h
42 src/glmesh.h
43 src/loader.h
44 src/mesh.h
45 src/window.h)
46
47 #set project resources and icon resource
48 set(Project_Resources qt/qt.qrc gl/gl.qrc)
49 set(Icon_Resource exe/fstl.rc)
50
51 #set Policy CMP0072 FindOpenGL behavior
52 set(OpenGL_GL_PREFERENCE GLVND)
53
54 #find required packages. 
55 find_package(Qt5 5.14 REQUIRED COMPONENTS Core Gui Widgets OpenGL)
56 find_package(OpenGL REQUIRED)
57 find_package(Threads REQUIRED)
58
59 #add resources to RCC
60 qt5_add_resources(Project_Resources_RCC ${Project_Resources})
61
62 #tell CMake AUTOGEN to skip autogen on the generated qrc files
63 set_property(SOURCE ${Project_Resources_RCC} PROPERTY SKIP_AUTOGEN ON)
64
65 #include opengl files. 
66 include_directories(${QT_QTOPENGL_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR} )
67
68 if(WIN32)
69   add_executable(fstl WIN32 ${Project_Sources} ${Project_Headers} ${Project_Resources_RCC} ${Icon_Resource})
70   set(Fstl_LINK_FLAGS ${CMAKE_CURRENT_SOURCE_DIR}/${Icon_Resource})
71   set_target_properties(fstl PROPERTIES LINK_FLAGS ${Fstl_LINK_FLAGS})
72 elseif(APPLE)
73   add_executable(fstl MACOSX_BUNDLE ${Project_Sources} ${Project_Headers} ${Project_Resources_RCC} ${Icon_Resource})
74 else()
75   add_executable(fstl ${Project_Sources} ${Project_Headers} ${Project_Resources_RCC} ${Icon_Resource})
76 endif(WIN32)
77
78 target_link_libraries(fstl Qt5::Widgets Qt5::Core Qt5::Gui Qt5::OpenGL ${OPENGL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
79
80 # Add version definitions to use within the code. 
81 target_compile_definitions(fstl PRIVATE -DFSTL_VERSION="${PROJECT_VERSION}")
82
83 #installer information that is platform independent
84 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Fast .stl file viewer.")
85 set(CPACK_PACKAGE_VERSION_MAJOR ${FSTL_VERSION_MAJOR})
86 set(CPACK_PACKAGE_VERSION_MINOR ${FSTL_VERSION_MINOR})
87 set(CPACK_PACKAGE_VERSION_PATCH ${FSTL_VERSION_PATCH})
88
89 if(WIN32)
90
91     set(QT_USE_QTMAIN true)
92     
93     if(MSVC)
94         set_source_files_properties(fstl PROPERTIES LINKER_LANGUAGE "CXX")
95         set_target_properties(fstl PROPERTIES LINK_FLAGS "/SUBSYSTEM:WINDOWS")
96
97         install(TARGETS fstl DESTINATION bin COMPONENT all)
98         
99         install(FILES
100             $<TARGET_FILE:Qt5::Gui_EGL>
101             $<TARGET_FILE:Qt5::Gui_GLESv2>
102             $<TARGET_FILE:Qt5::Core>
103             $<TARGET_FILE:Qt5::Gui> 
104             $<TARGET_FILE:Qt5::OpenGL>
105             $<TARGET_FILE:Qt5::Widgets>
106             DESTINATION bin COMPONENT all)
107         
108         #install file in the platforms directory.
109         install (FILES
110             ${Qt5Core_DIR}/../../../plugins/platforms/qwindows.dll
111             DESTINATION bin/platforms COMPONENT all
112         )
113
114         #custom commands based on: https://gist.github.com/Rod-Persky/e6b93e9ee31f9516261b
115         add_custom_command(TARGET fstl POST_BUILD 
116             COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:Qt5::Core>       $<TARGET_FILE_DIR:${PROJECT_NAME}>
117             COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:Qt5::Gui>        $<TARGET_FILE_DIR:${PROJECT_NAME}>
118             COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:Qt5::Widgets>    $<TARGET_FILE_DIR:${PROJECT_NAME}>
119             COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:Qt5::OpenGL>     $<TARGET_FILE_DIR:${PROJECT_NAME}>
120         )       
121     endif(MSVC)
122
123     # windows specific installer generation information
124     set(CPACK_GENERATOR NSIS)
125     set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL OFF)
126     set(CPACK_NSIS_MODIFY_PATH ON)
127     set(CPACK_NSIS_MUI_FINISHPAGE_RUN ${PROJECT_NAME})
128     set(CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME}")
129     set(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\fstl.exe")
130     set(CPACK_NSIS_URL_INFO_ABOUT "https://github.com/fstl-app/fstl")
131     set(CPACK_NSIS_DISPLAY_NAME "fstl ${FSTL_VERSION}")
132     set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}/exe/fstl.ico")
133     set(CPACK_NSIS_MUI_UNIICON  "${CMAKE_CURRENT_SOURCE_DIR}/exe/fstl.ico")
134     set(CPACK_NSIS_CREATE_ICONS_EXTRA
135         "CreateShortCut '$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\fstl.lnk' '$INSTDIR\\\\bin\\\\fstl.exe'")
136     set(CPACK_COMPONENTS_ALL all)
137     if (CMAKE_CL_64)
138         set(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES64")
139     else (CMAKE_CL_64)
140         set(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES")
141     endif (CMAKE_CL_64)
142 elseif(APPLE)
143     set(CPACK_GENERATOR "DragNDrop")
144     set(CPACK_DMG_FORMAT "UDBZ")
145     set(CPACK_DMG_VOLUME_NAME "${PROJECT_NAME}")
146     set(CPACK_SYSTEM_NAME "OSX")
147     set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}")
148     set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/app/fstl.icns")
149 else()
150     install(TARGETS fstl RUNTIME DESTINATION bin)
151
152     set(CPACK_GENERATOR "DEB;RPM")
153     set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}")
154 endif(WIN32)
155
156 include(CPack)