function(set_our_header_properties) not defined or something

when i make my project i’m getting a message something like, "set_our+header_properties) is not defined so i located the file it’s defined at and here’s what it says now after i tried putting in a message to indicate the file is being read:

#this is supposed to give me a messaage in the log. if it appears than this file is being read by cmake.

message(STATUS “Common.cmake loaded, function set_our_header_properties defined is here at the top of this file, if this message appears at least i know it’s reading the file.”)

function(set_our_header_properties)
foreach(file ${ARGN})
# Infer which subdirectory this header file should be installed.
set(loc ${file})
string(REPLACE “${CMAKE_CURRENT_BINARY_DIR}/” “” loc ${loc})
string(REGEX REPLACE “^include/” “” loc ${loc})
string(REGEX REPLACE “/[-A-Za-z0-9_]+.$” “” loc ${loc})
string(REGEX REPLACE “^addons/[^/]+/” “” loc ${loc})

    # If we have inferred correctly then it should be under allegro5.
    string(REGEX MATCH "^allegro5" matched ${loc})
    if(matched STREQUAL "allegro5")
        # MACOSX_PACKAGE_LOCATION is also used in install_our_headers.
        set_source_files_properties(${file}
            PROPERTIES
            MACOSX_PACKAGE_LOCATION Headers/${loc}
            )
    else()
        message(FATAL_ERROR "Could not infer where to install ${file}")
    endif()
endforeach(file)

endfunction(set_our_header_properties)

this is my file where function(set_our_properties) is and i don’t think it’s being read cause i included the file at line one of my CMakeLists.txt. this is the line i added:

include(cmake/Common.cmake)

the CMakeLists.txt file is in ~/allegro5 and the Common.cmake file is in ~allegro5/cmake so i think i have the correct path to include it. it seems the file still isn’t being read, i’ve made a log and reviewed it with the following command: cmake … --trace-expand -DWANT_PRIMITIVES=ON -DWANT_IMAGE=ON -DWANT_FONT=ON -DWANT_AUDIO=ON -DWANT_ACODEC=ON -DWANT_COLOR=ON -DWANT_MEMFILE=ON -DWANT_PHYSFS=ON -DWANT_NATIVE_DIALOG=ON -DWANT_VIDEO=ON -DWANT_TTF=ON > log 2>&1

when i review the log there’s no mention of Common.cmake file at all so i believe the problem is it’s still not looking at the file. i suspect there may be an issue with the cmake version but i’m not sure. how do i fix this?

system: linux mint: 6.8.0-49-generic
cmake version: cmake version 3.28.3
make version: GNU Make 4.3
Built for x86_64-pc-linux-gnu

If you’re not getting an error from the line include(cmake/Common.cmake), then the line is not failing and CMake has found a suitable file to include. You can use an absolute path there (perhaps based on CMAKE_SOURCE_DIR) to be sure you’re getting the file you want.

Also, double-check that you’re spelling the function in exactly the same way when you define it and when you call it.

If neither of these help, try reducing your setup to a minimum which still reproduces the issue. Either you’ll find the solution during the process, or you can post the minimal reproducer where the error may be much easier to see for someone else.

CMake Error at primitives/CMakeLists.txt:23 (set_our_header_properties):
Unknown CMake command “set_our_header_properties”.

You’re right about me not getting an error on the include statement. the only error i’m getting other than the cmake_minimum_required() line being missing two times is the (set_our_header_properties): error.

the only thing i can think of that can be causing the error is that my include statement is in the CMakeLists.txt file in the top directory, but the error is coming from the CMakeLists.txt file in the primitives directory, which is here:
allegro5/addons/primitives.

another thing worrying me is that there’s another directory called primitives being made by cmake here:

allegro5/addons/build/primitives. but that only has an empty directory in it called, “CMakeFiles”.

I just can’t understand why it’s making that in the build directory when it doesn’t seem like it should be. primitives is supposed to be just another addon/subdirectory in the addons folder. my best guess is that it starts making the /addons/primitives directory and files but then just quits when it’s encountering an error and thus, the directory and files remain unfinished in the build directory at the end. does that sound right?

also, i thought when i use, --trace-expand flags in the cmake command and review the log it should at least show all the files being read, so why doesn’t Common.cmake show up if there’s no issue with the include statement. and…

i thought if you included a file in the top directorie’s CMakeLists.txt file it would also be included in all the sub directories CMakeLists.txt files as well, but the error comes from the CMakeLists.txt file in /allegro5/addons/primitives. so i wonder if i can fix it by just adding an absoulte path include statement there even though it should be redundant.

