CMakeLists.txt

Mon, 06 Dec 2021 00:29:47 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Mon, 06 Dec 2021 00:29:47 +0200
changeset 67
c34057d3c94e
parent 62
d4857a7aa5a1
permissions
-rw-r--r--

Fix build on Windows

project (zcinema)
cmake_minimum_required (VERSION 2.6)
cmake_policy (SET CMP0020 NEW)
find_package (Qt5Widgets REQUIRED)
find_package (Qt5Core REQUIRED)
find_package (Python COMPONENTS Interpreter)
include_directories (${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR})

set (ZCINEMA_LAUNCHER_SOURCES
	launcher/demo.cpp
	launcher/main.cpp
	launcher/prompts.cpp
)

set (ZCINEMA_COMMON_SOURCES
	commonlib/config.cpp
	commonlib/misc.cpp
	commonlib/version.cpp
)

set (ZCINEMA_CONFIG_SOURCES
	config/configwindow.cpp
	config/addversionprompt.cpp
	config/main.cpp
	config/versionguientry.cpp
)

set (ZCINEMA_HEADERS
	commonlib/config.h
	commonlib/misc.h
	commonlib/types.h
	commonlib/version.h
	config/addversionprompt.h
	config/configwindow.h
	config/versionguientry.h
	launcher/demo.h
	launcher/prompts.h
)

set (ZCINEMA_FORMS
	ui/findfile.ui
	ui/demoprompt.ui
	ui/unknownversion.ui
	ui/configbox.ui
	ui/addversion.ui
)

set (ZCINEMA_RESOURCES zcinema.qrc)

if (NOT MSVC)
	set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall")
else()
	# Some Qt headers (QMap and QHash) trigger C4180, disable that.
	add_definitions ("/wd4180 /D_CRT_SECURE_NO_WARNINGS /nologo")
	set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Za")
endif()

if (MINGW)
	set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++ -lpthread -static")
endif()

include_directories ("${PROJECT_BINARY_DIR}")
include_directories ("${PROJECT_SOURCE_DIR}")

qt5_generate_moc (ZCINEMA_MOC ${ZCINEMA_HEADERS})
qt5_add_resources (ZCINEMA_QRC ${ZCINEMA_RESOURCES})
qt5_wrap_ui (ZCINEMA_FORMS_HEADERS ${ZCINEMA_FORMS})

add_library (${PROJECT_NAME}-common STATIC
	${ZCINEMA_COMMON_SOURCES}
	${ZCINEMA_QRC}
	${ZCINEMA_FORMS_HEADERS})
add_executable (${PROJECT_NAME} WIN32 ${ZCINEMA_LAUNCHER_SOURCES} zcinema.rc)
add_executable (${PROJECT_NAME}-config WIN32 ${ZCINEMA_CONFIG_SOURCES} zcinema.rc)
target_link_libraries (${PROJECT_NAME}-common Qt5::Widgets)
target_link_libraries (${PROJECT_NAME} ${PROJECT_NAME}-common)
target_link_libraries (${PROJECT_NAME}-config ${PROJECT_NAME}-common)

add_custom_target (make_hginfo
	    COMMAND ${Python_EXECUTABLE}
		"${CMAKE_SOURCE_DIR}/updaterevision.py"
		"${CMAKE_CURRENT_BINARY_DIR}/hginfo.h"
	WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})

add_dependencies (${PROJECT_NAME}-common make_hginfo)
set_target_properties (${PROJECT_NAME} PROPERTIES AUTOMOC 1)
set_target_properties (${PROJECT_NAME}-config PROPERTIES AUTOMOC 1)

# With clang, we need to set -Wno-deprecated since Qt headers seem to use the register keyword
# which clang doesn't seem to like.
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
	set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated")
endif()

install (TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)

mercurial