Skip to content

Commit cc8798e

Browse files
authored
Fix a few minor issues with CMakeLists.txt (#40)
This does a minor cleanup of a few issues with `CMakeLists.txt`: * Remove references to variable `PYMATCHING_SOURCE_FILES_NO_MAIN`. This variable is not defined anywhere in Chromobius and does not exist in Pymatching, so as far as I can tell, its value is always empty and thus has no effect in this `CMakeLists.txt` file. * Set variable `CHROMOBIUS_VERSION_INFO` from `setup.py`. Previously, the `CMakeLists.txt` file had this in it: ```cmake add_compile_definitions(CHROMOBIUS_VERSION_INFO=${CHROMOBIUS_VERSION_INFO}) ``` However, the variable on the RHS (`${CHROMOBIUS_VERSION_INFO}`) is not set when CMake is processing the file. This PR changes it to extract the version number from the `setup.py` file. * Wrap long lines and normalize indentation to 4 spaces.
1 parent 9f1857c commit cc8798e

File tree

1 file changed

+35
-15
lines changed

1 file changed

+35
-15
lines changed

CMakeLists.txt

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,28 +56,30 @@ if(NOT GTest_FOUND)
5656
message(STATUS "GTest fetch successful.")
5757
set(GTest_FOUND TRUE)
5858
else()
59-
message("WARNING: Failed to get GTest. Some tests will not be built. To fix, follow the Standalone CMake Project install instructions at https://github.com/google/googletest/blob/master/googletest/README.md")
59+
message(WARNING "Failed to find GoogleTest. Some tests will not be built. To fix "
60+
"this, follow the Standalone CMake Project install instructions for GTest "
61+
"at https://github.com/google/googletest/blob/master/googletest/README.md")
6062
endif()
6163
endif()
6264

6365
set(SIMD_WIDTH 128)
6466
FetchContent_Declare(stim
65-
GIT_REPOSITORY https://github.com/quantumlib/stim.git
66-
GIT_TAG 1320ad7eac7de34d2e9c70daa44fbc6d84174450) # v1.15.dev0 (what PyMatching 2.2.2 uses)
67+
GIT_REPOSITORY https://github.com/quantumlib/stim.git
68+
GIT_TAG 1320ad7eac7de34d2e9c70daa44fbc6d84174450) # v1.15.dev0 (what PyMatching 2.2.2 uses)
6769
FetchContent_GetProperties(stim)
6870
if(NOT stim_POPULATED)
69-
FetchContent_MakeAvailable(stim)
71+
FetchContent_MakeAvailable(stim)
7072
endif()
7173

7274
FetchContent_Declare(pymatching
73-
GIT_REPOSITORY https://github.com/oscarhiggott/pymatching.git
74-
GIT_TAG 08f4f03fc876bd3e13351b677241fc2e160b8b38) # v2.2.2
75+
GIT_REPOSITORY https://github.com/oscarhiggott/pymatching.git
76+
GIT_TAG 08f4f03fc876bd3e13351b677241fc2e160b8b38) # v2.2.2
7577
FetchContent_GetProperties(pymatching)
7678
if(NOT pymatching_POPULATED)
77-
FetchContent_MakeAvailable(pymatching)
79+
FetchContent_MakeAvailable(pymatching)
7880
endif()
7981

80-
add_executable(chromobius src/main.cc ${SOURCE_FILES_NO_MAIN} ${PYMATCHING_SOURCE_FILES_NO_MAIN})
82+
add_executable(chromobius src/main.cc ${SOURCE_FILES_NO_MAIN})
8183
target_compile_options(chromobius PRIVATE -O3 -Wall -Wpedantic)
8284
target_link_options(chromobius PRIVATE -O3)
8385
target_link_libraries(chromobius libstim libpymatching)
@@ -96,31 +98,35 @@ endif()
9698
install(TARGETS libchromobius LIBRARY DESTINATION)
9799
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/" DESTINATION "include" FILES_MATCHING PATTERN "*.h" PATTERN "*.inl")
98100

99-
add_executable(chromobius_perf ${SOURCE_FILES_NO_MAIN} ${PYMATCHING_SOURCE_FILES_NO_MAIN} ${PERF_FILES})
101+
add_executable(chromobius_perf ${SOURCE_FILES_NO_MAIN} ${PERF_FILES})
100102
target_compile_options(chromobius_perf PRIVATE -Wall -Wpedantic -O3 -g -fno-omit-frame-pointer -DNDEBUG)
101103
target_link_options(chromobius_perf PRIVATE -pthread)
102104
target_link_libraries(chromobius_perf PRIVATE libstim libpymatching)
103105