my gut tells me it’s just not reading the file, the include statement is being completely ignored, or you can’t include that file for some reason, like maybe it’s being included, but despite that, it’s not being read or something.

here’s a line i added to the Common.cmake file where “set_our_header_properties” is defined

message(STATUS “Common.cmake loaded, function set_our_header_properties defined is here at the top of this file, if this message appears at least i know it’s reading the file.”)

so if that message never appears in my log when i run the cmake command: cmake … -DWANT_PRIMITIVES=ON -DWANT_IMAGE=ON -DWANT_FONT=ON -DWANT_AUDIO=ON -DWANT_ACODEC=ON -DWANT_COLOR=ON -DWANT_MEMFILE=ON -DWANT_PHYSFS=ON -DWANT_NATIVE_DIALOG=ON -DWANT_VIDEO=ON -DWANT_TTF=ON > log 2>&1
doesn’t that mean it’s DEFINITELY not reading the file? (fyi: when i edit this comment there’s only two periods after "cmake " but whenever i look at it there’s three periods there, but i only had two periods to denote the parent directory in the command. i have no idea why it’s adding an extra period there after i edit this comment)

here’s my entire log after running that command:

CMake Warning (dev) in CMakeLists.txt:
No project() command is present. The top-level CMakeLists.txt file must
contain a literal, direct call to the project() command. Add a line of
code such as

project(ProjectName)

near the top of the file, but after cmake_minimum_required().

CMake is pretending there is a “project(Project)” command on the first
line.
This warning is for project developers. Use -Wno-dev to suppress it.

CMake Warning (dev) in CMakeLists.txt:
cmake_minimum_required() should be called prior to this top-level project()
call. Please see the cmake-commands(7) manual for usage documentation of
both commands.
This warning is for project developers. Use -Wno-dev to suppress it.

– The C compiler identification is GNU 13.2.0
– The CXX compiler identification is GNU 13.2.0
– Detecting C compiler ABI info
– Detecting C compiler ABI info - done
– Check for working C compiler: /usr/bin/cc - skipped
– Detecting C compile features
– Detecting C compile features - done
– Detecting CXX compiler ABI info
– Detecting CXX compiler ABI info - done
– Check for working CXX compiler: /usr/bin/c++ - skipped
– Detecting CXX compile features
– Detecting CXX compile features - done
CMake Error at primitives/CMakeLists.txt:23 (set_our_header_properties):
Unknown CMake command “set_our_header_properties”.

CMake Warning (dev) in CMakeLists.txt:
No cmake_minimum_required command is present. A line of code such as

cmake_minimum_required(VERSION 3.28)

should be added at the top of the file. The version specified may be lower
if you wish to support older CMake versions for this project. For more
information run “cmake --help-policy CMP0000”.
This warning is for project developers. Use -Wno-dev to suppress it.

– Configuring incomplete, errors occurred!

@qweqqweq Your messages are very hard to read because the lack of formatting. It’s impossible to know if you have written something, or you just repeat what CMake said.

Nonetheless, just use the --trace or --trace-expand option on CMake to find out which exact lines and commands are executed.
You will see which file is included, as long as the included file has any command in it:

> cmake --trace-expand -P x.cmake 
Running with expanded trace output on.
/tmp/x.cmake(3):  include(cmake/Common.cmake )
/tmp/cmake/Common.cmake(1):  set(a )

If the include command is not inside the trace, then you don’t include anything in the first place (e.g. surrounded by some if condition).

Firstly, as Josef said, please take the time to format your posts properly, they’re next to impossible to read as they are. If you want us to spend our time helping you, you should invest your time first to make helping you as easy as possible.

Secondly, here is what a minimal reproducer could look like:

root/CMakeLists.txt:

cmake_minimum_required(VERSION 3.25)
project(MinimalExample)

include(cmake/Common.cmake)

add_subdirectory(primitives)

root/cmake/Common.cmake:

function(set_our_header_properties)
	message("***** Called")
endfunction()

root/primitives/CMakeLists.txt:

set_our_header_properties()

I’ve created this setup on my machine, and it works. Try to reduce your project to something similarly minimal and post that (see also http://sscce.org/). Maybe you will figure out the problem yourself in the process (this happens quite often). If not, we will at least have something we can look at quickly, without having to wade through unrelated things.

Thirdly, you’re getting CMake warnings about missing cmake_minimum_required() and project() calls. These warnings are there for a reason and you should address them.

1 Like