I have a few projects that used to build clean, now they get the infamous CMP0115 warning. I’m using the cmake files from one to start a new project and since this project is smaller, will use it.
The file being flagged makes no sense. It is only in the first CMakeLists.txt and is not in the list of files found in the second. It is input for a configure that creates a header used in the second and by the project.
Project level CMakeLists.txt
cmake_minimum_required(VERSION 3.8.0 FATAL_ERROR)
cmake_policy(VERSION 3.8..3.13)
# support using rpath on Mac OS X
cmake_policy(SET CMP0042 NEW)
#if (${CMAKE_VERSION} VERSION_GREATER "3.24.0")
# cmake_policy(SET CMP0015 OLD)
#endif()
project(Xpns-It-Cs)
set(BUILD_MAJOR "1")
set(BUILD_MINOR "1")
# To more cleanly support RPM packaging BUILD_MICRO needs to be non-zero
set(BUILD_MICRO "2")
file (READ "description.txt" XPNS-IT-CS_DESCRIPTION)
set(BUILD_COMPONENTS "Xpns-It-Cs")
include(CheckCXXCompilerFlag)
include(CheckCXXSourceCompiles)
include(CheckIncludeFile)
include(CheckIncludeFiles)
include(CheckTypeSize)
find_package(CopperSpice REQUIRED)
find_package(CsScintilla REQUIRED CONFIG)
list(APPEND CMAKE_CXX_SOURCE_FILE_EXTENSIONS build_info)
# file locations for installing
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
include(GNUInstallDirs)
# indicates where libraries are located relative to the executable
set(CMAKE_INSTALL_RPATH "@executable_path/../Resources")
elseif(CMAKE_SYSTEM_NAME MATCHES "(Linux|OpenBSD|FreeBSD|NetBSD|DragonFly)")
include(GNUInstallDirs)
set(CMAKE_INSTALL_RPATH "\$ORIGIN")
set(XPNS-IT-CS_INSTALLED_SIZE "150000")
# this architecture value is only used on the control file for a debian package.
# if the value is bogus or empty on other platforms it simply doesn't matter.
#
EXECUTE_PROCESS( COMMAND dpkg --print-architecture OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE XPNS-IT-CS_ARCHITECTURE)
message( STATUS "Architecture: ${XPNS-IT-CS_ARCHITECTURE}")
# lots of warnings and all warnings as errors
add_compile_options(-Wall -Wextra -Wuninitialized -Wredundant-decls -pedantic -Werror -Wswitch-default -Wundef -Werror -Wno-unused)
elseif(MSVC)
# use defaults
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows")
set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION .)
include(${CopperSpice_DIR}/InstallMinGW.cmake)
endif()
set(PACKAGE "xpns-it-cs")
set(PACKAGE_NAME "Xpns-It-Cs")
set(PACKAGE_VERSION "${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_MICRO}")
set(PACKAGE_STRING "xpns-it-cs ${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_MICRO}")
set(PACKAGE_TARNAME "xpns-it-cs")
set(PACKAGE_BUGREPORT "roland@logikalsolutions.com")
set(PACKAGE_URL "https://sourceforge.net/projects/xpns-it-cs/")
set(RPM_VERSION "${BUILD_MAJOR}.${BUILD_MINOR}")
set(RPM_RELEASE "${BUILD_MICRO}")
set(CPACK_PACKAGE_NAME ${PROJECT_NAME} )
set(CPACK_PACKAGE_VENDOR "Logikal Solutions")
set(CPACK_PACKAGE_VERSION_MAJOR ${BUILD_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${BUILD_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${BUILD_MICRO})
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Expense Tracker for tax reporting")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.md")
set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CMAKE_INSTALL_PREFIX})
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
# mac osx only
set(CPACK_BUNDLE_NAME Xpns-It-Cs)
set(CPACK_BUNDLE_ICON "${CMAKE_SOURCE_DIR}/resources/xpns-it-cs.icns")
set(CPACK_BUNDLE_PLIST "${CMAKE_SOURCE_DIR}/resources/Info.plist")
include(CPack)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_INCLUDE_DIRECTORIES_BEFORE ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 17)
if(APPLE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-undefined,error")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-undefined,error")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-undefined,error")
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-undefined")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-undefined")
endif()
string(TIMESTAMP BUILD_DATE "%m/%d/%Y")
add_definitions(-DBUILD_DATE="${BUILD_DATE}")
configure_file(
${CMAKE_SOURCE_DIR}/src/xpns-it-csbuildinfo.h.in
src/xpns-it-csbuildinfo.h
)
if(CMAKE_SYSTEM_NAME MATCHES "(Linux|OpenBSD|FreeBSD|NetBSD|DragonFly)")
# Update files needed for Debian
# Note: You need to update XPNS-IT-CS_INSTALLED_SIZE to reflect current installed size
#
configure_file(
${CMAKE_SOURCE_DIR}/deb_build.etc/control.in
deb_build.etc/control
)
configure_file(
${CMAKE_SOURCE_DIR}/xpns-it-cs.spec.in
xpns-it-cs.spec
)
configure_file(
${CMAKE_SOURCE_DIR}/net.projects.xpns-it-cs.desktop
net.projects.xpns-it-cs.desktop
COPYONLY
)
# postrm has some heavy syntax - just copy
configure_file(
${CMAKE_SOURCE_DIR}/deb_build.etc/postrm.in
deb_build.etc/postrm
COPYONLY
)
# postinst has some heavy syntax - just copy
configure_file(
${CMAKE_SOURCE_DIR}/deb_build.etc/postinst.in
deb_build.etc/postinst
COPYONLY
)
# hopefully we never need to replace values in rules
configure_file(
${CMAKE_SOURCE_DIR}/deb_build.etc/rules.in
deb_build.etc/rules
COPYONLY
)
endif()
# location for building binary files
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_subdirectory(src)
if(${CMAKE_SIZEOF_VOID_P} EQUAL 4)
set(TARGETBITS 32)
else()
set(TARGETBITS 64)
endif()
message("")
message("Xpns-It-Cs configured to run on: ${CMAKE_SYSTEM_NAME} ${TARGETBITS} bit, ${CMAKE_BUILD_TYPE} Mode")
message("Xpns-It-Cs will be built in: ${CMAKE_BINARY_DIR}")
message("Xpns-It-Cs will be installed in: ${CMAKE_INSTALL_PREFIX}")
message("\n")
The .h.in is just an easy method of getting the build version, date, etc. You’ve all got something like it in your projects.
/**************************************************************************
*
* Copyright (c) 2022 Roland Hughes
*
***************************************************************************/
#ifndef XPNS_IT_CS_BUILD_INFO_H_IN
#define XPNS_IT_CS_BUILD_INFO_H_IN
// Xpns-It-Cs Version "x.y.z"
constexpr const char *XPNS_IT_CS_VERSION_STRING = "@PACKAGE_VERSION@";
// Xpns-It-Cs Build Date "08/17/2017"
constexpr const char *XPNS_IT_CS_BUILD_DT = "@BUILD_DATE@";
constexpr const char *XPNS_IT_CS_PACKAGE_NM = "@PACKAGE_NAME@";
constexpr const char *XPNS_IT_CS_PACKAGE = "@PACKAGE@";
#endif
Here is the current CMakeLists.txt from the src directory.
list(APPEND XPNS-IT-CS_INCLUDES
${CMAKE_CURRENT_SOURCE_DIR}/aboutdialog.h
${CMAKE_CURRENT_SOURCE_DIR}/browsewindow.h
${CMAKE_CURRENT_SOURCE_DIR}/categoryDialog.h
${CMAKE_CURRENT_SOURCE_DIR}/logondialog.h
${CMAKE_CURRENT_SOURCE_DIR}/mainwindow.h
${CMAKE_CURRENT_SOURCE_DIR}/payeeDialog.h
${CMAKE_CURRENT_SOURCE_DIR}/printerselectiondialog.h
${CMAKE_CURRENT_SOURCE_DIR}/reportbrowserdialog.h
${CMAKE_CURRENT_SOURCE_DIR}/taxyeardialog.h
${CMAKE_CURRENT_SOURCE_DIR}/YNValidator.h
${CMAKE_CURRENT_SOURCE_DIR}/xpns-it-csbuildinfo.h
)
list(APPEND XPNS-IT-CS_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/aboutdialog.cpp
${CMAKE_CURRENT_SOURCE_DIR}/browsewindow.cpp
${CMAKE_CURRENT_SOURCE_DIR}/categoryDialog.cpp
${CMAKE_CURRENT_SOURCE_DIR}/logondialog.cpp
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mainwindow.cpp
${CMAKE_CURRENT_SOURCE_DIR}/payeeDialog.cpp
${CMAKE_CURRENT_SOURCE_DIR}/printerselectiondialog.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reportbrowserdialog.cpp
${CMAKE_CURRENT_SOURCE_DIR}/taxyeardialog.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../forms/aboutdialog.ui
${CMAKE_CURRENT_SOURCE_DIR}/../forms/categorydialog.ui
${CMAKE_CURRENT_SOURCE_DIR}/../forms/logondialog.ui
${CMAKE_CURRENT_SOURCE_DIR}/../forms/mainwindow.ui
${CMAKE_CURRENT_SOURCE_DIR}/../forms/payeedialog.ui
${CMAKE_CURRENT_SOURCE_DIR}/../forms/printerselectiondialog.ui
${CMAKE_CURRENT_SOURCE_DIR}/../forms/reportbrowserdialog.ui
${CMAKE_CURRENT_SOURCE_DIR}/../forms/taxyeardialog.ui
qrc_Xpns-It-Cs.cpp
)
# run rcc to generate qrc output
COPPERSPICE_RESOURCES(
${CMAKE_CURRENT_SOURCE_DIR}/../Xpns-It-Cs.qrc
)
# run uic to generate source
COPPERSPICE_RESOURCES(
${CMAKE_CURRENT_SOURCE_DIR}/../forms/aboutdialog.ui
${CMAKE_CURRENT_SOURCE_DIR}/../forms/categorydialog.ui
${CMAKE_CURRENT_SOURCE_DIR}/../forms/logondialog.ui
${CMAKE_CURRENT_SOURCE_DIR}/../forms/mainwindow.ui
${CMAKE_CURRENT_SOURCE_DIR}/../forms/payeedialog.ui
${CMAKE_CURRENT_SOURCE_DIR}/../forms/printerselectiondialog.ui
${CMAKE_CURRENT_SOURCE_DIR}/../forms/reportbrowserdialog.ui
${CMAKE_CURRENT_SOURCE_DIR}/../forms/taxyeardialog.ui
)
add_executable(Xpns-It-Cs ${XPNS-IT-CS_SOURCES} ${XPNS-IT-CS_INCLUDES})
target_include_directories(Xpns-It-Cs
PRIVATE
${CMAKE_SOURCE_DIR}/src
)
target_link_libraries(Xpns-It-Cs
PRIVATE
CopperSpice::CsCore
CopperSpice::CsGui
CopperSpice::CsNetwork
CopperSpice::CsSql
)
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
set_target_properties(Xpns-It-Cs PROPERTIES OUTPUT_NAME xpns-it-cs)
#install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/../resources/reddiamond.icns DESTINATION .)
elseif(CMAKE_SYSTEM_NAME MATCHES "(Linux|OpenBSD|FreeBSD|NetBSD|DragonFly)")
set_target_properties(Xpns-It-Cs PROPERTIES OUTPUT_NAME xpns-it-cs)
# TODO:: Need application PNG for desktop icon
#install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/../resources/reddiamond.png DESTINATION .)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/../net.projects.reddiamond.desktop DESTINATION .)
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows")
# TODO:: Need application ICO
#install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/../resources/reddiamond.ico DESTINATION .)
endif()
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
install(TARGETS Xpns-It-Cs DESTINATION ../MacOS)
else()
install(TARGETS Xpns-It-Cs DESTINATION .)
endif()
#cs_copy_library(CsCore)
#cs_copy_library(CsGui)
#cs_copy_library(CsNetwork)
#cs_copy_library(CsSql)
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
# copy required plugins to the bundle
cs_copy_plugins(CsGui ../plugins)
cs_copy_plugins(CsPrinterDriver ../plugins)
else()
# installs required plugins
cs_copy_plugins(CsGui)
cs_copy_plugins(CsPrinterDriver)
endif()
Lots of projects use .h.in to configure build time info. Why is this flagging the .in file and how do I work round this without setting OLD?
Honestly, is this because the final binary is a true Linux binary, without extension like the .exe wart of DOS/Windows and it is just flagging the wrong file?