104106
if(GTest_FOUND)
105-
add_executable(chromobius_test ${SOURCE_FILES_NO_MAIN} ${PYMATCHING_SOURCE_FILES_NO_MAIN} ${TEST_FILES})
107+
add_executable(chromobius_test ${SOURCE_FILES_NO_MAIN} ${TEST_FILES})
106108
target_link_libraries(chromobius_test GTest::gtest GTest::gtest_main libstim libpymatching)
107-
target_compile_options(chromobius_test PRIVATE -Wall -Wpedantic -g -fno-omit-frame-pointer -fno-strict-aliasing -fsanitize=undefined -fsanitize=address)
109+
target_compile_options(chromobius_test PRIVATE -Wall -Wpedantic -g -fno-omit-frame-pointer -fno-strict-aliasing
110+
-fsanitize=undefined -fsanitize=address)
108111
target_link_options(chromobius_test PRIVATE -g -fno-omit-frame-pointer -fsanitize=undefined -fsanitize=address)
109112

110-
add_executable(chromobius_test_o3 ${SOURCE_FILES_NO_MAIN} ${PYMATCHING_SOURCE_FILES_NO_MAIN} ${TEST_FILES})
113+
add_executable(chromobius_test_o3 ${SOURCE_FILES_NO_MAIN} ${TEST_FILES})
111114
target_link_libraries(chromobius_test_o3 GTest::gtest GTest::gtest_main libstim libpymatching)
112115
target_compile_options(chromobius_test_o3 PRIVATE -O3 -Wall -Wpedantic -fno-strict-aliasing)
113116
target_link_options(chromobius_test_o3 PRIVATE)
114117
else()
115-
message("WARNING: Skipped chromobius_test target. `GTest` not found. To fix, follow Standalone CMake Project install instructions at https://github.com/google/googletest/blob/master/googletest/README.md")
118+
message(WARNING "Skipped target 'chromobius_test' because GoogleTest could not be found. "
119+
"To fix this, follow the Standalone CMake Project install instructions for GTest "
120+
"at https://github.com/google/googletest/blob/master/googletest/README.md")
116121
endif()
117122

118123
find_package(Python COMPONENTS Interpreter Development)
119124

120125
# Look for the same Pybind version range as ci.yml uses.
121126
find_package(pybind11 2.11.1...<2.12.0 QUIET CONFIG)
122127
if(NOT pybind11_FOUND)
123-
message(STATUS "Pybind11 not found or the version found is not the needed one. Will try fetching and building the desired version from source.")
128+
message(STATUS "Pybind11 not found or the version found is not the version needed. "
129+
"Will try fetching and building the desired version from source.")
124130
FetchContent_Declare(pybind11
125131
GIT_REPOSITORY https://github.com/pybind/pybind11.git
126132
GIT_TAG v2.11.2
@@ -137,8 +143,22 @@ if ((pybind11_FOUND AND Python_FOUND) OR "$ENV{CMAKE_FORCE_PYBIND_CHROMOBIUS}")
137143
target_compile_options(chromobius_pybind PRIVATE -O3 -DNDEBUG)
138144
target_link_libraries(chromobius_pybind PRIVATE libstim libpymatching)
139145
target_link_options(chromobius_pybind PRIVATE -O3)
146+
147+
set(SETUPPY_PATH "${CMAKE_CURRENT_SOURCE_DIR}/setup.py")
148+
file(READ ${SETUPPY_PATH} SETUPPY_TEXT)
149+
string(REGEX MATCH "__version__[ \t]*=[ \t]*[\"']([^\"']+)[\"']" _ ${SETUPPY_TEXT})
150+
if(NOT CMAKE_MATCH_1)
151+
message(FATAL_ERROR "Could not find __version__ string in ${SETUPPY_PATH}.")
152+
else()
153+
message(STATUS "Chromobius version is ${CMAKE_MATCH_1}")
154+
endif()
155+
set(CHROMOBIUS_VERSION_INFO "${CMAKE_MATCH_1}")
140156
add_compile_definitions(CHROMOBIUS_VERSION_INFO=${CHROMOBIUS_VERSION_INFO})
157+
141158
message(STATUS "Added chromobius_pybind target.")
142159
else()
143-
message("WARNING: Skipped chromobius_pybind target. `pybind11` not found. To fix, install pybind11. On debian based distributions, the package name is `pybind11-dev`")
160+
message(WARNING "Skipped target 'chromobius_pybind' because `pybind11` could not be found. "
161+
"To fix this, install pybind11. On Debian and Ubuntu Linux distributions, the "
162+
"package name is 'pybind11-dev'. For other systems, please see the pybind11 "
163+
"instructions at https://pybind11.readthedocs.io/.")
144164
endif()

0 commit comments

Comments
 (0)