1 # Add a file to be compiled.
3 # add_files([file1 ...] CONDITION condition [condition ...])
5 # CONDITION is a complete statement that can be evaluated with if().
6 # If it evaluates true, the source files will be added; otherwise not.
7 # For example: ADD_IF SDL_FOUND AND Allegro_FOUND
10 cmake_parse_arguments(PARAM "" "" "CONDITION" ${ARGN})
11 set(PARAM_FILES "${PARAM_UNPARSED_ARGUMENTS}")
14 if(NOT (${PARAM_CONDITION}))
19 foreach(FILE IN LISTS PARAM_FILES)
20 target_sources(openttd PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/${FILE})
24 # This function works around an 'issue' with CMake, where
25 # set_source_files_properties() only works in the scope of the file. We want
26 # to set properties for the source file on a more global level. To solve this,
27 # this function records the flags you want, and a macro adds them in the root
29 # See this URL for more information on the issue:
30 # http://cmake.3232098.n2.nabble.com/scope-of-set-source-files-properties-td4766111.html
32 # set_compile_flags([file1 ...] COMPILE_FLAGS cflag [cflag ...])
34 function(set_compile_flags)
35 cmake_parse_arguments(PARAM "" "" "COMPILE_FLAGS" ${ARGN})
36 set(PARAM_FILES "${PARAM_UNPARSED_ARGUMENTS}")
38 get_property(SOURCE_PROPERTIES GLOBAL PROPERTY source_properties)
40 foreach(FILE IN LISTS PARAM_FILES)
41 list(APPEND SOURCE_PROPERTIES "${CMAKE_CURRENT_SOURCE_DIR}/${FILE}::${PARAM_COMPILE_FLAGS}")
44 set_property(GLOBAL PROPERTY source_properties "${SOURCE_PROPERTIES}")
47 # Call this macro in the same CMakeLists.txt and after add_executable().
48 # This makes sure all the COMPILE_FLAGS of set_compile_flags() are set
51 # process_compile_flags()
53 function(process_compile_flags)
54 get_property(SOURCE_PROPERTIES GLOBAL PROPERTY source_properties)
56 foreach(ENTRY ${SOURCE_PROPERTIES})
57 string(REPLACE "::" ";" ENTRY "${ENTRY}")
58 list(GET ENTRY 0 FILE)
59 list(GET ENTRY 1 PROPERTIES)
61 set_source_files_properties(${FILE} PROPERTIES COMPILE_FLAGS ${PROPERTIES})