Skip to content

Commit 7c190d8

Browse files
committed
Integrate the iod compiler with cmake build system.
1 parent 4df8992 commit 7c190d8

6 files changed

+99
-4
lines changed

CMakeLists.txt

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
cmake_minimum_required(VERSION 2.8)
2+
project(Iod)
3+
4+
5+
install(DIRECTORY iod DESTINATION include
6+
FILES_MATCHING PATTERN "*.hh")
7+
install(DIRECTORY iod DESTINATION include
8+
FILES_MATCHING PATTERN "*.hpp")
9+
10+
add_subdirectory(tools)
11+
12+
set(IOD_INCLUDE_DIR "include")
13+
set(CMAKE_CONFIG_DEST "share/iod")
14+
15+
include(CMakePackageConfigHelpers)
16+
configure_package_config_file (
17+
${CMAKE_SOURCE_DIR}/IodConfig.cmake.in
18+
${CMAKE_BINARY_DIR}/IodConfig.cmake
19+
INSTALL_DESTINATION ${CMAKE_CONFIG_DEST}
20+
PATH_VARS IOD_INCLUDE_DIR CMAKE_CONFIG_DEST)
21+
22+
export(PACKAGE Iod)
23+
24+
configure_file(IodConfigVersion.cmake.in
25+
"${PROJECT_BINARY_DIR}/IodConfigVersion.cmake" @ONLY)
26+
27+
install(FILES
28+
"${PROJECT_SOURCE_DIR}/IodUse.cmake"
29+
"${PROJECT_BINARY_DIR}/IodConfig.cmake"
30+
"${PROJECT_BINARY_DIR}/IodConfigVersion.cmake"
31+
DESTINATION share/iod)
32+
33+
# Install the export set for use with the install-tree
34+
install(EXPORT IodTargets DESTINATION ${CMAKE_CONFIG_DEST})

IodConfig.cmake.in

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@PACKAGE_INIT@
2+
3+
# - Config file for the Iod package
4+
# It defines the following variables
5+
# IOD_INCLUDE_DIRS - include directories for Iod
6+
7+
set_and_check(IOD_INCLUDE_DIR "@PACKAGE_IOD_INCLUDE_DIR@")
8+
9+
include("@PACKAGE_CMAKE_CONFIG_DEST@/IodTargets.cmake")
10+
11+
set_and_check(IOD_USE_FILE "@PACKAGE_CMAKE_CONFIG_DEST@/IodUse.cmake")

IodConfigVersion.cmake.in

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
set(PACKAGE_VERSION "1.0")

IodUse.cmake

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
set(IOD_TMP_DIR "${CMAKE_CURRENT_BINARY_DIR}/iod_tmp_dir")
2+
file(MAKE_DIRECTORY ${IOD_TMP_DIR})
3+
4+
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++14")
5+
6+
function(add_iod_executable arg1)
7+
8+
set(sources "")
9+
foreach(iod_compile_rules ${ARGN})
10+
set(input_file ${CMAKE_CURRENT_SOURCE_DIR}/${iod_compile_rules})
11+
set(output_file ${IOD_TMP_DIR}/${iod_compile_rules})
12+
set(sources ${sources} ${output_file})
13+
14+
add_custom_command(OUTPUT ${IOD_TMP_DIR}/${iod_compile_rules}
15+
COMMAND iodc ${input_file} ${output_file}
16+
DEPENDS ${input_file})
17+
18+
endforeach(iod_compile_rules)
19+
add_executable(${arg1} ${sources})
20+
21+
endfunction(add_iod_executable)

tools/CMakeLists.txt

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
cmake_minimum_required(VERSION 2.8)
2+
project(Iod)
3+
4+
find_package(Boost)
5+
add_definitions(-std=c++14)
6+
7+
add_executable(iodc iod_compiler.cc)
8+
target_link_libraries(iodc boost_regex)
9+
10+
install(TARGETS iodc
11+
EXPORT IodTargets
12+
DESTINATION bin)

tools/iod_compiler.cc

+20-4
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,19 @@ int main(int argc, char* argv[])
1717
{
1818
using namespace std;
1919

20-
if (argc == 0)
20+
if (argc != 3)
2121
{
22-
cout << "Usage: " << argv[0] << " input_cpp_file" << endl;
22+
cout << "Usage: " << argv[0] << " input_iod_cpp_file output_cpp_file" << endl;
2323
return 1;
2424
}
2525

2626
ifstream f(argv[1]);
27-
27+
if (!f)
28+
{
29+
std::cerr << "Cannot open file " << argv[1] << " for reading." << std::endl;
30+
return 1;
31+
}
32+
2833
set<string> symbols;
2934

3035
// prefix identifier @ symbol_identifier (
@@ -96,7 +101,13 @@ int main(int argc, char* argv[])
96101
lines.push_back(line);
97102
}
98103

99-
auto& os = cout;
104+
std::ofstream os(argv[2]);
105+
if (!os)
106+
{
107+
std::cerr << "Cannot open file " << argv[2] << " for writting." << std::endl;
108+
return 2;
109+
}
110+
100111
os << "// Generated by the iod compiler." << endl;
101112
os << "#include <iod/symbol.hh>" << endl;
102113
for (string s : symbols)
@@ -107,6 +118,11 @@ int main(int argc, char* argv[])
107118
<< "#endif" << endl;
108119
}
109120

121+
int i = 1;
110122
for (auto line : lines)
123+
{
124+
os << "# " << i << '"' << argv[1] << '"' << std::endl;
111125
os << line << endl;
126+
i++;
127+
}
112128
}

0 commit comments

Comments
 (0)